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