CategoryController.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: admin
  5. * Date: 2019/12/1
  6. * Time: 13:55
  7. */
  8. namespace shop\controllers;
  9. use biz\goods\services\CategoryService;
  10. use biz\goods\services\GoodsCategoryService;
  11. use Yii;
  12. use common\components\util;
  13. class CategoryController extends BaseController
  14. {
  15. //分类列表
  16. public function actionList()
  17. {
  18. $list = CategoryService::getCategoryList($this->merchantId);
  19. util::success($list);
  20. }
  21. //查看详情 shish 2019.12.8
  22. public function actionDetail()
  23. {
  24. $id = Yii::$app->request->get('categoryId', 0);
  25. $category = CategoryService::getById($id);
  26. CategoryService::valid($category, $this->merchantId);
  27. $info = CategoryService::getInfo($id);
  28. util::success($info);
  29. }
  30. //添加分类 shish 2019.12.8
  31. public function actionAdd()
  32. {
  33. $post = Yii::$app->request->post();
  34. $post['merchantId'] = $this->merchantId;
  35. $cat = CategoryService::addCategory($post);
  36. util::success(['id' => $cat['id']]);
  37. }
  38. //更新分类 shish 2019.12.8
  39. public function actionUpdate()
  40. {
  41. $post = Yii::$app->request->post();
  42. $categoryId = isset($post['categoryId']) ? $post['categoryId'] : 0;
  43. $category = CategoryService::getById($categoryId);
  44. CategoryService::valid($category, $this->merchantId);
  45. CategoryService::updateCategory($category, $post);
  46. util::complete('修改成功');
  47. }
  48. //分类启用停用 shish 2019.12.8
  49. public function actionChangeStatus()
  50. {
  51. $get = Yii::$app->request->get();
  52. $categoryId = isset($get['categoryId']) ? $get['categoryId'] : 0;
  53. $status = isset($get['status']) ? $get['status'] : 0;
  54. $category = CategoryService::getById($categoryId);
  55. CategoryService::valid($category, $this->merchantId);
  56. CategoryService::changeStatus($categoryId, $status);
  57. util::complete();
  58. }
  59. //删除分类 shish 2019.12.28
  60. public function actionDelete()
  61. {
  62. $get = Yii::$app->request->get();
  63. $categoryId = isset($get['categoryId']) ? $get['categoryId'] : 0;
  64. $category = CategoryService::getById($categoryId);
  65. CategoryService::valid($category, $this->merchantId);
  66. CategoryService::deleteCategory($categoryId);
  67. util::complete('删除成功');
  68. }
  69. //取分类下商品 shish 2019.12.2
  70. public function actionGoodsList()
  71. {
  72. $categoryId = Yii::$app->request->get('categoryId');
  73. //没有分类默认取商家第一个分类
  74. $categoryId = !empty($categoryId) ? $categoryId : CategoryService::getTopCategoryId($this->merchantId);
  75. $where = [];
  76. $where['merchantId'] = $this->merchantId;
  77. $where['cId'] = $categoryId;
  78. $where['delStatus'] = 0;
  79. $data = GoodsCategoryService::getGoodsList($where);
  80. util::success($data);
  81. }
  82. //分类排序 shish 2020.3.11
  83. public function actionSort()
  84. {
  85. $id = Yii::$app->request->get('id', 0);
  86. $inTurn = Yii::$app->request->get('inTurn', 0);
  87. $category = CategoryService::getById($id);
  88. CategoryService::valid($category, $this->merchantId);
  89. CategoryService::updateById($id, ['inTurn' => $inTurn]);
  90. util::complete();
  91. }
  92. }