ProductPresell.php 4.5 KB

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