KindController.php 5.2 KB

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