StoreProductPresell.php 5.1 KB

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