ProductPresell.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. <?php
  2. namespace app\controller\merchant\store\product;
  3. use app\common\repositories\store\product\ProductPresellRepository as repository;
  4. use app\common\repositories\store\product\ProductRepository;
  5. use ln\basic\BaseController;
  6. use ln\jobs\ChangeSpuStatusJob;
  7. use think\App;
  8. use app\validate\merchant\StoreProductPresellValidate;
  9. class ProductPresell extends BaseController
  10. {
  11. protected $repository;
  12. /**
  13. * Product constructor.
  14. * @param App $app
  15. * @param repository $repository
  16. */
  17. public function __construct(App $app, repository $repository)
  18. {
  19. parent::__construct($app);
  20. $this->repository = $repository;
  21. }
  22. /**
  23. * TODO 列表
  24. * @return mixed
  25. * @author Qinii
  26. * @day 2020-10-12
  27. */
  28. public function lst()
  29. {
  30. [$page, $limit] = $this->getPage();
  31. $where = $this->request->params(['product_status', 'keyword', 'type', 'presell_type', 'is_show', 'us_status','product_presell_id']);
  32. $where['mer_id'] = $this->request->merId();
  33. return app('json')->success($this->repository->getMerchantList($where, $page, $limit));
  34. }
  35. /**
  36. * TODO 添加
  37. * @param StoreProductPresellValidate $validate
  38. * @return mixed
  39. * @author Qinii
  40. * @day 2020-10-12
  41. */
  42. public function create(StoreProductPresellValidate $validate)
  43. {
  44. $data = $this->checkParams($validate);
  45. $this->repository->create($this->request->merId(), $data);
  46. return app('json')->success('添加成功');
  47. }
  48. /**
  49. * TODO 详情
  50. * @param $id
  51. * @return mixed
  52. * @author Qinii
  53. * @day 2020-10-12
  54. */
  55. public function detail($id)
  56. {
  57. $data = $this->repository->detail($this->request->merId(), $id);
  58. return app('json')->success($data);
  59. }
  60. /**
  61. * TODO
  62. * @param $id
  63. * @param StoreProductPresellValidate $validate
  64. * @return mixed
  65. * @author Qinii
  66. * @day 2020-10-13
  67. */
  68. public function update($id, StoreProductPresellValidate $validate)
  69. {
  70. $data = $this->checkParams($validate);
  71. $where = [
  72. $this->repository->getPk() => $id,
  73. 'mer_id' => $this->request->merId()
  74. ];
  75. if (!$this->repository->getWhere($where))
  76. return app('json')->fail('数据不存在');
  77. $data['mer_id'] = $this->request->merId();
  78. $this->repository->edit($id, $data);
  79. return app('json')->success('编辑成功');
  80. }
  81. public function delete($id)
  82. {
  83. $where = [
  84. $this->repository->getPk() => $id,
  85. 'mer_id' => $this->request->merId()
  86. ];
  87. $this->repository->delete($where);
  88. return app('json')->success('删除成功');
  89. }
  90. public function switchStatus($id)
  91. {
  92. $status = $this->request->param('status', 0) == 1 ? 1 : 0;
  93. if (!$this->repository->detail($this->request->merId(), $id))
  94. return app('json')->fail('数据不存在');
  95. $this->repository->update($id, ['is_show' => $status]);
  96. Queue(ChangeSpuStatusJob::class, ['product_type' => 2, 'id' => $id]);
  97. return app('json')->success('修改成功');
  98. }
  99. public function number()
  100. {
  101. return app('json')->success($this->repository->stat($this->request->merId()));
  102. }
  103. public function checkParams(StoreProductPresellValidate $validate)
  104. {
  105. $params = [
  106. "image", "slider_image", "store_name", "store_info", "product_id", "is_show", "temp_id", "attrValue","sort","guarantee_template_id",
  107. "start_time", "end_time", "final_start_time", "final_end_time", "status", "presell_type", 'pay_count', "delivery_type", "delivery_day", "product_status",
  108. ];
  109. $data = $this->request->params($params);
  110. $validate->check($data);
  111. return $data;
  112. }
  113. public function updateSort($id)
  114. {
  115. $sort = $this->request->param('sort');
  116. $this->repository->updateSort($id, $this->request->merId(), ['sort' => $sort]);
  117. return app('json')->success('修改成功');
  118. }
  119. public function preview(ProductRepository $repository)
  120. {
  121. $data = $this->request->param();
  122. $data['merchant'] = [
  123. 'mer_name' => $this->request->merchant()->mer_name,
  124. 'is_trader' => $this->request->merchant()->is_trader,
  125. 'mer_avatar' => $this->request->merchant()->mer_avatar,
  126. 'product_score' => $this->request->merchant()->product_score,
  127. 'service_score' => $this->request->merchant()->service_score,
  128. 'postage_score' => $this->request->merchant()->postage_score,
  129. 'service_phone' => $this->request->merchant()->service_phone,
  130. 'care_count' => $this->request->merchant()->care_count,
  131. 'type_name' => $this->request->merchant()->type_name->type_name ?? '',
  132. 'care' => true,
  133. 'recommend' => $this->request->merchant()->recommend,
  134. ];
  135. $data['mer_id'] = $this->request->merId();
  136. $data['status'] = 1;
  137. $data['mer_status'] = 1;
  138. $data['rate'] = 3;
  139. return app('json')->success($repository->preview($data));
  140. }
  141. }