Product.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671
  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\merchant\store\product;
  12. use app\common\repositories\store\product\CdkeyLibraryRepository;
  13. use app\common\repositories\store\product\ProductAttrValueRepository;
  14. use app\common\repositories\store\product\ProductBatchProcessRepository;
  15. use app\common\repositories\store\product\SpuRepository;
  16. use app\common\repositories\store\shipping\ShippingTemplateRepository;
  17. use app\common\repositories\store\StoreCategoryRepository;
  18. use app\common\repositories\system\operate\OperateLogRepository;
  19. use crmeb\services\UploadService;
  20. use think\App;
  21. use crmeb\basic\BaseController;
  22. use app\common\repositories\store\product\ProductRepository as repository;
  23. use think\exception\ValidateException;
  24. use think\facade\Cache;
  25. class Product extends BaseController
  26. {
  27. protected $repository;
  28. /**
  29. * Product constructor.
  30. * @param App $app
  31. * @param repository $repository
  32. */
  33. public function __construct(App $app, repository $repository)
  34. {
  35. parent::__construct($app);
  36. $this->repository = $repository;
  37. }
  38. /**
  39. * 获取列表数据
  40. *
  41. * @return \think\response\Json
  42. */
  43. public function lst()
  44. {
  45. // 获取分页参数
  46. [$page, $limit] = $this->getPage();
  47. // 获取查询参数
  48. $type = $this->request->param('type', 1);
  49. $where = $this->request->params([
  50. 'temp_id',
  51. 'cate_id',
  52. 'keyword',
  53. 'mer_cate_id',
  54. 'is_gift_bag',
  55. 'status',
  56. 'us_status',
  57. 'product_id',
  58. 'mer_labels',
  59. ['order', 'sort'],
  60. 'is_ficti',
  61. 'svip_price_type',
  62. 'filters_type',
  63. 'is_action',
  64. 'is_good',
  65. 'not_product_id',
  66. 'form_id',
  67. 'mer_form_id',
  68. 'cate_hot'
  69. ]);
  70. if ($where['is_ficti']==1){
  71. $where['is_ficti'] = 0;
  72. $where['is_gift'] = 1;
  73. }elseif ($where['is_ficti']==2){
  74. $where['is_ficti'] = 0;
  75. $where['is_oil'] = 1;
  76. }
  77. // 根据类型和商家ID获取查询条件
  78. $where = array_merge($where, $this->repository->switchType($type, $this->request->merId(), 0));
  79. // 调用仓库方法获取列表数据并返回JSON格式的响应
  80. return app('json')->success($this->repository->getList($this->request->merId(), $where, $page, $limit));
  81. }
  82. /**
  83. * 获取商品详情
  84. * @param int $id 商品ID
  85. * @return \think\response\Json
  86. */
  87. public function detail($id)
  88. {
  89. // 判断商品是否存在
  90. if (!$this->repository->merExists($this->request->merId(), $id))
  91. return app('json')->fail('数据不存在');
  92. // 返回商品详情
  93. $is_copy = $this->request->param('is_copy',0);
  94. return app('json')->success($this->repository->getAdminOneProduct($id, null,0,$is_copy));
  95. }
  96. public function getEdit($id)
  97. {
  98. // 判断商品是否存在
  99. if (!$this->repository->merExists($this->request->merId(), $id))
  100. return app('json')->fail('数据不存在');
  101. // 返回商品详情
  102. $is_copy = $this->request->param('is_copy',0);
  103. $data = $this->repository->getEdit($id, $is_copy);
  104. return app('json')->success($data);
  105. }
  106. /**
  107. * 创建商品
  108. * @return \think\response\Json
  109. */
  110. public function create()
  111. {
  112. // 获取参数
  113. $params = $this->request->params($this->repository::CREATE_PARAMS);
  114. // 校验参数
  115. $data = $this->repository->checkParams($params, $this->request->merId());
  116. // 设置商家ID和管理员ID
  117. $data['mer_id'] = $this->request->merId();
  118. $data['admin_id'] = $this->request->merAdminId();
  119. // 判断是否为礼包商品并且商家礼包数量是否超过限制
  120. if ($data['is_gift_bag'] && !$this->repository->checkMerchantBagNumber($data['mer_id']))
  121. return app('json')->fail('礼包数量超过数量限制');
  122. // 设置商品状态
  123. $data['status'] = $this->request->merchant()->is_audit ? 0 : 1;
  124. // 设置商家状态
  125. $data['mer_status'] = ($this->request->merchant()->is_del || !$this->request->merchant()->mer_state || !$this->request->merchant()->status) ? 0 : 1;
  126. // 设置评分
  127. $data['rate'] = 5;
  128. // 设置管理员信息
  129. $data['admin_info'] = $this->request->adminInfo();
  130. if ($data['is_oil']==1||$data['is_gift']==1){
  131. if ($data['mer_id']!=1){
  132. return app('json')->fail('非平台商户不能创建此类型商品');
  133. }
  134. }
  135. // 创建商品
  136. $this->repository->create($data, 0);
  137. // 返回创建成功信息
  138. return app('json')->success('添加成功');
  139. }
  140. /**
  141. * 修改商品
  142. * @param int $id 商品ID
  143. * @return \think\response\Json
  144. */
  145. public function update($id)
  146. {
  147. // 获取参数
  148. $params = $this->request->params($this->repository::CREATE_PARAMS);
  149. $data = $this->repository->checkParams($params, $this->request->merId(), $id);
  150. // 判断商品是否存在
  151. if (!$this->repository->merExists($this->request->merId(), $id))
  152. return app('json')->fail('数据不存在');
  153. // 获取商品信息
  154. $pro = $this->repository->getWhere(['product_id' => $id]);
  155. if ($pro->status == -2) {
  156. $data['status'] = 0;
  157. } else {
  158. // 设置商品状态
  159. $data['status'] = $this->request->merchant()->is_audit ? 0 : 1;
  160. }
  161. // 设置商家状态
  162. $data['mer_status'] = ($this->request->merchant()->is_del || !$this->request->merchant()->mer_state || !$this->request->merchant()->status) ? 0 : 1;
  163. // 设置商家ID和管理员ID
  164. $data['mer_id'] = $this->request->merId();
  165. // 设置管理员信息
  166. $data['admin_info'] = $this->request->adminInfo();
  167. $productData = $this->repository->edit($id, $data, $this->request->merId(), 0);
  168. $product = $productData->toArray();
  169. ksort($product);
  170. $cache_unique = 'get_product_show_' . $id . '_' . md5(json_encode($product));
  171. Cache::delete($cache_unique);
  172. return app('json')->success('编辑成功');
  173. }
  174. /**
  175. * 删除商品
  176. *
  177. * @param int $id 商品ID
  178. * @return \think\response\Json
  179. */
  180. public function delete($id)
  181. {
  182. // 判断商品是否存在
  183. if (!$this->repository->merExists($this->request->merId(), $id))
  184. return app('json')->fail('数据不存在');
  185. // 判断商品是否已经上架
  186. if ($this->repository->getWhereCount(['product_id' => $id, 'is_show' => 1, 'status' => 1]))
  187. return app('json')->fail('商品上架中');
  188. // 删除商品
  189. $this->repository->delete($id);
  190. //queue(ChangeSpuStatusJob::class,['product_type' => 0,'id' => $id]);
  191. app()->make(CdkeyLibraryRepository::class)->cancel($id);
  192. // 返回操作结果
  193. return app('json')->success('转入回收站');
  194. }
  195. /**
  196. * 永久删除商品
  197. *
  198. * @param int $id 商品ID
  199. * @return \think\response\Json
  200. */
  201. public function destory($id)
  202. {
  203. // 判断商品是否存在于回收站
  204. if (!$this->repository->merDeleteExists($this->request->merId(), $id))
  205. return app('json')->fail('只能删除回收站的商品');
  206. // if(app()->make(StoreCartRepository::class)->getProductById($id))
  207. // return app('json')->fail('商品有被加入购物车不可删除');
  208. $seckillProduct = $this->repository->getWhere(['old_product_id' => $id, 'is_del' => 0, 'product_type' => 1], 'product_id, store_name, is_show');
  209. if($seckillProduct) {
  210. return app('json')->fail('该商品有秒杀商品不可删除,请先删除关联秒杀商品再操作!秒杀商品ID:'. $seckillProduct->product_id);
  211. }
  212. // 永久删除商品
  213. $this->repository->destory($id);
  214. return app('json')->success('删除成功');
  215. }
  216. /**
  217. * 获取状态过滤器
  218. *
  219. * @return \Illuminate\Http\JsonResponse
  220. */
  221. public function getStatusFilter()
  222. {
  223. // 调用 repository 的 getFilter 方法获取商品状态过滤器
  224. return app('json')->success($this->repository->getFilter($this->request->merId(), '商品', 0));
  225. }
  226. /**
  227. * 配置信息
  228. *
  229. * @return \Illuminate\Http\JsonResponse
  230. */
  231. public function config()
  232. {
  233. $data = systemConfig(['extension_status', 'svip_switch_status', 'integral_status', 'extension_one_rate', 'extension_two_rate']);
  234. $merData = merchantConfig($this->request->merId(), ['mer_integral_status', 'mer_integral_rate', 'mer_svip_status', 'svip_store_rate']);
  235. // 计算商家 svip 店铺比例
  236. $svip_store_rate = $merData['svip_store_rate'] > 0 ? bcdiv($merData['svip_store_rate'], 100, 2) : 0;
  237. // 判断商家 svip 状态
  238. $data['mer_svip_status'] = ($data['svip_switch_status'] && $merData['mer_svip_status'] != 0) ? 1 : 0;
  239. // 设置商家 svip 店铺比例
  240. $data['svip_store_rate'] = $svip_store_rate;
  241. // 判断积分状态
  242. $data['integral_status'] = $data['integral_status'] && $merData['mer_integral_status'] ? 1 : 0;
  243. // 设置积分比例
  244. $data['integral_rate'] = $merData['mer_integral_rate'] ?: 0;
  245. // 获取商家配送方式
  246. $data['delivery_way'] = $this->request->merchant()->delivery_way ? $this->request->merchant()->delivery_way : [2];
  247. // 获取商家审核状态
  248. $data['is_audit'] = $this->request->merchant()->is_audit;
  249. // 设置分销一比例
  250. $data['extension_one_rate'] = $data['extension_one_rate'] ? $data['extension_one_rate'] * 100 : 0;
  251. // 设置分销二比例
  252. $data['extension_two_rate'] = $data['extension_two_rate'] ? $data['extension_two_rate'] * 100 : 0;
  253. // 返回配置信息
  254. return app('json')->success($data);
  255. }
  256. /**
  257. * 从回收站中恢复指定ID的商品
  258. *
  259. * @param int $id 商品ID
  260. * @return \Illuminate\Http\JsonResponse 返回JSON格式的操作结果
  261. */
  262. public function restore($id)
  263. {
  264. // 判断商品是否存在于回收站中
  265. if (!$this->repository->merDeleteExists($this->request->merId(), $id))
  266. return app('json')->fail('只能恢复回收站的商品');
  267. // 恢复商品
  268. $this->repository->restore($id);
  269. // 返回操作结果
  270. return app('json')->success('商品已恢复');
  271. }
  272. /**
  273. * 获取上传临时密钥
  274. *
  275. * @return \Illuminate\Http\JsonResponse 返回JSON格式的上传临时密钥
  276. */
  277. public function temp_key()
  278. {
  279. // 创建上传服务实例
  280. $upload = UploadService::create();
  281. // 获取上传临时密钥
  282. $re = $upload->getTempKeys();
  283. // 返回上传临时密钥
  284. return app('json')->success($re);
  285. }
  286. /**
  287. * 更新商品排序
  288. *
  289. * @param int $id 商品ID
  290. * @return \think\response\Json 返回JSON格式的操作结果
  291. */
  292. public function updateSort($id)
  293. {
  294. // 获取请求参数中的排序值
  295. $sort = $this->request->param('sort');
  296. // 调用商品仓库的更新排序方法
  297. $this->repository->updateSort($id, $this->request->merId(), ['sort' => $sort]);
  298. // 返回操作成功的JSON格式数据
  299. return app('json')->success('修改成功');
  300. }
  301. /**
  302. * 预览商品信息
  303. *
  304. * @return \think\response\Json 返回JSON格式的操作结果
  305. */
  306. public function preview()
  307. {
  308. // 获取请求参数中的商品信息
  309. $data = $this->request->param();
  310. // 设置商家信息
  311. $data['merchant'] = [
  312. 'mer_name' => $this->request->merchant()->mer_name,
  313. 'is_trader' => $this->request->merchant()->is_trader,
  314. 'mer_avatar' => $this->request->merchant()->mer_avatar,
  315. 'product_score' => $this->request->merchant()->product_score,
  316. 'service_score' => $this->request->merchant()->service_score,
  317. 'postage_score' => $this->request->merchant()->postage_score,
  318. 'service_phone' => $this->request->merchant()->service_phone,
  319. 'care_count' => $this->request->merchant()->care_count,
  320. 'type_name' => $this->request->merchant()->type_name->type_name ?? '',
  321. 'care' => true,
  322. 'recommend' => $this->request->merchant()->recommend,
  323. ];
  324. // 设置商家ID和状态
  325. $data['mer_id'] = $this->request->merId();
  326. $data['status'] = 1;
  327. $data['mer_status'] = 1;
  328. $data['rate'] = 3;
  329. // 调用商品仓库的预览方法并返回操作结果
  330. return app('json')->success($this->repository->preview($data));
  331. }
  332. /**
  333. * 设置SPU标签
  334. * @param int $id SPU ID
  335. * @return \think\response\Json 返回JSON格式的操作结果
  336. */
  337. public function setLabels($id)
  338. {
  339. // 获取请求参数中的标签数据
  340. $data = $this->request->params(['mer_labels']);
  341. // 调用SpuRepository类的setLabels方法设置SPU标签
  342. app()->make(SpuRepository::class)->setLabels($id, 0, $data, $this->request->merId());
  343. // 返回操作成功的JSON格式数据
  344. return app('json')->success('修改成功');
  345. }
  346. /**
  347. * 获取属性值
  348. * @param int $id 属性ID
  349. * @return \think\response\Json 返回JSON格式的属性值
  350. */
  351. public function getAttrValue($id)
  352. {
  353. // 调用repository对象的getAttrValue方法获取属性值
  354. $data = $this->repository->getAttrValue($id, $this->request->merId());
  355. return app('json')->success($data);
  356. }
  357. /**
  358. * 免审
  359. * @param int $id SPU ID
  360. * @return \think\response\Json 返回JSON格式的操作结果
  361. * @throws \app\common\exception\ValidateException
  362. */
  363. public function freeTrial($id)
  364. {
  365. // 定义需要获取的请求参数
  366. $params = [
  367. "mer_cate_id",
  368. "sort",
  369. "is_show",
  370. "is_good",
  371. "attr",
  372. "attrValue",
  373. 'spec_type'
  374. ];
  375. // 获取请求参数中的数据
  376. $data = $this->request->params($params);
  377. // 判断商户分类是否存在
  378. if (!empty($data['mer_cate_id'])) {
  379. $count = app()->make(StoreCategoryRepository::class)->getWhereCount(['store_category_id' => $data['mer_cate_id'], 'is_show' => 1, 'mer_id' => $this->request->merId()]);
  380. if (!$count) throw new ValidateException('商户分类不存在或不可用');
  381. }
  382. // 设置状态为1
  383. $data['status'] = 1;
  384. // 调用repository对象的freeTrial方法进行免费试用
  385. $this->repository->freeTrial($id, $data, $this->request->merId(), $this->request->adminInfo());
  386. return app('json')->success('编辑成功');
  387. }
  388. /**
  389. * 上下架
  390. * @Author:Qinii
  391. * @Date: 2020/5/18
  392. * @param int $id
  393. * @return mixed
  394. */
  395. public function switchStatus($id)
  396. {
  397. $status = $this->request->param('status', 0) == 1 ? 1 : 0;
  398. $this->repository->switchShow($id, $status, 'is_show', $this->request->merId(), $this->request->adminInfo());
  399. return app('json')->success('修改成功');
  400. }
  401. /**
  402. * 批量上下架
  403. * @return \think\response\Json
  404. * @author Qinii
  405. * @day 2022/9/6
  406. */
  407. public function batchShow()
  408. {
  409. $ids = $this->request->param('ids');
  410. if (empty($ids)) return app('json')->fail('请选择商品');
  411. $status = $this->request->param('status') == 1 ? 1 : 0;
  412. $this->repository->batchSwitchShow($ids, $status, 'is_show', $this->request->merId(), $this->request->adminInfo());
  413. return app('json')->success('修改成功');
  414. }
  415. /**
  416. * 批量设置模板
  417. * @return \think\response\Json
  418. * @author Qinii
  419. * @day 2022/9/6
  420. */
  421. public function batchTemplate()
  422. {
  423. $ids = $this->request->param('ids');
  424. $ids = is_array($ids) ? $ids : explode(',', $ids);
  425. $data = $this->request->params(['temp_id']);
  426. if (empty($ids)) return app('json')->fail('请选择商品');
  427. if (empty($data['temp_id'])) return app('json')->fail('请选择运费模板');
  428. if (!$this->repository->merInExists($this->request->merId(), $ids)) return app('json')->fail('请选择您自己商品');
  429. $make = app()->make(ShippingTemplateRepository::class);
  430. if (!$make->merInExists($this->request->merId(), [$data['temp_id']]))
  431. return app('json')->fail('请选择您自己的运费模板');
  432. $data['delivery_free'] = 0;
  433. $this->repository->updates($ids, $data);
  434. return app('json')->success('修改成功');
  435. }
  436. /**
  437. * 批量标签
  438. * @return \think\response\Json
  439. * @author Qinii
  440. * @day 2022/9/6
  441. */
  442. public function batchLabels()
  443. {
  444. $ids = $this->request->param('ids');
  445. $data = $this->request->params(['mer_labels']);
  446. if (empty($ids)) return app('json')->fail('请选择商品');
  447. if (!$this->repository->merInExists($this->request->merId(), $ids))
  448. return app('json')->fail('请选择您自己商品');
  449. app()->make(SpuRepository::class)->batchLabels($ids, $data, $this->request->merId());
  450. return app('json')->success('修改成功');
  451. }
  452. /**
  453. * 批量设置推荐类型
  454. * @return \think\response\Json
  455. * @author Qinii
  456. * @day 2022/9/6
  457. */
  458. public function batchHot()
  459. {
  460. $ids = $this->request->param('ids');
  461. $data['is_good'] = 1;
  462. if (empty($ids)) return app('json')->fail('请选择商品');
  463. if (!$this->repository->merInExists($this->request->merId(), $ids))
  464. return app('json')->fail('请选择您自己商品');
  465. $this->repository->updates($ids, $data);
  466. return app('json')->success('修改成功');
  467. }
  468. /**
  469. * 批量设置佣金
  470. * @param ProductAttrValueRepository $repository
  471. * @return \think\response\Json
  472. * @author Qinii
  473. * @day 2022/12/26
  474. */
  475. public function batchExtension(ProductAttrValueRepository $repository)
  476. {
  477. $ids = $this->request->param('ids');
  478. $data = $this->request->params(['extension_one', 'extension_two']);
  479. if ($data['extension_one'] > 1 || $data['extension_one'] < 0 || $data['extension_two'] < 0 || $data['extension_two'] > 1) {
  480. return app('json')->fail('比例0~1之间');
  481. }
  482. if (empty($ids)) return app('json')->fail('请选择商品');
  483. if (!$this->repository->merInExists($this->request->merId(), $ids))
  484. return app('json')->fail('请选择您自己商品');
  485. $repository->updatesExtension($ids, $data);
  486. return app('json')->success('修改成功');
  487. }
  488. /**
  489. * 批量设置商品SVIP类型
  490. */
  491. public function batchSvipType()
  492. {
  493. // 获取请求参数中的商品ID
  494. $ids = $this->request->param('ids');
  495. // 获取请求参数中的SVIP价格类型
  496. $data = $this->request->params([['svip_price_type', 0]]);
  497. // 如果商品ID为空,则返回错误信息
  498. if (empty($ids)) return app('json')->fail('请选择商品');
  499. // 如果商品不属于当前商家,则返回错误信息
  500. if (!$this->repository->merInExists($this->request->merId(), $ids))
  501. return app('json')->fail('请选择您自己商品');
  502. // 更新商品SVIP类型
  503. $this->repository->updates($ids, $data);
  504. // 返回操作成功信息
  505. return app('json')->success('修改成功');
  506. }
  507. /**
  508. * 判断商品属性是否符合格式要求
  509. * @param int $id 商品ID
  510. * @return \think\response\Json 返回JSON格式的数据
  511. */
  512. public function isFormatAttr($id)
  513. {
  514. // 获取请求参数中的商品属性、商品项和商品类型
  515. $data = $this->request->params([
  516. ['attrs', []],
  517. ['items', []],
  518. ['product_type', 0],
  519. ]);
  520. $is_copy = $this->request->param('is_copy',0);
  521. // 判断商品属性是否符合格式要求
  522. $data = $this->repository->isFormatAttr($data['attrs'], $id,[],$is_copy);
  523. // 返回操作成功信息和商品属性
  524. return app('json')->success($data);
  525. }
  526. /**
  527. * 获取批量操作类型
  528. * @return \think\response\Json
  529. *
  530. * @date 2023/10/12
  531. * @author yyw
  532. */
  533. public function getBatchList()
  534. {
  535. $productBatch = app()->make(ProductBatchProcessRepository::class);
  536. return app('json')->success($productBatch->getTypeList());
  537. }
  538. /**
  539. * 商品批量操作
  540. * @return \think\response\Json
  541. *
  542. * @date 2023/10/12
  543. * @author yyw
  544. */
  545. public function batchProcess()
  546. {
  547. $ids = $this->request->param('ids', []);
  548. $batch_type = $this->request->param('batch_type');
  549. $batch_select_type = $this->request->param('batch_select_type', 'select');
  550. $admin_info = $this->request->adminInfo();
  551. // 商品列表 搜索条件
  552. $where = $this->request->param('where', []) ?: [];
  553. if (!empty($where)) {
  554. $where = array_merge($where, $this->repository->switchType($where['type'], $this->request->merId(), 0));
  555. }
  556. $productBatch = app()->make(ProductBatchProcessRepository::class);
  557. $type_info = $productBatch->getTypeInfo($batch_type);
  558. $data = $this->request->params($type_info['param']);
  559. $res = $productBatch->setProductIds($this->request->merId(), $batch_type, $batch_select_type, $where, $ids, $data, $admin_info);
  560. if (is_string($res)) {
  561. return app('json')->success($res);
  562. }
  563. return app('json')->success('修改成功');
  564. }
  565. /**
  566. * 获取操作日志列表
  567. *
  568. * @param int $product_id 商品ID
  569. * @return \think\response\Json
  570. */
  571. public function getOperateList($product_id)
  572. {
  573. // 从请求参数中获取类型和日期
  574. $where = $this->request->params([
  575. ['type', ''],
  576. ['date', '']
  577. ]);
  578. // 设置关联ID和关联类型
  579. $where['relevance_id'] = $product_id;
  580. $where['relevance_type'] = OperateLogRepository::RELEVANCE_PRODUCT;
  581. // 获取分页信息
  582. [$page, $limit] = $this->getPage();
  583. // 调用操作日志仓库的lst方法获取操作日志列表并返回JSON格式的成功响应
  584. return app('json')->success(app()->make(OperateLogRepository::class)->lst($where, $page, $limit));
  585. }
  586. /**
  587. * 解绑卡密库
  588. * @return \think\response\Json
  589. * @author Qinii
  590. */
  591. public function unbind()
  592. {
  593. $data = $this->request->params(['value_id','library_id']);
  594. $this->repository->unbindCdkeyLibrary($data['value_id'],$data['library_id']);
  595. return app('json')->success('删除成功');
  596. }
  597. /**
  598. * 可以用于选择为活动商品的 商品选择列表
  599. * @return \think\response\Json
  600. * @author Qinii
  601. */
  602. public function product_list()
  603. {
  604. $where = $this->request->params([
  605. ['keyword',''], //商品搜索
  606. ['mer_labels', ''], //商户标签
  607. ['is_show',''], //上下架
  608. ['mer_cate_id',''], //商户分类
  609. ['in_type','0,1'], //商品类型
  610. ['status', 1], //商品审核状态
  611. ['cate_pid',''], //平台商品分类选择 1,2 级
  612. ['cate_id',''], //平台商品分类 3级
  613. ]);
  614. [$page, $limit] = $this->getPage();
  615. $data = $this->repository->getList($this->request->merId(), $where, $page, $limit);
  616. return app('json')->success($data);
  617. }
  618. }