StoreProductGroup.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2024 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\controller\admin\store;
  12. use app\common\repositories\store\product\ProductGroupRepository;
  13. use app\common\repositories\store\product\ProductRepository;
  14. use app\common\repositories\store\product\SpuRepository;
  15. use app\validate\merchant\StoreProductAdminValidate as validate;
  16. use crmeb\basic\BaseController;
  17. use think\App;
  18. /**
  19. * 拼团商品信息
  20. */
  21. class StoreProductGroup extends BaseController
  22. {
  23. protected $repository;
  24. /**
  25. * @param App $app
  26. * @param ProductGroupRepository $repository
  27. */
  28. public function __construct(App $app, ProductGroupRepository $repository)
  29. {
  30. parent::__construct($app);
  31. $this->repository = $repository;
  32. }
  33. /**
  34. * 列表
  35. * @return \think\response\Json
  36. * @author Qinii
  37. */
  38. public function lst()
  39. {
  40. [$page, $limit] = $this->getPage();
  41. $where = $this->request->params(['product_status', 'keyword', 'status', 'active_type', 'mer_id', 'is_trader', 'level', 'us_status', 'star', 'product_group_id', 'sys_labels']);
  42. $data = $this->repository->getAdminList($where, $page, $limit);
  43. return app('json')->success($data);
  44. }
  45. /**
  46. * 详情
  47. * @param $id
  48. * @return mixed
  49. * @author Qinii
  50. * @day 2020-10-12
  51. */
  52. public function detail($id)
  53. {
  54. $data = $this->repository->detail(null, $id);
  55. return app('json')->success($data);
  56. }
  57. /**
  58. * 获取商品
  59. * @param $id
  60. * @return mixed
  61. * @author Qinii
  62. * @day 2020-11-02
  63. */
  64. public function get($id)
  65. {
  66. $data = $this->repository->get($id);
  67. if (!$data) return app('json')->fail('数据不存在');
  68. $res = app()->make(ProductRepository::class)->getAdminOneProduct($data['product_id'], $id);
  69. $res['product_group_id'] = $id;
  70. if (!$data) return app('json')->fail('数据不存在');
  71. return app('json')->success($res);
  72. }
  73. /**
  74. * 编辑商品
  75. * @param $id
  76. * @param validate $validate
  77. * @return mixed
  78. * @author Qinii
  79. * @day 2020-11-02
  80. */
  81. public function update($id, validate $validate)
  82. {
  83. $data = $this->checkParams($validate);
  84. if (!$this->repository->getWhereCount([$this->repository->getPk() => $id]))
  85. return app('json')->fail('数据不存在');
  86. $this->repository->updateProduct($id, $data);
  87. return app('json')->success('编辑成功');
  88. }
  89. /**
  90. * 修改状态
  91. * @param $id
  92. * @return \think\response\Json
  93. * @author Qinii
  94. */
  95. public function switchStatus($id)
  96. {
  97. $status = $this->request->param('status', 0) == 1 ? 1 : 0;
  98. if (!$ret = $this->repository->get($id))
  99. return app('json')->fail('数据不存在');
  100. $this->repository->update($id, ['status' => $status]);
  101. app()->make(SpuRepository::class)->changeStatus($id, 4);
  102. return app('json')->success('修改成功');
  103. }
  104. /**
  105. * 验证参数
  106. * @param validate $validate
  107. * @return array|mixed|string|string[]
  108. * @author Qinii
  109. */
  110. public function checkParams(validate $validate)
  111. {
  112. $data = $this->request->params(['is_hot', 'is_best', 'is_benefit', 'is_new', 'store_name', 'keyword', 'content', 'rank', 'star']);
  113. $validate->check($data);
  114. return $data;
  115. }
  116. /**
  117. * 审核
  118. * @return \think\response\Json
  119. * @author Qinii
  120. */
  121. public function switchAudit()
  122. {
  123. $id = $this->request->param('id');
  124. $data = $this->request->params(['status', 'refusal']);
  125. if ($data['status'] == -1 && empty($data['refusal']))
  126. return app('json')->fail('请填写拒绝理由');
  127. $this->repository->switchStatus($id, $data);
  128. return app('json')->success('操作成功');
  129. }
  130. /**
  131. * 编辑排序
  132. * @param $id
  133. * @return \think\response\Json
  134. * @author Qinii
  135. */
  136. public function updateSort($id)
  137. {
  138. $sort = $this->request->param('sort');
  139. $this->repository->updateSort($id, null, ['rank' => $sort]);
  140. return app('json')->success('修改成功');
  141. }
  142. /**
  143. * 编辑标签
  144. * @param $id
  145. * @return \think\response\Json
  146. * @author Qinii
  147. */
  148. public function setLabels($id)
  149. {
  150. $data = $this->request->params(['sys_labels']);
  151. // if (empty($data['sys_labels'])) return app('json')->fail('标签为空');
  152. app()->make(SpuRepository::class)->setLabels($id, 4, $data, 0);
  153. return app('json')->success('修改成功');
  154. }
  155. }