CategoryController.php 3.9 KB

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