StoreProduct.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393
  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\SpuRepository;
  13. use app\common\repositories\system\merchant\MerchantRepository;
  14. use app\common\repositories\system\operate\OperateLogRepository;
  15. use think\App;
  16. use crmeb\basic\BaseController;
  17. use app\validate\merchant\StoreProductAdminValidate as validate;
  18. use app\common\repositories\store\product\ProductRepository as repository;
  19. use think\facade\Queue;
  20. /**
  21. * 主商品
  22. */
  23. class StoreProduct extends BaseController
  24. {
  25. /**
  26. * @var repository
  27. */
  28. protected $repository;
  29. /**
  30. * StoreProduct constructor.
  31. * @param App $app
  32. * @param repository $repository
  33. */
  34. public function __construct(App $app, repository $repository)
  35. {
  36. parent::__construct($app);
  37. $this->repository = $repository;
  38. }
  39. /**
  40. * 列表
  41. * @Author:Qinii
  42. * @Date: 2020/5/18
  43. * @return mixed
  44. */
  45. public function lst()
  46. {
  47. [$page, $limit] = $this->getPage();
  48. $type = $this->request->param('type', 1);
  49. $where = $this->request->params(['cate_id', 'keyword', 'mer_cate_id', 'pid', 'store_name', 'is_trader', 'us_status', 'product_id', 'star', 'sys_labels', 'hot_type', 'svip_price_type', 'is_ficti', 'product_ids', 'form_id','cate_hot']);
  50. $mer_id = $this->request->param('mer_id', '');
  51. $merId = $mer_id ?: null;
  52. $where['is_gift_bag'] = 0;
  53. if ($where['is_ficti']==1){
  54. $where['is_ficti'] = 0;
  55. $where['is_gift'] = 1;
  56. }elseif ($where['is_ficti']==2){
  57. $where['is_ficti'] = 0;
  58. $where['is_oil'] = 1;
  59. }
  60. $_where = $this->repository->switchType($type, null, 0);
  61. unset($_where['star']);
  62. $where = array_merge($where, $_where);
  63. return app('json')->success($this->repository->getAdminList($merId, $where, $page, $limit));
  64. }
  65. /**
  66. * 礼包列表
  67. * @Author:Qinii
  68. * @Date: 2020/5/18
  69. * @return mixed
  70. */
  71. public function bagList()
  72. {
  73. [$page, $limit] = $this->getPage();
  74. $where = $this->request->params(['cate_id', 'keyword', 'mer_cate_id', 'is_trader', 'us_status']);
  75. $merId = $this->request->param('mer_id') ? $this->request->param('mer_id') : null;
  76. $type = $this->request->param('type', 1);
  77. $_where = $this->repository->switchType($type, null, 10);
  78. $where = array_merge($where, $_where);
  79. $where['order'] = 'rank';
  80. unset($where['star']);
  81. return app('json')->success($this->repository->getAdminList($merId, $where, $page, $limit));
  82. }
  83. /**
  84. * 顶部统计 和 状态区分
  85. * @Author:Qinii
  86. * @Date: 2020/5/18
  87. * @return mixed
  88. */
  89. public function getStatusFilter()
  90. {
  91. return app('json')->success($this->repository->getFilter(null, '商品', 0));
  92. }
  93. /**
  94. * 礼包表头
  95. * @Author:Qinii
  96. * @Date: 2020/5/18
  97. * @return mixed
  98. */
  99. public function getBagStatusFilter()
  100. {
  101. return app('json')->success($this->repository->getFilter(null, '礼包', 10));
  102. }
  103. /**
  104. * 详情
  105. * @Author:Qinii
  106. * @Date: 2020/5/18
  107. * @param $id
  108. * @return mixed
  109. */
  110. public function detail($id)
  111. {
  112. if (!$this->repository->merExists(null, $id))
  113. return app('json')->fail('数据不存在');
  114. return app('json')->success($this->repository->getAdminOneProduct($id, 0));
  115. }
  116. /**
  117. * 编辑
  118. * @Author:Qinii
  119. * @Date: 2020/5/11
  120. * @param $id
  121. * @param validate $validate
  122. * @return mixed
  123. */
  124. public function update($id, validate $validate)
  125. {
  126. $data = $this->checkParams($validate);
  127. $this->repository->adminUpdate($id, $data);
  128. return app('json')->success('编辑成功');
  129. }
  130. /**
  131. * 审核 / 下架
  132. * @Author:Qinii
  133. * @Date: 2020/5/18
  134. * @param int $id
  135. * @return mixed
  136. */
  137. public function switchStatus()
  138. {
  139. //0:审核中,1:审核通过 -1: 未通过 -2: 下架
  140. $id = $this->request->param('id');
  141. $data = $this->request->params(['status', 'refusal']);
  142. if (in_array($data['status'], [1, 0, -2, -1]))
  143. if ($data['status'] == -1 && empty($data['refusal']))
  144. return app('json')->fail('请填写拒绝理由');
  145. if (is_array($id)) {
  146. $this->repository->batchSwitchStatus($id, $data, $this->request->adminInfo());
  147. } else {
  148. $this->repository->switchStatus($id, $data, $this->request->adminInfo());
  149. }
  150. return app('json')->success('操作成功');
  151. }
  152. /**
  153. * 字段验证
  154. * @Author:Qinii
  155. * @Date: 2020/5/11
  156. * @param validate $validate
  157. * @return array
  158. */
  159. public function checkParams(validate $validate)
  160. {
  161. $data = $this->request->params(['cate_hot','is_hot', 'is_best', 'is_benefit', 'is_new', 'store_name', 'content',
  162. 'rank', ['star',0],'cate_hot']);
  163. $validate->check($data);
  164. return $data;
  165. }
  166. /**
  167. * 检测商品佣金队列 - 弃用
  168. * @author Qinii
  169. * @day 2020-06-24
  170. */
  171. public function checkProduct()
  172. {
  173. Queue::push(CheckProductExtensionJob::class, []);
  174. return app('json')->success('后台已开始检测');
  175. }
  176. /**
  177. * 商户下啦筛选 - 弃用
  178. * @return \think\response\Json
  179. * @author Qinii
  180. */
  181. public function lists()
  182. {
  183. $make = app()->make(MerchantRepository::class);
  184. $data = $make->selectWhere(['is_del' => 0], 'mer_id,mer_name');
  185. return app('json')->success($data);
  186. }
  187. /**
  188. * 增加虚拟销量表单
  189. * @Author:Qinii
  190. * @Date: 2020/10/9
  191. * @param $id
  192. * @return mixed
  193. */
  194. public function addFictiForm($id)
  195. {
  196. if (!$this->repository->merExists(null, $id))
  197. return app('json')->fail('数据不存在');
  198. return app('json')->success(formToData($this->repository->fictiForm($id)));
  199. }
  200. /**
  201. * 修改虚拟销量
  202. * @Author:Qinii
  203. * @Date: 2020/10/9
  204. * @param $id
  205. * @return mixed
  206. *
  207. */
  208. public function addFicti($id)
  209. {
  210. $data = $this->request->params(['type', 'ficti']);
  211. if (!in_array($data['type'], [1, 2])) return app('json')->fail('类型错误');
  212. if (!$data['ficti'] || $data['ficti'] < 0) return app('json')->fail('已售数量必须大于0');
  213. $res = $this->repository->getWhere(['product_id' => $id], 'ficti,sales');
  214. if (!$res) return app('json')->fail('数据不存在');
  215. if ($data['type'] == 2 && $res['ficti'] < $data['ficti']) return app('json')->fail('已售数量不足');
  216. $ficti = ($data['type'] == 1) ? $data['ficti'] : '-' . $data['ficti'];
  217. $data = [
  218. 'ficti' => $res['ficti'] + $ficti,
  219. 'sales' => $res['sales'] + $ficti
  220. ];
  221. $this->repository->update($id, $data);
  222. return app('json')->success('修改成功');
  223. }
  224. /**
  225. * 修改排序
  226. * @param $id
  227. * @return \think\response\Json
  228. * @author Qinii
  229. * @day 3/17/21
  230. */
  231. public function updateSort($id)
  232. {
  233. $sort = $this->request->param('sort');
  234. $this->repository->updateSort($id, null, ['rank' => $sort]);
  235. return app('json')->success('修改成功');
  236. }
  237. /**
  238. * 设置标签
  239. * @param $id
  240. * @return \think\response\Json
  241. * @author Qinii
  242. */
  243. public function setLabels($id)
  244. {
  245. $data = $this->request->params(['sys_labels']);
  246. app()->make(SpuRepository::class)->setLabels($id, 0, $data, 0);
  247. return app('json')->success('修改成功');
  248. }
  249. /**
  250. * 是否隐藏
  251. * @param $id
  252. * @return mixed
  253. * @author Qinii
  254. * @day 2020-07-17
  255. */
  256. public function changeUsed($id)
  257. {
  258. if (!$this->repository->merExists(null, $id))
  259. return app('json')->fail('数据不存在');
  260. $status = $this->request->param('status', 0) == 1 ? 1 : 0;
  261. $this->repository->switchShow($id, $status, 'is_used', 0, $this->request->adminInfo());
  262. return app('json')->success('修改成功');
  263. }
  264. /**
  265. * 批量显示隐藏
  266. * @return \think\response\Json
  267. * @author Qinii
  268. * @day 2022/11/14
  269. */
  270. public function batchShow()
  271. {
  272. $ids = $this->request->param('ids');
  273. $status = $this->request->param('status') == 1 ? 1 : 0;
  274. $this->repository->batchSwitchShow($ids, $status, 'is_used', 0, $this->request->adminInfo());
  275. return app('json')->success('修改成功');
  276. }
  277. /**
  278. * 批量标签
  279. * @return \think\response\Json
  280. * @author Qinii
  281. * @day 2022/9/6
  282. */
  283. public function batchLabels()
  284. {
  285. $ids = $this->request->param('ids');
  286. $data = $this->request->params(['sys_labels']);
  287. if (empty($ids)) return app('json')->fail('请选择商品');
  288. app()->make(SpuRepository::class)->batchLabels($ids, $data, 0);
  289. return app('json')->success('修改成功');
  290. }
  291. /**
  292. * 批量设置推荐类型
  293. * @return \think\response\Json
  294. * @author Qinii
  295. * @day 2022/9/6
  296. */
  297. //public function batchHot()
  298. //{
  299. // $ids = $this->request->param('ids');
  300. // $data = $this->request->params([['is_hot', 0], ['is_benefit', 0], ['is_best', 0], ['is_new', 0]]);
  301. // if (empty($ids)) return app('json')->fail('请选择商品');
  302. // $this->repository->updates($ids, $data);
  303. // return app('json')->success('修改成功');
  304. //}
  305. /**
  306. * 获取商品操作记录
  307. * @param $product_id
  308. *
  309. * @date 2023/10/13
  310. * @author yyw
  311. */
  312. public function getOperateList($product_id)
  313. {
  314. $where = $this->request->params([
  315. ['type', ''],
  316. ['date', '']
  317. ]);
  318. $where['relevance_id'] = $product_id;
  319. $where['relevance_type'] = OperateLogRepository::RELEVANCE_PRODUCT;
  320. [$page, $limit] = $this->getPage();
  321. return app('json')->success(app()->make(OperateLogRepository::class)->lst($where, $page, $limit));
  322. }
  323. /**
  324. * 获取平台自营产品
  325. * @return void
  326. * FerryZhao 2024/4/12
  327. */
  328. public function get_self_product_list()
  329. {
  330. $productWhere = $this->request->params(['keyword', 'sys_labels', 'us_status', 'cate_id', 'active_id']);
  331. $productWhere['cate_pid'] = $this->request->param('level_one_cate_ids');
  332. $productWhere['product_type'] = 0;
  333. $productWhere['is_ficti'] = '0,1';
  334. $merWhere = $this->request->params(['type_id', 'category_id', 'mer_id']);
  335. $merWhere['status'] = 1;
  336. $merWhere['mer_state'] = 1;
  337. $merWhere['is_del'] = 0;
  338. $merWhere['is_trader'] = 1;//自营
  339. [$page, $limit] = $this->getPage();
  340. $result = $this->repository->getProductList($merWhere, $productWhere, $page, $limit,true);
  341. return app('json')->success('获取成功', $result);
  342. }
  343. /**
  344. * 批量设置 分类推荐
  345. * @return \think\response\Json
  346. * @author Qinii
  347. * @day 2024/6/5
  348. */
  349. public function batchHot()
  350. {
  351. $ids = $this->request->param('ids',[]);
  352. if (empty($ids)) return app('json')->fail('请选择商品');
  353. $ids = !is_array($ids) ? [$ids] : $ids;
  354. $data = $this->request->params([['cate_hot',''],['is_hot',''], ['is_best',''], ['is_benefit',''], ['is_new','']]);
  355. $res = [];
  356. foreach ($data as $k => $v) {
  357. if ($v !== '') {
  358. $res[$k] = $v;
  359. }
  360. }
  361. if (!$res) return app('json')->fail('无信息提交');
  362. $this->repository->updates($ids, $res);
  363. return app('json')->success('修改成功');
  364. }
  365. }