StoreProductAssist.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 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\validate\merchant\StoreProductAdminValidate as validate;
  14. use crmeb\basic\BaseController;
  15. use crmeb\jobs\ChangeSpuStatusJob;
  16. use crmeb\services\SwooleTaskService;
  17. use think\App;
  18. class StoreProductAssist extends BaseController
  19. {
  20. protected $repository ;
  21. /**
  22. * Product constructor.
  23. * @param App $app
  24. * @param repository $repository
  25. */
  26. public function __construct(App $app ,repository $repository)
  27. {
  28. parent::__construct($app);
  29. $this->repository = $repository;
  30. }
  31. /**
  32. * TODO 列表
  33. * @return mixed
  34. * @author Qinii
  35. * @day 2020-10-12
  36. */
  37. public function lst()
  38. {
  39. [$page, $limit] = $this->getPage();
  40. $where = $this->request->params(['product_status','keyword','status','type','mer_id','is_trader','us_status','star','product_assist_id']);
  41. $data = $this->repository->getAdminList($where,$page,$limit);
  42. return app('json')->success($data);
  43. }
  44. /**
  45. * TODO 详情
  46. * @param $id
  47. * @return mixed
  48. * @author Qinii
  49. * @day 2020-10-12
  50. */
  51. public function detail($id)
  52. {
  53. $data = $this->repository->detail(null,$id);
  54. return app('json')->success($data);
  55. }
  56. public function switchStatus($id)
  57. {
  58. $status = $this->request->param('status', 0) == 1 ? 1 : 0;
  59. if(!$ret = $this->repository->get($id))
  60. return app('json')->fail('数据不存在');
  61. $this->repository->update($id, ['status' => $status]);
  62. // if(!$status) SwooleTaskService::merchant('notice', [
  63. // 'type' => 'product_assist',
  64. // 'data' => [
  65. // 'title' => '下架提醒',
  66. // 'message' => '您有一个助力商品被下架',
  67. // 'id' => $id
  68. // ]
  69. // ], $ret->mer_id);
  70. queue(ChangeSpuStatusJob::class,['id' => $id,'product_type' => 3]);
  71. return app('json')->success('修改成功');
  72. }
  73. /**
  74. * TODO 获取商品
  75. * @param $id
  76. * @return mixed
  77. * @author Qinii
  78. * @day 2020-11-02
  79. */
  80. public function get($id)
  81. {
  82. if(!$this->repository->getWhereCount([$this->repository->getPk() => $id]))
  83. return app('json')->fail('数据不存在');
  84. $data = $this->repository->get($id);
  85. return app('json')->success($data);
  86. }
  87. /**
  88. * TODO 编辑商品
  89. * @param $id
  90. * @param validate $validate
  91. * @return mixed
  92. * @author Qinii
  93. * @day 2020-11-02
  94. */
  95. public function update($id,validate $validate)
  96. {
  97. $data = $this->checkParams($validate);
  98. if(!$this->repository->getWhereCount([$this->repository->getPk() => $id]))
  99. return app('json')->fail('数据不存在');
  100. $this->repository->updateProduct($id,$data);
  101. return app('json')->success('编辑成功');
  102. }
  103. public function checkParams(validate $validate)
  104. {
  105. $data = $this->request->params(['is_hot','is_best','is_benefit','is_new','store_name','keyword','content','rank','star']);
  106. $validate->check($data);
  107. return $data;
  108. }
  109. public function productStatus()
  110. {
  111. $id = $this->request->param('id');
  112. if(!$ret = $this->repository->get($id))
  113. return app('json')->fail('数据不存在');
  114. $data = $this->request->params(['status','refusal']);
  115. if($data['status'] == -1 && empty($data['refusal']))
  116. return app('json')->fail('请填写拒绝理由');
  117. if(!is_array($id)) $id = [$id];
  118. $status = 0;
  119. if($data['status'] == 1){
  120. $status = 1;
  121. $title = '审核结果';
  122. $message = '审核通过';
  123. $type = "product_assist_success";
  124. }
  125. if($data['status'] == -1){
  126. $title = '审核结果';
  127. $message = '审核失败';
  128. $type = "product_assist_fail";
  129. }
  130. if($data['status'] == -2){
  131. $title = '下架提醒';
  132. $message = '被下架';
  133. $type = "product_assist_fail";
  134. }
  135. $this->repository->updates($id,['product_status' => $data['status'],'refusal' => $data['refusal'],'status' => $status]);
  136. SwooleTaskService::merchant('notice', [
  137. 'type' => $type,
  138. 'data' => [
  139. 'title' => $title,
  140. 'message' => '您有一个助力商品'. $message,
  141. 'id' => $id[0]
  142. ]
  143. ], $ret->mer_id);
  144. foreach ($id as $item){
  145. queue(ChangeSpuStatusJob::class,['id' => $item,'product_type' => 3]);
  146. }
  147. return app('json')->success('操作成功');
  148. }
  149. }