CategoryController.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. use bizHd\goods\classes\CategoryClass;
  14. class CategoryController extends BaseController
  15. {
  16. //分类列表
  17. public function actionList()
  18. {
  19. $get = Yii::$app->request->get();
  20. //$property = $get['property'] ?? '';
  21. $list = CategoryService::getCategoryList($this->mainId);
  22. util::success($list);
  23. }
  24. //查看详情 ssh 2019.12.8
  25. public function actionDetail()
  26. {
  27. $id = Yii::$app->request->get('categoryId', 0);
  28. $category = CategoryService::getById($id);
  29. CategoryService::valid($category, $this->mainId);
  30. $info = CategoryService::getInfo($id);
  31. util::success($info);
  32. }
  33. //添加分类 ssh 2019.12.8
  34. public function actionAdd()
  35. {
  36. $post = Yii::$app->request->post();
  37. $post['sjId'] = $this->sjId;
  38. $cat = CategoryService::addCategory($post);
  39. util::success(['id' => $cat['id']]);
  40. }
  41. //更新分类 ssh 2019.12.8
  42. public function actionUpdate()
  43. {
  44. $post = Yii::$app->request->post();
  45. $categoryId = isset($post['categoryId']) ? $post['categoryId'] : 0;
  46. $category = CategoryService::getById($categoryId);
  47. CategoryService::valid($category, $this->mainId);
  48. CategoryService::updateCategory($category, $post);
  49. util::complete('修改成功');
  50. }
  51. //分类启用停用 ssh 2019.12.8
  52. public function actionChangeStatus()
  53. {
  54. $get = Yii::$app->request->get();
  55. $categoryId = isset($get['categoryId']) ? $get['categoryId'] : 0;
  56. $status = isset($get['status']) ? $get['status'] : 0;
  57. $category = CategoryService::getById($categoryId);
  58. CategoryService::valid($category, $this->mainId);
  59. CategoryService::changeStatus($categoryId, $status);
  60. util::complete();
  61. }
  62. //删除分类 ssh 2019.12.28
  63. public function actionDelete()
  64. {
  65. $get = Yii::$app->request->get();
  66. $categoryId = $get['categoryId'] ?? 0;
  67. $category = CategoryService::getById($categoryId);
  68. CategoryService::valid($category, $this->mainId);
  69. CategoryClass::deleteCategory($categoryId);
  70. util::complete('删除成功');
  71. }
  72. //分类排序 ssh 2020.3.11
  73. public function actionSort()
  74. {
  75. $id = Yii::$app->request->get('id', 0);
  76. $inTurn = Yii::$app->request->get('inTurn', 0);
  77. $category = CategoryService::getById($id);
  78. CategoryService::valid($category, $this->mainId);
  79. CategoryService::updateById($id, ['inTurn' => $inTurn]);
  80. util::complete();
  81. }
  82. }