StoreProductPresell.php 5.8 KB

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