StoreProductAssist.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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\ProductAssistRepository as repository;
  13. use app\common\repositories\store\product\SpuRepository;
  14. use app\validate\merchant\StoreProductAdminValidate as validate;
  15. use crmeb\basic\BaseController;
  16. use crmeb\services\SwooleTaskService;
  17. use think\App;
  18. /**
  19. * 商品助力活动
  20. */
  21. class StoreProductAssist extends BaseController
  22. {
  23. protected $repository;
  24. /**
  25. * Product constructor.
  26. * @param App $app
  27. * @param repository $repository
  28. */
  29. public function __construct(App $app, repository $repository)
  30. {
  31. parent::__construct($app);
  32. $this->repository = $repository;
  33. }
  34. /**
  35. * 列表
  36. * @return mixed
  37. * @author Qinii
  38. * @day 2020-10-12
  39. */
  40. public function lst()
  41. {
  42. [$page, $limit] = $this->getPage();
  43. $where = $this->request->params(['product_status', 'keyword', 'status', 'type', 'mer_id', 'is_trader', 'us_status', 'star', 'product_assist_id', 'sys_labels']);
  44. $data = $this->repository->getAdminList($where, $page, $limit);
  45. return app('json')->success($data);
  46. }
  47. /**
  48. * 详情
  49. * @param $id
  50. * @return mixed
  51. * @author Qinii
  52. * @day 2020-10-12
  53. */
  54. public function detail($id)
  55. {
  56. $data = $this->repository->detail(null, $id);
  57. return app('json')->success($data);
  58. }
  59. /**
  60. * 修改状态
  61. * @param $id
  62. * @return \think\response\Json
  63. * @author Qinii
  64. */
  65. public function switchStatus($id)
  66. {
  67. $status = $this->request->param('status', 0) == 1 ? 1 : 0;
  68. if (!$ret = $this->repository->get($id))
  69. return app('json')->fail('数据不存在');
  70. $this->repository->update($id, ['status' => $status]);
  71. app()->make(SpuRepository::class)->changeStatus($id, 3);
  72. return app('json')->success('修改成功');
  73. }
  74. /**
  75. * 获取商品
  76. * @param $id
  77. * @return mixed
  78. * @author Qinii
  79. * @day 2020-11-02
  80. */
  81. public function get($id)
  82. {
  83. if (!$this->repository->getWhereCount([$this->repository->getPk() => $id]))
  84. return app('json')->fail('数据不存在');
  85. $data = $this->repository->get($id);
  86. return app('json')->success($data);
  87. }
  88. /**
  89. * 编辑商品
  90. * @param $id
  91. * @param validate $validate
  92. * @return mixed
  93. * @author Qinii
  94. * @day 2020-11-02
  95. */
  96. public function update($id, validate $validate)
  97. {
  98. $data = $this->checkParams($validate);
  99. if (!$this->repository->getWhereCount([$this->repository->getPk() => $id]))
  100. return app('json')->fail('数据不存在');
  101. $this->repository->updateProduct($id, $data);
  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. * @day 2022/11/15
  121. */
  122. public function switchAudit()
  123. {
  124. $id = $this->request->param('id');
  125. if (!$ret = $this->repository->get($id))
  126. return app('json')->fail('数据不存在');
  127. $data = $this->request->params(['status', 'refusal']);
  128. if ($data['status'] == -1 && empty($data['refusal']))
  129. return app('json')->fail('请填写拒绝理由');
  130. $this->repository->switchStatus($id, $data);
  131. return app('json')->success('操作成功');
  132. }
  133. /**
  134. * 修改标签
  135. * @param $id
  136. * @return \think\response\Json
  137. * @author Qinii
  138. */
  139. public function setLabels($id)
  140. {
  141. $data = $this->request->params(['sys_labels']);
  142. app()->make(SpuRepository::class)->setLabels($id, 3, $data, 0);
  143. return app('json')->success('修改成功');
  144. }
  145. }