CategoryController.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <?php
  2. namespace shop\controllers;
  3. use biz\goods\services\CategoryService;
  4. use biz\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. //查看详情 shish 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. //添加分类 shish 2019.12.8
  25. public function actionAdd()
  26. {
  27. $post = Yii::$app->request->post();
  28. $post['merchantId'] = $this->sjId;
  29. $cat = CategoryService::addCategory($post);
  30. util::success(['id' => $cat['id']]);
  31. }
  32. //更新分类 shish 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. //分类启用停用 shish 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. //删除分类 shish 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. CategoryService::deleteCategory($categoryId);
  61. util::complete('删除成功');
  62. }
  63. //取分类下商品 shish 2019.12.2
  64. public function actionGoodsList()
  65. {
  66. $categoryId = Yii::$app->request->get('categoryId', 0);
  67. //没有分类默认取商家第一个分类
  68. if (empty($categoryId)) {
  69. $categoryId = CategoryService::getTopCategoryId($this->sjId);
  70. }
  71. if (empty($categoryId)) {
  72. util::fail('没有找商品分类');
  73. }
  74. $where = [];
  75. $where['merchantId'] = $this->sjId;
  76. $where['cId'] = $categoryId;
  77. $where['delStatus'] = 0;
  78. $data = GoodsCategoryService::getGoodsList($where);
  79. util::success($data);
  80. }
  81. //分类排序 shish 2020.3.11
  82. public function actionSort()
  83. {
  84. $id = Yii::$app->request->get('id', 0);
  85. $inTurn = Yii::$app->request->get('inTurn', 0);
  86. $category = CategoryService::getById($id);
  87. CategoryService::valid($category, $this->sjId);
  88. CategoryService::updateById($id, ['inTurn' => $inTurn]);
  89. util::complete();
  90. }
  91. //获取分类 shish 2019.12.2
  92. public function actionMallList()
  93. {
  94. $return = CategoryService::getEnableList($this->sjId);
  95. util::success($return);
  96. }
  97. }