StoreProductAssist.php 4.7 KB

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