KindController.php 4.4 KB

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