StoreCategory.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2023 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\outapi\controller;
  12. use think\facade\App;
  13. use app\outapi\validate\StoreCategoryValidate;
  14. use app\services\product\product\StoreCategoryServices;
  15. /**
  16. * 商品分类控制器
  17. * Class StoreCategory
  18. * @package app\outapi\controller
  19. */
  20. class StoreCategory extends AuthController
  21. {
  22. /**
  23. * @var StoreCategoryServices
  24. */
  25. protected $services;
  26. /**
  27. * StoreCategory constructor.
  28. * @param App $app
  29. * @param StoreCategoryServices $services
  30. */
  31. public function __construct(App $app, StoreCategoryServices $services)
  32. {
  33. parent::__construct($app);
  34. $this->services = $services;
  35. }
  36. /**
  37. * 分类列表
  38. * @return mixed
  39. * @throws \think\db\exception\DataNotFoundException
  40. * @throws \think\db\exception\DbException
  41. * @throws \think\db\exception\ModelNotFoundException
  42. */
  43. public function index()
  44. {
  45. $where = $this->request->getMore([
  46. ['is_show', ''],
  47. ['pid', ''],
  48. ['cate_name', ''],
  49. ]);
  50. $where['pid'] = -2;
  51. $data = $this->services->getCategoryList($where);
  52. return app('json')->success($data);
  53. }
  54. /**
  55. * 新增分类
  56. * @return mixed
  57. */
  58. public function save()
  59. {
  60. $data = $this->request->postMore([
  61. ['pid', 0],
  62. ['cate_name', ''],
  63. ['pic', ''],
  64. ['big_pic', ''],
  65. ['sort', 0],
  66. ['is_show', 0]
  67. ]);
  68. $this->validate($data, StoreCategoryValidate::class, 'save');
  69. $cateId = $this->services->createData($data);
  70. return app('json')->success(100000, ['id' => $cateId]);
  71. }
  72. /**
  73. * 更新分类
  74. * @param $id
  75. * @return mixed
  76. */
  77. public function update($id)
  78. {
  79. $data = $this->request->postMore([
  80. ['pid', 0],
  81. ['cate_name', ''],
  82. ['pic', ''],
  83. ['big_pic', ''],
  84. ['sort', 0],
  85. ['is_show', 0]
  86. ]);
  87. $this->validate($data, StoreCategoryValidate::class, 'save');
  88. $this->services->editData($id, $data);
  89. return app('json')->success(100001);
  90. }
  91. /**
  92. * 删除分类
  93. * @param $id
  94. * @return mixed
  95. */
  96. public function delete($id)
  97. {
  98. $this->services->del((int)$id);
  99. return app('json')->success(100002);
  100. }
  101. /**
  102. * 详情
  103. * @param $id
  104. * @return mixed
  105. */
  106. public function read($id)
  107. {
  108. $info = $this->services->getInfo((int)$id);
  109. return app('json')->success($info);
  110. }
  111. /**
  112. * 修改状态
  113. * @param string $id
  114. * @param string $is_show
  115. */
  116. public function set_show($id = '', $is_show = '')
  117. {
  118. if ( $id == '' || $is_show == '') return app('json')->fail(100100);
  119. $this->services->setShow((int)$id, (int)$is_show);
  120. return app('json')->success($is_show == 1 ? 100003 : 100004);
  121. }
  122. }