CategoryController.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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->sjId);
  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 2019.12.8
  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->sjId);
  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->sjId);
  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->sjId);
  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 2019.12.2
  73. public function actionGoodsList()
  74. {
  75. $categoryId = Yii::$app->request->get('categoryId', 0);
  76. //没有分类默认取商家第一个分类
  77. if (empty($categoryId)) {
  78. $categoryId = CategoryService::getTopCategoryId($this->mainId);
  79. }
  80. if (empty($categoryId)) {
  81. util::fail('没有找商品分类');
  82. }
  83. $where = [];
  84. $where['sjId'] = $this->sjId;
  85. $where['cId'] = $categoryId;
  86. $where['delStatus'] = 0;
  87. $status = Yii::$app->request->get('status', '');
  88. if (is_numeric($status)) {
  89. $where['status'] = $status;
  90. }
  91. $data = GoodsCategoryService::getGoodsList($where);
  92. util::success($data);
  93. }
  94. //分类排序 ssh 2020.3.11
  95. public function actionSort()
  96. {
  97. $id = Yii::$app->request->get('id', 0);
  98. $inTurn = Yii::$app->request->get('inTurn', 0);
  99. $category = CategoryService::getById($id);
  100. CategoryService::valid($category, $this->sjId);
  101. CategoryService::updateById($id, ['inTurn' => $inTurn]);
  102. util::complete();
  103. }
  104. //获取分类 ssh 2019.12.2
  105. public function actionMallList()
  106. {
  107. $return = CategoryService::getEnableList($this->sjId);
  108. util::success($return);
  109. }
  110. }