Product.php 24 KB

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