CategoryController.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <?php
  2. namespace hd\controllers;
  3. use bizHd\goods\classes\CategoryClass;
  4. use bizHd\goods\services\CategoryService;
  5. use bizHd\goods\services\GoodsCategoryService;
  6. use Yii;
  7. use common\components\util;
  8. class CategoryController extends BaseController
  9. {
  10. public function actionGetAllCategory()
  11. {
  12. $where = ['mainId' => $this->mainId, 'delStatus' => 0];
  13. $list = CategoryClass::getAllByCondition($where, 'inTurn desc', '*');
  14. util::success(['list' => $list]);
  15. }
  16. //分类列表
  17. public function actionList()
  18. {
  19. $get = Yii::$app->request->get();
  20. $flower = $get['flower'] ?? '';
  21. $list = CategoryService::getCategoryList($this->mainId, $flower);
  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. $cat = CategoryService::addCategory($post);
  40. util::success(['id' => $cat['id']]);
  41. }
  42. //更新分类 ssh 20220404
  43. public function actionUpdate()
  44. {
  45. $post = Yii::$app->request->post();
  46. $categoryId = isset($post['categoryId']) ? $post['categoryId'] : 0;
  47. $category = CategoryService::getById($categoryId);
  48. CategoryService::valid($category, $this->mainId);
  49. CategoryService::updateCategory($category, $post);
  50. util::complete('修改成功');
  51. }
  52. //分类启用停用 ssh 2019.12.8
  53. public function actionChangeStatus()
  54. {
  55. $get = Yii::$app->request->get();
  56. $categoryId = isset($get['categoryId']) ? $get['categoryId'] : 0;
  57. $status = isset($get['status']) ? $get['status'] : 0;
  58. $category = CategoryService::getById($categoryId);
  59. CategoryService::valid($category, $this->mainId);
  60. CategoryService::changeStatus($categoryId, $status);
  61. util::complete();
  62. }
  63. //删除分类 ssh 2019.12.28
  64. public function actionDelete()
  65. {
  66. $get = Yii::$app->request->get();
  67. $categoryId = isset($get['categoryId']) ? $get['categoryId'] : 0;
  68. $category = CategoryService::getById($categoryId);
  69. CategoryService::valid($category, $this->mainId);
  70. if ($category['goodsNum'] > 0) {
  71. util::fail('分类下还有商品');
  72. }
  73. $count = CategoryService::deleteCategory($categoryId);
  74. if (!$count) {
  75. util::fail('删除失败');
  76. }
  77. util::complete('删除成功');
  78. }
  79. //取分类下商品 ssh 20220406
  80. public function actionGoodsList()
  81. {
  82. $get = Yii::$app->request->get();
  83. $catId = $get['catId'] ?? 0;
  84. $where = [];
  85. $where['mainId'] = $this->mainId;
  86. if (!empty($catId)) {
  87. $where['cId'] = $catId;
  88. }
  89. $flower = $get['flower'] ?? '';
  90. if (is_numeric($flower)) {
  91. $where['flower'] = $flower;
  92. }
  93. $where['delStatus'] = $get['delStatus'] ?? 0;
  94. $status = $get['status'] ?? '';
  95. if (is_numeric($status)) {
  96. $where['status'] = $status;
  97. }
  98. $flowerNum = $get['flowerNum'] ?? 0;
  99. if (!empty($flowerNum)) {
  100. $where['flowerNum'] = $flowerNum;
  101. }
  102. $searchText = $get['searchText'] ?? '';
  103. if (!empty($searchText)) {
  104. $where['name'] = ['like', $searchText];
  105. }
  106. $data = GoodsCategoryService::getGoodsList($where);
  107. util::success($data);
  108. }
  109. //分类排序 ssh 2020.3.11
  110. public function actionSort()
  111. {
  112. $id = Yii::$app->request->get('id', 0);
  113. $inTurn = Yii::$app->request->get('inTurn', 0);
  114. $category = CategoryService::getById($id);
  115. CategoryService::valid($category, $this->mainId);
  116. CategoryService::updateById($id, ['inTurn' => $inTurn]);
  117. util::complete();
  118. }
  119. //获取分类 ssh 2019.12.2
  120. public function actionMallList()
  121. {
  122. $return = CategoryService::getEnableList($this->sjId);
  123. util::success($return);
  124. }
  125. }