ProductPresell.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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\ProductPresellRepository 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\StoreProductPresellValidate;
  18. class ProductPresell 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', 'type', 'presell_type', 'is_show', 'us_status','product_presell_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 StoreProductPresellValidate $validate
  47. * @return mixed
  48. * @author Qinii
  49. * @day 2020-10-12
  50. */
  51. public function create(StoreProductPresellValidate $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 StoreProductPresellValidate $validate
  73. * @return mixed
  74. * @author Qinii
  75. * @day 2020-10-13
  76. */
  77. public function update($id, StoreProductPresellValidate $validate)
  78. {
  79. $data = $this->checkParams($validate);
  80. $where = [
  81. $this->repository->getPk() => $id,
  82. 'mer_id' => $this->request->merId()
  83. ];
  84. if (!$this->repository->getWhere($where))
  85. return app('json')->fail('数据不存在');
  86. $data['mer_id'] = $this->request->merId();
  87. $this->repository->edit($id, $data);
  88. return app('json')->success('编辑成功');
  89. }
  90. public function delete($id)
  91. {
  92. $where = [
  93. $this->repository->getPk() => $id,
  94. 'mer_id' => $this->request->merId()
  95. ];
  96. $this->repository->delete($where);
  97. return app('json')->success('删除成功');
  98. }
  99. public function switchStatus($id)
  100. {
  101. $status = $this->request->param('status', 0) == 1 ? 1 : 0;
  102. if (!$this->repository->detail($this->request->merId(), $id))
  103. return app('json')->fail('数据不存在');
  104. $this->repository->update($id, ['is_show' => $status]);
  105. app()->make(SpuRepository::class)->changeStatus($id,2);
  106. return app('json')->success('修改成功');
  107. }
  108. public function number()
  109. {
  110. return app('json')->success($this->repository->stat($this->request->merId()));
  111. }
  112. public function checkParams(StoreProductPresellValidate $validate)
  113. {
  114. $params = [
  115. "image", "slider_image", "store_name", "store_info", "product_id", "is_show", "temp_id", "attrValue","sort","guarantee_template_id",
  116. "start_time", "end_time", "final_start_time", "final_end_time", "status", "presell_type", 'pay_count', "delivery_type", "delivery_day",
  117. "product_status",'mer_labels','delivery_way','delivery_free'
  118. ];
  119. $data = $this->request->params($params);
  120. $validate->check($data);
  121. return $data;
  122. }
  123. public function updateSort($id)
  124. {
  125. $sort = $this->request->param('sort');
  126. $this->repository->updateSort($id, $this->request->merId(), ['sort' => $sort]);
  127. return app('json')->success('修改成功');
  128. }
  129. public function preview(ProductRepository $repository)
  130. {
  131. $data = $this->request->param();
  132. $data['merchant'] = [
  133. 'mer_name' => $this->request->merchant()->mer_name,
  134. 'is_trader' => $this->request->merchant()->is_trader,
  135. 'mer_avatar' => $this->request->merchant()->mer_avatar,
  136. 'product_score' => $this->request->merchant()->product_score,
  137. 'service_score' => $this->request->merchant()->service_score,
  138. 'postage_score' => $this->request->merchant()->postage_score,
  139. 'service_phone' => $this->request->merchant()->service_phone,
  140. 'care_count' => $this->request->merchant()->care_count,
  141. 'type_name' => $this->request->merchant()->type_name->type_name ?? '',
  142. 'care' => true,
  143. 'recommend' => $this->request->merchant()->recommend,
  144. ];
  145. $data['mer_id'] = $this->request->merId();
  146. $data['status'] = 1;
  147. $data['mer_status'] = 1;
  148. $data['rate'] = 3;
  149. return app('json')->success($repository->preview($data));
  150. }
  151. public function setLabels($id)
  152. {
  153. $data = $this->request->params(['mer_labels']);
  154. // if (empty($data['mer_labels'])) return app('json')->fail('标签为空');
  155. app()->make(SpuRepository::class)->setLabels($id,2,$data,$this->request->merId());
  156. return app('json')->success('修改成功');
  157. }
  158. }