KindController.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. <?php
  2. namespace hd\controllers;
  3. use bizHd\goods\classes\KindClass;
  4. use bizHd\goods\services\CategoryService;
  5. use bizHd\goods\services\GoodsCategoryService;
  6. use Yii;
  7. use common\components\util;
  8. class KindController extends BaseController
  9. {
  10. //品类列表
  11. public function actionList()
  12. {
  13. $get = Yii::$app->request->get();
  14. $mainId = $this->mainId ?? 0;
  15. $where = ['mainId' => $mainId, 'delStatus' => 0];
  16. $name = isset($get['name']) ? $get['name'] : '';
  17. $name = trim($name);
  18. if (!empty($name)) {
  19. $where['name'] = ['like', $name];
  20. }
  21. $flower = $get['flower'] ?? '';
  22. if (is_numeric($flower)) {
  23. $where['flower'] = $flower;
  24. }
  25. $list = KindClass::getKindList($where);
  26. util::success($list);
  27. }
  28. //查看详情 ssh 2019.12.8
  29. public function actionDetail()
  30. {
  31. $id = Yii::$app->request->get('categoryId', 0);
  32. $category = CategoryService::getById($id);
  33. CategoryService::valid($category, $this->mainId);
  34. $info = CategoryService::getInfo($id);
  35. util::success($info);
  36. }
  37. //添加品类 ssh 2019.12.8
  38. public function actionAdd()
  39. {
  40. $post = Yii::$app->request->post();
  41. $post['sjId'] = $this->sjId;
  42. $post['mainId'] = $this->mainId;
  43. KindClass::addData($post);
  44. util::complete();
  45. }
  46. //更新种类 ssh 20230220
  47. public function actionUpdate()
  48. {
  49. $post = Yii::$app->request->post();
  50. $kindId = isset($post['kindId']) ? $post['kindId'] : 0;
  51. $kind = KindClass::getById($kindId, true);
  52. if (empty($kind)) {
  53. util::fail('没有找到种类');
  54. }
  55. if ($kind->mainId != $this->mainId) {
  56. util::fail('没有权限');
  57. }
  58. $inTurn = $post['inTurn'] ?? 0;
  59. $name = $post['name'] ?? '';
  60. $name = trim($name);
  61. $list = KindClass::getAllByCondition(['mainId' => $this->mainId, 'delStatus' => 0], null, '*', null, true);
  62. foreach ($list as $key => $item) {
  63. $currentName = $item->name ?? '';
  64. if ($currentName == $name && $item->id != $kind->id) {
  65. util::fail('名称已经存在了');
  66. }
  67. }
  68. $kind->inTurn = $inTurn;
  69. $kind->name = $name;
  70. $kind->save();
  71. util::complete('修改成功');
  72. }
  73. //品类启用停用 ssh 2019.12.8
  74. public function actionChangeStatus()
  75. {
  76. $get = Yii::$app->request->get();
  77. $categoryId = isset($get['categoryId']) ? $get['categoryId'] : 0;
  78. $status = isset($get['status']) ? $get['status'] : 0;
  79. $category = CategoryService::getById($categoryId);
  80. CategoryService::valid($category, $this->mainId);
  81. CategoryService::changeStatus($categoryId, $status);
  82. util::complete();
  83. }
  84. //删除品类 ssh 2019.12.28
  85. public function actionDelete()
  86. {
  87. $get = Yii::$app->request->get();
  88. $categoryId = isset($get['categoryId']) ? $get['categoryId'] : 0;
  89. $category = CategoryService::getById($categoryId);
  90. CategoryService::valid($category, $this->mainId);
  91. if ($category['goodsNum'] > 0) {
  92. util::fail('品类下还有商品');
  93. }
  94. $count = CategoryService::deleteCategory($categoryId);
  95. if (!$count) {
  96. util::fail('删除失败');
  97. }
  98. util::complete('删除成功');
  99. }
  100. //取品类下商品 ssh 20220406
  101. public function actionGoodsList()
  102. {
  103. $get = Yii::$app->request->get();
  104. $catId = $get['catId'] ?? 0;
  105. if (empty($catId)) {
  106. util::fail('没有品类');
  107. }
  108. $where = [];
  109. $where['mainId'] = $this->mainId;
  110. $where['cId'] = $catId;
  111. $flower = $get['flower'] ?? '';
  112. if (is_numeric($flower)) {
  113. $where['flower'] = $flower;
  114. }
  115. $where['delStatus'] = $get['delStatus'] ?? 0;
  116. $status = $get['status'] ?? '';
  117. if (is_numeric($status)) {
  118. $where['status'] = $status;
  119. }
  120. $flowerNum = $get['flowerNum'] ?? 0;
  121. if (!empty($flowerNum)) {
  122. $where['flowerNum'] = $flowerNum;
  123. }
  124. $data = GoodsCategoryService::getGoodsList($where);
  125. util::success($data);
  126. }
  127. //品类排序 ssh 2020.3.11
  128. public function actionSort()
  129. {
  130. $id = Yii::$app->request->get('id', 0);
  131. $inTurn = Yii::$app->request->get('inTurn', 0);
  132. $category = CategoryService::getById($id);
  133. CategoryService::valid($category, $this->mainId);
  134. CategoryService::updateById($id, ['inTurn' => $inTurn]);
  135. util::complete();
  136. }
  137. //获取品类 ssh 2019.12.2
  138. public function actionMallList()
  139. {
  140. $return = CategoryService::getEnableList($this->sjId);
  141. util::success($return);
  142. }
  143. }