StoreProductGroup.php 5.0 KB

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