StoreProduct.php 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2022 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\SpuRepository;
  13. use app\common\repositories\system\merchant\MerchantRepository;
  14. use think\App;
  15. use crmeb\basic\BaseController;
  16. use app\validate\merchant\StoreProductAdminValidate as validate;
  17. use app\common\repositories\store\product\ProductRepository as repository;
  18. use think\facade\Queue;
  19. class StoreProduct extends BaseController
  20. {
  21. /**
  22. * @var repository
  23. */
  24. protected $repository;
  25. /**
  26. * StoreProduct constructor.
  27. * @param App $app
  28. * @param repository $repository
  29. */
  30. public function __construct(App $app, repository $repository)
  31. {
  32. parent::__construct($app);
  33. $this->repository = $repository;
  34. }
  35. /**
  36. * @Author:Qinii
  37. * @Date: 2020/5/18
  38. * @return mixed
  39. */
  40. public function lst()
  41. {
  42. [$page, $limit] = $this->getPage();
  43. $where = $this->request->params(['cate_id', 'keyword', ['type', 1], 'mer_cate_id', 'pid','store_name','is_trader','us_status','product_id','star','sys_labels','hot_type']);
  44. $mer_id = $this->request->param('mer_id','');
  45. $merId = $mer_id ? $mer_id : null;
  46. $where['is_gift_bag'] = 0;
  47. $_where = $this->repository->switchType($where['type'], null,0);
  48. unset($_where['star']);
  49. $where = array_merge($where, $_where);
  50. return app('json')->success($this->repository->getAdminList($merId, $where, $page, $limit));
  51. }
  52. /**
  53. * @Author:Qinii
  54. * @Date: 2020/5/18
  55. * @return mixed
  56. */
  57. public function bagList()
  58. {
  59. [$page, $limit] = $this->getPage();
  60. $where = $this->request->params(['cate_id','keyword',['type',1],'mer_cate_id' ,'is_trader','us_status']);
  61. $merId = $this->request->param('mer_id') ? $this->request->param('mer_id') : null;
  62. $_where = $this->repository->switchType($where['type'], null,10);
  63. $where = array_merge($where,$_where);
  64. $where['order'] = 'rank';
  65. unset($where['star']);
  66. return app('json')->success($this->repository->getAdminList($merId,$where, $page, $limit));
  67. }
  68. /**
  69. * @Author:Qinii
  70. * @Date: 2020/5/18
  71. * @return mixed
  72. */
  73. public function getStatusFilter()
  74. {
  75. return app('json')->success($this->repository->getFilter(null,'商品',0));
  76. }
  77. /**
  78. * TODO 礼包表头
  79. * @Author:Qinii
  80. * @Date: 2020/5/18
  81. * @return mixed
  82. */
  83. public function getBagStatusFilter()
  84. {
  85. return app('json')->success($this->repository->getFilter(null,'礼包',10));
  86. }
  87. /**
  88. * @Author:Qinii
  89. * @Date: 2020/5/18
  90. * @param $id
  91. * @return mixed
  92. */
  93. public function detail($id)
  94. {
  95. if(!$this->repository->merExists(null,$id))
  96. return app('json')->fail('数据不存在');
  97. return app('json')->success($this->repository->getAdminOneProduct($id,0));
  98. }
  99. /**
  100. * @Author:Qinii
  101. * @Date: 2020/5/11
  102. * @param $id
  103. * @param validate $validate
  104. * @return mixed
  105. */
  106. public function update($id,validate $validate)
  107. {
  108. $data = $this->checkParams($validate);
  109. $this->repository->adminUpdate($id,$data);
  110. return app('json')->success('编辑成功');
  111. }
  112. /**
  113. * TODO 审核 / 下架
  114. * @Author:Qinii
  115. * @Date: 2020/5/18
  116. * @param int $id
  117. * @return mixed
  118. */
  119. public function switchStatus()
  120. {
  121. //0:审核中,1:审核通过 -1: 未通过 -2: 下架
  122. $id = $this->request->param('id');
  123. $data = $this->request->params(['status','refusal']);
  124. if (in_array($data['status'],[1,0,-2,-1]))
  125. if($data['status'] == -1 && empty($data['refusal']))
  126. return app('json')->fail('请填写拒绝理由');
  127. if(is_array($id)) {
  128. $this->repository->batchSwitchStatus($id,$data);
  129. } else {
  130. $this->repository->switchStatus($id,$data);
  131. }
  132. return app('json')->success('操作成功');
  133. }
  134. /**
  135. * @Author:Qinii
  136. * @Date: 2020/5/11
  137. * @param validate $validate
  138. * @return array
  139. */
  140. public function checkParams(validate $validate)
  141. {
  142. $data = $this->request->params(['is_hot','is_best','is_benefit','is_new','store_name','content','rank','star']);
  143. $validate->check($data);
  144. return $data;
  145. }
  146. /**
  147. * TODO
  148. * @author Qinii
  149. * @day 2020-06-24
  150. */
  151. public function checkProduct()
  152. {
  153. Queue::push(CheckProductExtensionJob::class,[]);
  154. return app('json')->success('后台已开始检测');
  155. }
  156. public function lists()
  157. {
  158. $make = app()->make(MerchantRepository::class);
  159. $data = $make->selectWhere(['is_del' => 0],'mer_id,mer_name');
  160. return app('json')->success($data);
  161. }
  162. /**
  163. * 增加虚拟销量表单
  164. * @Author:Qinii
  165. * @Date: 2020/10/9
  166. * @param $id
  167. * @return mixed
  168. */
  169. public function addFictiForm($id)
  170. {
  171. if(!$this->repository->merExists(null,$id))
  172. return app('json')->fail('数据不存在');
  173. return app('json')->success(formToData($this->repository->fictiForm($id)));
  174. }
  175. /**
  176. * 修改虚拟销量
  177. * @Author:Qinii
  178. * @Date: 2020/10/9
  179. * @param $id
  180. * @return mixed
  181. *
  182. */
  183. public function addFicti($id)
  184. {
  185. $data = $this->request->params(['type','ficti']);
  186. if(!in_array($data['type'],[1,2])) return app('json')->fail('类型错误');
  187. if(!$data['ficti'] || $data['ficti'] < 0) return app('json')->fail('虚拟销量必须大于0');
  188. $res = $this->repository->getWhere(['product_id' => $id],'ficti,sales');
  189. if(!$res) return app('json')->fail('数据不存在');
  190. if($data['type'] == 2 && $res['ficti'] < $data['ficti']) return app('json')->fail('虚拟销量不足');
  191. $ficti = ($data['type'] == 1) ? $data['ficti'] : '-' . $data['ficti'];
  192. $data = [
  193. 'ficti' => $res['ficti'] + $ficti,
  194. 'sales' => $res['sales'] + $ficti
  195. ];
  196. $this->repository->update($id,$data);
  197. return app('json')->success('修改成功');
  198. }
  199. /**
  200. * TODO
  201. * @param $id
  202. * @return \think\response\Json
  203. * @author Qinii
  204. * @day 3/17/21
  205. */
  206. public function updateSort($id)
  207. {
  208. $sort = $this->request->param('sort');
  209. $this->repository->updateSort($id,null,['rank' => $sort]);
  210. return app('json')->success('修改成功');
  211. }
  212. public function setLabels($id)
  213. {
  214. $data = $this->request->params(['sys_labels']);
  215. app()->make(SpuRepository::class)->setLabels($id,0,$data,0);
  216. return app('json')->success('修改成功');
  217. }
  218. /**
  219. * TODO 是否隐藏
  220. * @param $id
  221. * @return mixed
  222. * @author Qinii
  223. * @day 2020-07-17
  224. */
  225. public function changeUsed($id)
  226. {
  227. if(!$this->repository->merExists(null,$id))
  228. return app('json')->fail('数据不存在');
  229. $status = $this->request->param('status',0) == 1 ? 1 : 0;
  230. $this->repository->switchShow($id,$status,'is_used',0);
  231. return app('json')->success('修改成功');
  232. }
  233. /**
  234. * TODO 批量显示隐藏
  235. * @return \think\response\Json
  236. * @author Qinii
  237. * @day 2022/11/14
  238. */
  239. public function batchShow()
  240. {
  241. $ids = $this->request->param('ids');
  242. $status = $this->request->param('status') == 1 ? 1 : 0;
  243. $this->repository->batchSwitchShow($ids,$status,'is_used',0);
  244. return app('json')->success('修改成功');
  245. }
  246. /**
  247. * TODO 批量标签
  248. * @return \think\response\Json
  249. * @author Qinii
  250. * @day 2022/9/6
  251. */
  252. public function batchLabels()
  253. {
  254. $ids = $this->request->param('ids');
  255. $data = $this->request->params(['sys_labels']);
  256. if (empty($ids)) return app('json')->fail('请选择商品');
  257. app()->make(SpuRepository::class)->batchLabels($ids, $data,0);
  258. return app('json')->success('修改成功');
  259. }
  260. /**
  261. * TODO 批量设置推荐类型
  262. * @return \think\response\Json
  263. * @author Qinii
  264. * @day 2022/9/6
  265. */
  266. public function batchHot()
  267. {
  268. $ids = $this->request->param('ids');
  269. $data = $this->request->params([['is_hot',0],['is_benefit',0],['is_best',0],['is_new',0]]);
  270. if (empty($ids)) return app('json')->fail('请选择商品');
  271. $this->repository->updates($ids,$data);
  272. return app('json')->success('修改成功');
  273. }
  274. }