KindController.php 4.7 KB

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