ProductAssist.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2022 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\merchant\store\product;
  12. use app\common\repositories\store\product\ProductAssistRepository as repository;
  13. use app\common\repositories\store\product\ProductRepository;
  14. use app\common\repositories\store\product\SpuRepository;
  15. use crmeb\basic\BaseController;
  16. use think\App;
  17. use app\validate\merchant\StoreProductAssistValidate;
  18. class ProductAssist extends BaseController
  19. {
  20. protected $repository ;
  21. /**
  22. * Product constructor.
  23. * @param App $app
  24. * @param repository $repository
  25. */
  26. public function __construct(App $app ,repository $repository)
  27. {
  28. parent::__construct($app);
  29. $this->repository = $repository;
  30. }
  31. /**
  32. * TODO 列表
  33. * @return mixed
  34. * @author Qinii
  35. * @day 2020-10-12
  36. */
  37. public function lst()
  38. {
  39. [$page, $limit] = $this->getPage();
  40. $where = $this->request->params(['product_status','keyword','is_show','type','presell_type','us_status','product_assist_id','mer_labels']);
  41. $where['mer_id'] = $this->request->merId();
  42. return app('json')->success($this->repository->getMerchantList($where,$page,$limit));
  43. }
  44. /**
  45. * TODO 添加
  46. * @param StoreProductAssistValidate $validate
  47. * @return mixed
  48. * @author Qinii
  49. * @day 2020-10-12
  50. */
  51. public function create(StoreProductAssistValidate $validate)
  52. {
  53. $data = $this->checkParams($validate);
  54. $this->repository->create($this->request->merId(),$data);
  55. return app('json')->success('添加成功');
  56. }
  57. /**
  58. * TODO 详情
  59. * @param $id
  60. * @return mixed
  61. * @author Qinii
  62. * @day 2020-10-12
  63. */
  64. public function detail($id)
  65. {
  66. $data = $this->repository->detail($this->request->merId(),$id);
  67. return app('json')->success($data);
  68. }
  69. /**
  70. * TODO
  71. * @param $id
  72. * @param StoreProductAssistValidate $validate
  73. * @return mixed
  74. * @author Qinii
  75. * @day 2020-10-13
  76. */
  77. public function update($id,StoreProductAssistValidate $validate)
  78. {
  79. $data = $this->checkParams($validate->isUpdate());
  80. $this->repository->edit($id,$data);
  81. return app('json')->success('编辑成功');
  82. }
  83. public function delete($id)
  84. {
  85. $where = [
  86. $this->repository->getPk() => $id,
  87. 'mer_id' => $this->request->merId()
  88. ];
  89. $this->repository->delete($where);
  90. return app('json')->success('删除成功');
  91. }
  92. public function switchStatus($id)
  93. {
  94. $status = $this->request->param('status', 0) == 1 ? 1 : 0;
  95. if(!$this->repository->detail($this->request->merId(),$id))
  96. return app('json')->fail('数据不存在');
  97. $this->repository->update($id, ['is_show' => $status]);
  98. app()->make(SpuRepository::class)->changeStatus($id,3);
  99. return app('json')->success('修改成功');
  100. }
  101. public function checkParams(StoreProductAssistValidate $validate)
  102. {
  103. $params = [
  104. "image", "slider_image", "store_name", "store_info", "product_id","is_show","temp_id","attrValue","guarantee_template_id",
  105. "start_time", "end_time", "assist_user_count", "assist_count", "status","pay_count","product_status","sort",'mer_labels','delivery_way','delivery_free',
  106. ];
  107. $data = $this->request->params($params);
  108. $validate->check($data);
  109. return $data;
  110. }
  111. public function updateSort($id)
  112. {
  113. $sort = $this->request->param('sort');
  114. $this->repository->updateSort($id,$this->request->merId(),['sort' => $sort]);
  115. return app('json')->success('修改成功');
  116. }
  117. public function preview(ProductRepository $repository)
  118. {
  119. $data = $this->request->param();
  120. $data['merchant'] = [
  121. 'mer_name' => $this->request->merchant()->mer_name,
  122. 'is_trader' => $this->request->merchant()->is_trader,
  123. 'mer_avatar' => $this->request->merchant()->mer_avatar,
  124. 'product_score' => $this->request->merchant()->product_score,
  125. 'service_score' => $this->request->merchant()->service_score,
  126. 'postage_score' => $this->request->merchant()->postage_score,
  127. 'service_phone' => $this->request->merchant()->service_phone,
  128. 'care_count' => $this->request->merchant()->care_count,
  129. 'type_name' => $this->request->merchant()->type_name->type_name ?? '',
  130. 'care' => true,
  131. 'recommend' => $this->request->merchant()->recommend,
  132. ];
  133. $data['mer_id'] = $this->request->merId();
  134. $data['status'] = 1;
  135. $data['mer_status'] = 1;
  136. $data['rate'] = 3;
  137. return app('json')->success($repository->preview($data));
  138. }
  139. public function setLabels($id)
  140. {
  141. $data = $this->request->params(['mer_labels']);
  142. // if (empty($data['mer_labels'])) return app('json')->fail('标签为空');
  143. app()->make(SpuRepository::class)->setLabels($id,3,$data,$this->request->merId());
  144. return app('json')->success('修改成功');
  145. }
  146. }