CategoryController.php 3.1 KB

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