StoreProduct.php 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  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\api\server;
  12. use app\common\repositories\store\order\StoreCartRepository;
  13. use app\common\repositories\store\product\ProductLabelRepository;
  14. use app\common\repositories\store\product\ProductRepository;
  15. use app\common\repositories\store\service\StoreServiceRepository;
  16. use app\common\repositories\system\merchant\MerchantRepository;
  17. use app\validate\merchant\StoreProductValidate;
  18. use crmeb\basic\BaseController;
  19. use crmeb\services\UploadService;
  20. use think\App;
  21. use think\exception\HttpResponseException;
  22. use think\exception\ValidateException;
  23. /**
  24. * Class StoreProduct
  25. * app\controller\api\server
  26. * 移动客服 商品管理
  27. */
  28. class StoreProduct extends BaseController
  29. {
  30. protected $merId;
  31. protected $repository;
  32. public function __construct(App $app, ProductRepository $repository)
  33. {
  34. parent::__construct($app);
  35. $this->repository = $repository;
  36. $this->merId = $this->request->route('merId');
  37. }
  38. /**
  39. * 头部统计
  40. * @param $merId
  41. * @return \think\response\Json
  42. * @author Qinii
  43. * @day 8/24/21
  44. */
  45. public function title($merId)
  46. {
  47. return app('json')->success($this->repository->getFilter($merId, '', 0));
  48. }
  49. /**
  50. * 列表
  51. * @param $merId
  52. * @return \think\response\Json
  53. * @author Qinii
  54. * @day 8/24/21
  55. */
  56. public function lst($merId)
  57. {
  58. [$page, $limit] = $this->getPage();
  59. $where = $this->request->params(['cate_id', 'keyword', 'mer_cate_id', 'is_gift_bag', 'status', 'us_status', 'product_id', 'mer_labels',['order','sort']]);
  60. $type = $this->request->param('type',1);
  61. $where = array_merge($where, $this->repository->switchType($type, $merId, 0));
  62. return app('json')->success($this->repository->getList($merId, $where, $page, $limit));
  63. }
  64. /**
  65. * 添加
  66. * @param $merId
  67. * @param StoreProductValidate $validate
  68. * @return \think\response\Json
  69. * @author Qinii
  70. * @day 8/24/21
  71. */
  72. public function create($merId, StoreProductValidate $validate)
  73. {
  74. $res = $this->request->params($this->repository::CREATE_PARAMS);
  75. $data = $this->repository->checkParams($res,$merId);
  76. $data['mer_id'] = $merId;
  77. $data['is_gift_bag'] = 0;
  78. $merchant = app()->make(MerchantRepository::class)->get($merId);
  79. $data['status'] = $merchant->is_audit ? 0 : 1;
  80. $data['mer_status'] = ($merchant['is_del'] || !$merchant['mer_state'] || !$merchant['status']) ? 0 : 1;
  81. $data['rate'] = 3;
  82. $this->repository->create($data, 0, 1);
  83. return app('json')->success('添加成功');
  84. }
  85. /**
  86. * 编辑
  87. * @param $merId
  88. * @param $id
  89. * @param StoreProductValidate $validate
  90. * @return \think\response\Json
  91. * @author Qinii
  92. * @day 8/24/21
  93. */
  94. public function update($merId, $id, StoreProductValidate $validate)
  95. {
  96. $res = $this->request->params($this->repository::CREATE_PARAMS);
  97. $data = $this->repository->checkParams($res,$merId,$id);
  98. $merchant = app()->make(MerchantRepository::class)->get($merId);
  99. if (!$this->repository->merExists($merId, $id))
  100. return app('json')->fail('数据不存在');
  101. $pro = $this->repository->getWhere(['product_id' => $id]);
  102. if ($pro->status == -2) {
  103. $data['status'] = 0;
  104. } else {
  105. $data['status'] = $merchant->is_audit ? 0 : 1;
  106. }
  107. $data['mer_status'] = ($merchant['is_del'] || !$merchant['mer_state'] || !$merchant['status']) ? 0 : 1;
  108. $data['mer_id'] = $merId;
  109. $this->repository->edit($id, $data, $merId, 0, 1);
  110. return app('json')->success('编辑成功');
  111. }
  112. /**
  113. * 详情
  114. * @param $merId
  115. * @param $id
  116. * @return \think\response\Json
  117. * @author Qinii
  118. * @day 8/24/21
  119. */
  120. public function detail($merId, $id)
  121. {
  122. if (!$this->repository->merExists($merId, $id))
  123. return app('json')->fail('数据不存在');
  124. return app('json')->success($this->repository->getAdminOneProduct($id, 0, 1));
  125. }
  126. /**
  127. * 修改状态
  128. * @param $merId
  129. * @param $id
  130. * @return \think\response\Json
  131. * @author Qinii
  132. * @day 8/24/21
  133. */
  134. public function switchStatus($merId, $id)
  135. {
  136. $status = $this->request->param('status', 0) == 1 ? 1 : 0;
  137. if (!$this->repository->merExists($merId, $id))
  138. return app('json')->fail('数据不存在');
  139. $this->repository->switchShow($id,$status, 'is_show',$merId);
  140. return app('json')->success('修改成功');
  141. }
  142. /**
  143. * 加入回收站
  144. * @param $merId
  145. * @param $id
  146. * @return \think\response\Json
  147. * @author Qinii
  148. * @day 8/24/21
  149. */
  150. public function delete($merId, $id)
  151. {
  152. if (!$this->repository->merExists($merId, $id))
  153. return app('json')->fail('数据不存在');
  154. if ($this->repository->getWhereCount(['product_id' => $id, 'is_show' => 1, 'status' => 1]))
  155. return app('json')->fail('商品上架中');
  156. $this->repository->delete($id);
  157. return app('json')->success('转入回收站');
  158. }
  159. /**
  160. * 商品配置
  161. * @param $merId
  162. * @return \think\response\Json
  163. * @author Qinii
  164. * @day 8/24/21
  165. */
  166. public function config($merId)
  167. {
  168. $data['extension_status'] = systemConfig('extension_status');
  169. $data['integral_status'] = 0;
  170. $data['integral_rate'] = 0;
  171. if(systemConfig('integral_status') && merchantConfig($merId,'mer_integral_status')) {
  172. $data['integral_status'] = 1;
  173. $data['integral_rate'] = merchantConfig($merId,'mer_integral_rate');
  174. }
  175. $merchant = app()->make(MerchantRepository::class)->get($merId);
  176. $data['delivery_way'] = $merchant->delivery_way;
  177. return app('json')->success($data);
  178. }
  179. /**
  180. * 商品加入回收站
  181. * @param $merId
  182. * @return \think\response\Json
  183. * @author Qinii
  184. * @day 8/24/21
  185. */
  186. public function restore($id)
  187. {
  188. if (!$this->repository->merDeleteExists($this->merId, $id))
  189. return app('json')->fail('只能删除回收站的商品');
  190. $this->repository->restore($id);
  191. return app('json')->success('商品已恢复');
  192. }
  193. /**
  194. * 商品彻底删除
  195. * @param $merId
  196. * @return \think\response\Json
  197. * @author Qinii
  198. * @day 8/24/21
  199. */
  200. public function destory($id)
  201. {
  202. if (!$this->repository->merDeleteExists($this->merId, $id))
  203. return app('json')->fail('只能删除回收站的商品');
  204. // if (app()->make(StoreCartRepository::class)->getProductById($id))
  205. // return app('json')->fail('商品有被加入购物车不可删除');
  206. $this->repository->destory($id);
  207. return app('json')->success('删除成功');
  208. }
  209. /**
  210. * 商品推荐
  211. * @param $merId
  212. * @return \think\response\Json
  213. * @author Qinii
  214. * @day 8/24/21
  215. */
  216. public function updateGood($id)
  217. {
  218. $is_good = $this->request->param('is_good', 0) == 1 ? 1 : 0;
  219. if (!$this->repository->merExists($this->merId, $id))
  220. return app('json')->fail('数据不存在');
  221. $this->repository->update($id, ['is_good' => $is_good]);
  222. return app('json')->success('修改成功');
  223. }
  224. }