StoreProductGroup.php 5.6 KB

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