CategoryController.php 3.6 KB

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