Product.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  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\points;
  12. use app\common\repositories\store\product\ProductRepository;
  13. use app\validate\merchant\StoreProductValidate;
  14. use think\App;
  15. use crmeb\basic\BaseController;
  16. use app\validate\merchant\StoreProductAdminValidate as validate;
  17. use app\common\repositories\store\pionts\PointsProductRepository;
  18. /**
  19. * 积分商品
  20. */
  21. class Product extends BaseController
  22. {
  23. /**
  24. * @var PointsProductRepository
  25. */
  26. protected $repository;
  27. /**
  28. * StoreProduct constructor.
  29. * @param App $app
  30. * @param PointsProductRepository $repository
  31. */
  32. public function __construct(App $app, PointsProductRepository $repository)
  33. {
  34. parent::__construct($app);
  35. $this->repository = $repository;
  36. }
  37. /**
  38. * 列表
  39. * @Author:Qinii
  40. * @Date: 2020/5/18
  41. * @return mixed
  42. */
  43. public function lst()
  44. {
  45. [$page, $limit] = $this->getPage();
  46. $where = $this->request->params(['cate_id', 'keyword', 'is_used', 'date', 'store_name']);
  47. return app('json')->success($this->repository->getAdminList(0, $where, $page, $limit));
  48. }
  49. /**
  50. * 添加
  51. * @return \think\response\Json
  52. * @author Qinii
  53. */
  54. public function create()
  55. {
  56. $data = $this->checkParams();
  57. $this->repository->create($data, $this->repository::PRODUCT_TYPE_POINTS);
  58. return app('json')->success('添加成功');
  59. }
  60. /**
  61. * 头部筛选 统计
  62. * @Author:Qinii
  63. * @Date: 2020/5/18
  64. * @return mixed
  65. */
  66. public function getStatusFilter()
  67. {
  68. return app('json')->success($this->repository->getFilter(null, '商品', 0));
  69. }
  70. /**
  71. * 详情
  72. * @Author:Qinii
  73. * @Date: 2020/5/18
  74. * @param $id
  75. * @return mixed
  76. */
  77. public function detail($id)
  78. {
  79. return app('json')->success($this->repository->detail($id));
  80. }
  81. /**
  82. * 编辑
  83. * @Author:Qinii
  84. * @Date: 2020/5/11
  85. * @param $id
  86. * @param validate $validate
  87. * @return mixed
  88. */
  89. public function update($id)
  90. {
  91. $data = $this->checkParams();
  92. $this->repository->edit($id, $data, $this->request->merId(), $this->repository::PRODUCT_TYPE_POINTS);
  93. return app('json')->success('编辑成功');
  94. }
  95. /**
  96. * 上 / 下架
  97. * @Author:Qinii
  98. * @Date: 2020/5/18
  99. * @param int $id
  100. * @return mixed
  101. */
  102. public function switchStatus($id)
  103. {
  104. if (!$this->repository->merExists(null, $id))
  105. return app('json')->fail('数据不存在');
  106. $status = $this->request->param('status', 0) == 1 ? 1 : 0;
  107. $this->repository->switchShow($id, $status, 'is_used');
  108. return app('json')->success('修改成功');
  109. }
  110. /**
  111. * 删除
  112. * @Author:Qinii
  113. * @Date: 2020/5/18
  114. * @param $id
  115. * @return mixed
  116. */
  117. public function delete($id)
  118. {
  119. if (!$this->repository->merExists($this->request->merId(), $id))
  120. return app('json')->fail('数据不存在');
  121. $this->repository->destory($id);
  122. return app('json')->success('删除成功');
  123. }
  124. /**
  125. * 验证数据
  126. * @Author:Qinii
  127. * @Date: 2020/5/11
  128. * @param validate $validate
  129. * @return array
  130. */
  131. public function checkParams()
  132. {
  133. $data = $this->request->params($this->repository::CREATE_PARAMS);
  134. $data['mer_status'] = 1;
  135. $data['delivery_way'] = [2];
  136. $data['delivery_free'] = 1;
  137. $data['is_used'] = $this->request->param('is_used', 0);
  138. $data['is_hot'] = $this->request->param('is_hot', 0);
  139. $data['is_show'] = 1;
  140. $data['status'] = 1;
  141. $data['pay_limit'] = 2;
  142. $data['product_type'] = $this->repository::PRODUCT_TYPE_POINTS;
  143. app()->make(StoreProductValidate::class)->check($data);
  144. return $data;
  145. }
  146. /**
  147. * 设置排序
  148. * @param $id
  149. * @return \think\response\Json
  150. * @author Qinii
  151. * @day 3/17/21
  152. */
  153. public function updateSort($id)
  154. {
  155. $sort = $this->request->param('sort');
  156. $this->repository->updateSort($id, null, ['rank' => $sort]);
  157. return app('json')->success('修改成功');
  158. }
  159. /**
  160. * 批量显示隐藏
  161. * @return \think\response\Json
  162. * @author Qinii
  163. * @day 2022/11/14
  164. */
  165. public function batchShow()
  166. {
  167. $ids = $this->request->param('ids');
  168. $status = $this->request->param('status') == 1 ? 1 : 0;
  169. $this->repository->batchSwitchShow($ids, $status, 'is_used', 0);
  170. return app('json')->success('修改成功');
  171. }
  172. /**
  173. * 获取商品的规格
  174. * @param $id
  175. * @return mixed
  176. * @author Qinii
  177. */
  178. public function isFormatAttr($id)
  179. {
  180. $data = $this->request->params([
  181. ['attrs', []],
  182. ['items', []],
  183. ['product_type', 0]
  184. ]);
  185. $data = app()->make(ProductRepository::class)->isFormatAttr($data['attrs'], $id);
  186. return app('json')->success($data);
  187. }
  188. /**
  189. * 预览
  190. * @return \think\response\Json
  191. * @author Qinii
  192. */
  193. public function preview()
  194. {
  195. $data = $this->request->param();
  196. return app('json')->success($this->repository->preview($data));
  197. }
  198. }