CategoryController.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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. $property = $get['property'] ?? '';
  14. $list = CategoryService::getCategoryList($this->sjId, $property);
  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. $cat = CategoryService::addCategory($post);
  32. util::success(['id' => $cat['id']]);
  33. }
  34. //更新分类 ssh 2019.12.8
  35. public function actionUpdate()
  36. {
  37. $post = Yii::$app->request->post();
  38. $categoryId = isset($post['categoryId']) ? $post['categoryId'] : 0;
  39. $category = CategoryService::getById($categoryId);
  40. CategoryService::valid($category, $this->sjId);
  41. CategoryService::updateCategory($category, $post);
  42. util::complete('修改成功');
  43. }
  44. //分类启用停用 ssh 2019.12.8
  45. public function actionChangeStatus()
  46. {
  47. $get = Yii::$app->request->get();
  48. $categoryId = isset($get['categoryId']) ? $get['categoryId'] : 0;
  49. $status = isset($get['status']) ? $get['status'] : 0;
  50. $category = CategoryService::getById($categoryId);
  51. CategoryService::valid($category, $this->sjId);
  52. CategoryService::changeStatus($categoryId, $status);
  53. util::complete();
  54. }
  55. //删除分类 ssh 2019.12.28
  56. public function actionDelete()
  57. {
  58. $get = Yii::$app->request->get();
  59. $categoryId = isset($get['categoryId']) ? $get['categoryId'] : 0;
  60. $category = CategoryService::getById($categoryId);
  61. CategoryService::valid($category, $this->sjId);
  62. if ($category['goodsNum'] > 0) {
  63. util::fail('分类下还有商品');
  64. }
  65. $count = CategoryService::deleteCategory($categoryId);
  66. if (!$count) {
  67. util::fail('删除失败');
  68. }
  69. util::complete('删除成功');
  70. }
  71. //取分类下商品 ssh 2019.12.2
  72. public function actionGoodsList()
  73. {
  74. $categoryId = Yii::$app->request->get('categoryId', 0);
  75. //没有分类默认取商家第一个分类
  76. if (empty($categoryId)) {
  77. $categoryId = CategoryService::getTopCategoryId($this->sjId);
  78. }
  79. if (empty($categoryId)) {
  80. util::fail('没有找商品分类');
  81. }
  82. $where = [];
  83. $where['sjId'] = $this->sjId;
  84. $where['cId'] = $categoryId;
  85. $where['delStatus'] = 0;
  86. $status = Yii::$app->request->get('status', '');
  87. if (is_numeric($status)) {
  88. $where['status'] = $status;
  89. }
  90. $data = GoodsCategoryService::getGoodsList($where);
  91. util::success($data);
  92. }
  93. //分类排序 ssh 2020.3.11
  94. public function actionSort()
  95. {
  96. $id = Yii::$app->request->get('id', 0);
  97. $inTurn = Yii::$app->request->get('inTurn', 0);
  98. $category = CategoryService::getById($id);
  99. CategoryService::valid($category, $this->sjId);
  100. CategoryService::updateById($id, ['inTurn' => $inTurn]);
  101. util::complete();
  102. }
  103. //获取分类 ssh 2019.12.2
  104. public function actionMallList()
  105. {
  106. $return = CategoryService::getEnableList($this->sjId);
  107. util::success($return);
  108. }
  109. }