KindController.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <?php
  2. namespace hd\controllers;
  3. use bizHd\goods\classes\KindClass;
  4. use bizHd\goods\services\CategoryService;
  5. use bizHd\goods\services\GoodsCategoryService;
  6. use Yii;
  7. use common\components\util;
  8. class KindController extends BaseController
  9. {
  10. //品类列表
  11. public function actionList()
  12. {
  13. $list = KindClass::getKindList($this->mainId);
  14. util::success($list);
  15. }
  16. //查看详情 ssh 2019.12.8
  17. public function actionDetail()
  18. {
  19. $id = Yii::$app->request->get('categoryId', 0);
  20. $category = CategoryService::getById($id);
  21. CategoryService::valid($category, $this->mainId);
  22. $info = CategoryService::getInfo($id);
  23. util::success($info);
  24. }
  25. //添加品类 ssh 2019.12.8
  26. public function actionAdd()
  27. {
  28. $post = Yii::$app->request->post();
  29. $post['sjId'] = $this->sjId;
  30. $post['mainId'] = $this->mainId;
  31. $cat = CategoryService::addCategory($post);
  32. util::success(['id' => $cat['id']]);
  33. }
  34. //更新品类 ssh 20220404
  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->mainId);
  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->mainId);
  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->mainId);
  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 20220406
  72. public function actionGoodsList()
  73. {
  74. $get = Yii::$app->request->get();
  75. $catId = $get['catId'] ?? 0;
  76. if (empty($catId)) {
  77. util::fail('没有品类');
  78. }
  79. $where = [];
  80. $where['mainId'] = $this->mainId;
  81. $where['cId'] = $catId;
  82. $flower = $get['flower'] ?? '';
  83. if (is_numeric($flower)) {
  84. $where['flower'] = $flower;
  85. }
  86. $where['delStatus'] = $get['delStatus'] ?? 0;
  87. $status = $get['status'] ?? '';
  88. if (is_numeric($status)) {
  89. $where['status'] = $status;
  90. }
  91. $flowerNum = $get['flowerNum'] ?? 0;
  92. if (!empty($flowerNum)) {
  93. $where['flowerNum'] = $flowerNum;
  94. }
  95. $data = GoodsCategoryService::getGoodsList($where);
  96. util::success($data);
  97. }
  98. //品类排序 ssh 2020.3.11
  99. public function actionSort()
  100. {
  101. $id = Yii::$app->request->get('id', 0);
  102. $inTurn = Yii::$app->request->get('inTurn', 0);
  103. $category = CategoryService::getById($id);
  104. CategoryService::valid($category, $this->mainId);
  105. CategoryService::updateById($id, ['inTurn' => $inTurn]);
  106. util::complete();
  107. }
  108. //获取品类 ssh 2019.12.2
  109. public function actionMallList()
  110. {
  111. $return = CategoryService::getEnableList($this->sjId);
  112. util::success($return);
  113. }
  114. }