StoreProductPresell.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2024 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\store\product\SpuRepository;
  14. use crmeb\basic\BaseController;
  15. use think\App;
  16. use app\validate\merchant\StoreProductAdminValidate as validate;
  17. /**
  18. * 商品预售活动
  19. */
  20. class StoreProductPresell extends BaseController
  21. {
  22. protected $repository;
  23. /**
  24. * Product constructor.
  25. * @param App $app
  26. * @param repository $repository
  27. */
  28. public function __construct(App $app, repository $repository)
  29. {
  30. parent::__construct($app);
  31. $this->repository = $repository;
  32. }
  33. /**
  34. * 列表
  35. * @return mixed
  36. * @author Qinii
  37. * @day 2020-10-12
  38. */
  39. public function lst()
  40. {
  41. [$page, $limit] = $this->getPage();
  42. $where = $this->request->params(['product_status', 'keyword', 'status', 'type', 'presell_type', 'mer_id', 'is_trader', 'us_status', 'star', 'product_presell_id', 'sys_labels']);
  43. $data = $this->repository->getAdminList($where, $page, $limit);
  44. return app('json')->success($data);
  45. }
  46. /**
  47. * 详情
  48. * @param $id
  49. * @return mixed
  50. * @author Qinii
  51. * @day 2020-10-12
  52. */
  53. public function detail($id)
  54. {
  55. $data = $this->repository->detail(null, $id);
  56. return app('json')->success($data);
  57. }
  58. /**
  59. * 获取商品
  60. * @param $id
  61. * @return mixed
  62. * @author Qinii
  63. * @day 2020-11-02
  64. */
  65. public function get($id)
  66. {
  67. $data = $this->repository->get($id);
  68. if (!$data) return app('json')->fail('数据不存在');
  69. return app('json')->success($data);
  70. }
  71. /**
  72. * 编辑商品
  73. * @param $id
  74. * @param validate $validate
  75. * @return mixed
  76. * @author Qinii
  77. * @day 2020-11-02
  78. */
  79. public function update($id, validate $validate)
  80. {
  81. $data = $this->checkParams($validate);
  82. if (!$this->repository->getWhereCount([$this->repository->getPk() => $id]))
  83. return app('json')->fail('数据不存在');
  84. $this->repository->updateProduct($id, $data);
  85. return app('json')->success('编辑成功');
  86. }
  87. /**
  88. * 修改状态
  89. * @param $id
  90. * @return \think\response\Json
  91. * @author Qinii
  92. */
  93. public function switchStatus($id)
  94. {
  95. $status = $this->request->param('status', 0) == 1 ? 1 : 0;
  96. if (!$ret = $this->repository->get($id)) return app('json')->fail('数据不存在');
  97. $this->repository->update($id, ['status' => $status]);
  98. app()->make(SpuRepository::class)->changeStatus($id, 2);
  99. return app('json')->success('修改成功');
  100. }
  101. /**
  102. * 参数验证
  103. * @param validate $validate
  104. * @return array|mixed|string|string[]
  105. * @author Qinii
  106. */
  107. public function checkParams(validate $validate)
  108. {
  109. $data = $this->request->params(['is_hot', 'is_best', 'is_benefit', 'is_new', 'store_name', 'keyword', 'content', 'rank', 'star']);
  110. $validate->check($data);
  111. return $data;
  112. }
  113. /**
  114. * 审核
  115. * @return \think\response\Json
  116. * @author Qinii
  117. * @day 2022/11/15
  118. */
  119. public function switchAudit()
  120. {
  121. $id = $this->request->param('id');
  122. $data = $this->request->params(['status', 'refusal']);
  123. if ($data['status'] == -1 && empty($data['refusal']))
  124. return app('json')->fail('请填写拒绝理由');
  125. $this->repository->switchStatus($id, $data);
  126. return app('json')->success('操作成功');
  127. }
  128. /**
  129. * 修改标签
  130. * @param $id
  131. * @return \think\response\Json
  132. * @author Qinii
  133. */
  134. public function setLabels($id)
  135. {
  136. $data = $this->request->params(['sys_labels']);
  137. // if (empty($data['sys_labels'])) return app('json')->fail('标签为空');
  138. app()->make(SpuRepository::class)->setLabels($id, 2, $data, 0);
  139. return app('json')->success('修改成功');
  140. }
  141. }