Product.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523
  1. <?php
  2. namespace App\Http\Controllers\Manager\Collect;
  3. use App\Http\Controllers\Controller;
  4. use App\Http\Requests\Manager\Collect\Product as Request;
  5. use App\Models\Manager\Collect\Product as ProductModel;
  6. use Illuminate\Support\Facades\DB;
  7. use App\Models\Manager\Collect\ProductKeyword as ProductKeywordModel;
  8. /**
  9. * 采集配置-商品管理
  10. * @author 唐远望
  11. * @version 1.0
  12. * @date 2025-12-30
  13. */
  14. class Product extends Controller
  15. {
  16. /**
  17. * 列表
  18. * @author 唐远望
  19. * @version 1.0
  20. * @date 2025-12-30
  21. *
  22. */
  23. public function list(Request $request, ProductModel $ProductModel)
  24. {
  25. $request->scene('list')->validate();
  26. $admin_company_id = request('admin_company_id', '0');
  27. $company_id = request('access_token.company_id', '0');
  28. $is_admin = request('access_token.is_admin', '0');
  29. // 查询条件
  30. $map = [];
  31. $limit = request('limit', config('page_num', 10));
  32. $status = request('status', '');
  33. $start_time = request('start_time', '');
  34. $end_time = request('end_time', '');
  35. $product_name = request('product_name', '');
  36. $platforms = request('platform', '');
  37. $product_brand = request('product_brand', '');
  38. // 时间条件
  39. if ($start_time) $map[] = ['insert_time', '>=', strtotime($start_time)];
  40. if ($end_time) $map[] = ['insert_time', '<=', strtotime($end_time)];
  41. // 其他条件
  42. if (is_numeric($status)) $map[] = ['status', '=', $status];
  43. if ($product_name) $map[] = ['product_name', 'like', "%$product_name%"];
  44. if (is_numeric($platforms) || $platforms) {
  45. $ProductModel = $ProductModel
  46. ->where(function ($query) use ($platforms) {
  47. $platforms = explode(',',$platforms);
  48. foreach ($platforms as $platform) {
  49. $query->orWhereRaw("FIND_IN_SET(?, platform)", [$platform]);
  50. }
  51. });
  52. }
  53. if ($product_brand) $map[] = ['product_brand', 'like', "%$product_brand%"];
  54. // 权限判断
  55. if ($is_admin != 1 && $company_id != 0) {
  56. $map[] = ['company_id', '=', $company_id];
  57. } else {
  58. $map[] = ['company_id', '=', $admin_company_id];
  59. }
  60. // 查询数据
  61. $result = $ProductModel
  62. ->where($map)
  63. ->with(['product_keyword'])
  64. ->orderByDesc('id')
  65. ->paginate($limit)->toarray();
  66. // 分配数据
  67. if (!$result) return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => []]);
  68. if (isset($result['data']) && count($result['data']) > 0) {
  69. foreach ($result['data'] as $key => $value) {
  70. $result['data'][$key]['platform'] = isset($value['platform']) ? explode(',', $value['platform']) : '';
  71. $product_specs = isset($value['product_specs']) ? explode(',', $value['product_specs']) : '';
  72. //移除空数组
  73. $result['data'][$key]['product_specs'] = $product_specs ? array_filter($product_specs) : '';
  74. }
  75. }
  76. // 加载模板
  77. return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => $result]);
  78. }
  79. /**
  80. * 商品名称规格列表
  81. * @author 唐远望
  82. * @version 1.0
  83. * @date 2026-03-25
  84. *
  85. */
  86. public function product_name_specs_list(Request $request, ProductModel $ProductModel, ProductKeywordModel $ProductKeywordModel)
  87. {
  88. $request->scene('product_name_specs_list')->validate();
  89. $admin_company_id = request('admin_company_id', '0');
  90. $company_id = request('access_token.company_id', '0');
  91. $is_admin = request('access_token.is_admin', '0');
  92. // 查询条件
  93. $map = [];
  94. $map2 = [];
  95. $map3 = [];
  96. $start_time = request('start_time', '');
  97. $end_time = request('end_time', '');
  98. $product_name = request('product_name', '');
  99. $product_brand = request('product_brand', '');
  100. // 时间条件
  101. if ($start_time) {
  102. $map[] = ['insert_time', '>=', strtotime($start_time)];
  103. $map2[] = ['insert_time', '>=', strtotime($start_time)];
  104. $map3[] = ['insert_time', '>=', strtotime($start_time)];
  105. }
  106. if ($end_time) {
  107. $map[] = ['insert_time', '<=', strtotime($end_time)];
  108. $map2[] = ['insert_time', '<=', strtotime($end_time)];
  109. $map3[] = ['insert_time', '<=', strtotime($end_time)];
  110. }
  111. // 其他条件
  112. $map[] = ['status', '=', 0];
  113. if ($product_name) $map2[] = ['product_name', 'like', "%$product_name%"];
  114. if ($product_brand) $map[] = ['product_brand', 'like', "%$product_brand%"];
  115. // 权限判断
  116. if ($is_admin != 1 && $company_id != 0) {
  117. $map[] = ['company_id', '=', $company_id];
  118. $map2[] = ['company_id', '=', $company_id];
  119. $map3[] = ['company_id', '=', $company_id];
  120. } else {
  121. $map[] = ['company_id', '=', $admin_company_id];
  122. $map2[] = ['company_id', '=', $admin_company_id];
  123. $map3[] = ['company_id', '=', $admin_company_id];
  124. }
  125. // 查询数据
  126. $result = $ProductModel->query()
  127. ->where($map)
  128. ->where([['product_brand', '!=', ''], ['product_brand', '!=', null]])
  129. ->select([DB::raw('MAX(id) as id'), 'product_brand'])
  130. ->groupBy(['product_brand'])
  131. ->orderByDesc('id')->get()->toarray();
  132. if (!$result) return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => []]);
  133. foreach ($result as $key => $value) {
  134. $product_list = $ProductModel->query()
  135. ->where($map2)
  136. ->where([['product_name', '!=', ''], ['product_name', '!=', null]])
  137. ->where(['product_brand' => $value['product_brand']])
  138. ->select([DB::raw('MAX(id) as id'), 'product_name'])
  139. ->groupBy(['product_name'])
  140. ->orderByDesc('id')->get()->toarray();
  141. if (!empty($product_list)) {
  142. foreach ($product_list as $key2 => $value2) {
  143. $product_keyword = $ProductKeywordModel->query()
  144. ->where(['collect_product_id' => $value2['id']])
  145. ->select('keyword')
  146. ->groupBy(['keyword'])
  147. ->get()->toarray();
  148. $product_list[$key2]['product_keyword'] = $product_keyword ? array_column($product_keyword, 'keyword') : [];
  149. $product_specs = $ProductModel->query()
  150. ->where($map3)
  151. ->where([['product_specs', '!=', ''], ['product_specs', '!=', null]])
  152. ->where(['product_name' => $value2['product_name']])
  153. ->where(['product_brand' => $value['product_brand']])
  154. ->select([DB::raw('MAX(id) as id'), 'product_specs'])
  155. ->groupBy(['product_specs'])
  156. ->orderByDesc('id')->get()->toarray();
  157. $product_specs_tring = [];
  158. if (count($product_specs) > 0) {
  159. foreach ($product_specs as $key3 => $value3) {
  160. $product_specs_item = isset($value3['product_specs']) ? explode(',', $value3['product_specs']) : '';
  161. //合并数组
  162. if (!empty($product_specs_item)) {
  163. $product_specs_tring = array_merge($product_specs_tring, $product_specs_item);
  164. }
  165. }
  166. //去重
  167. $product_specs_tring = array_unique($product_specs_tring);
  168. }
  169. //移除空数组
  170. $product_list[$key2]['product_specs'] = $product_specs_tring ? array_filter($product_specs_tring) : '';
  171. }
  172. }
  173. $result[$key]['product_list'] = !empty($product_list) ? $product_list : [];
  174. }
  175. // 加载模板
  176. return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => $result]);
  177. }
  178. /**
  179. * 详情
  180. * @author 唐远望
  181. * @version 1.0
  182. * @date 2025-12-30
  183. */
  184. public function detail(Request $request, ProductModel $ProductModel)
  185. {
  186. $request->scene('detail')->validate();
  187. $admin_company_id = request('admin_company_id', '0');
  188. $company_id = request('access_token.company_id', '0');
  189. $is_admin = request('access_token.is_admin', '0');
  190. // 接收参数
  191. $id = request('id', 0);
  192. $map = ['id' => $id];
  193. // 权限判断
  194. if ($is_admin != 1 && $company_id != 0) {
  195. $map['company_id'] = $company_id;
  196. } else {
  197. $map['company_id'] = $admin_company_id;
  198. }
  199. $data = $ProductModel->where($map)->with(['product_keyword'])->first();
  200. if (!$data) return json_send(['code' => 'error', 'msg' => '记录不存在']);
  201. $data->platform = isset($data->platform) ? explode(',', $data->platform) : '';
  202. $product_specs = isset($data->product_specs) ? explode(',', $data->product_specs) : '';
  203. //移除空数组
  204. $data->product_specs = $product_specs ? array_filter($product_specs) : '';
  205. // 加载模板
  206. return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => $data]);
  207. }
  208. /**
  209. * 添加
  210. * @author 唐远望
  211. * @version 1.0
  212. * @date 2025-12-30
  213. *
  214. */
  215. public function add(Request $request, ProductModel $ProductModel)
  216. {
  217. $request->scene('add')->validate();
  218. $admin_company_id = request('admin_company_id', '0');
  219. $company_id = request('access_token.company_id', '0');
  220. $is_admin = request('access_token.is_admin', '0'); //是否管理员操作 0=是1=否
  221. //商品启用数量
  222. // $product_count = $ProductModel->where('status', 0)->count();
  223. //判断是否超过限制
  224. // if ($product_count >= 50) {
  225. // return json_send(['code' => 'error', 'msg' => '启用数量超过限制,不能超过50条']);
  226. // }
  227. // 接收数据
  228. $all_data = request()->all();
  229. $product_brand = request('product_brand', '');
  230. $product_keyword = request('product_keyword', '');
  231. $platform_string = $all_data['platform'];
  232. if(empty($platform_string)) return json_send(['code' => 'error', 'msg' => '平台不能为空']);
  233. $all_data['product_brand'] = $product_brand;
  234. $all_data['product_keyword'] = $product_keyword;
  235. if (trim($product_keyword) != '') {
  236. $product_keyword_count = count(explode(',', $product_keyword));
  237. if ($product_keyword_count > 5) {
  238. return json_send(['code' => 'error', 'msg' => '商品关键词不能超过5个']);
  239. }
  240. }
  241. //采集信息配置
  242. $enable_full_quantity = request('enable_full_quantity', 1); //全量,0启用,1禁用
  243. $all_data['enable_full_quantity'] = $enable_full_quantity;
  244. if ($enable_full_quantity == 1 && !isset($all_data['product_specs'])) {
  245. return json_send(['code' => 'error', 'msg' => '非全量采集时,商品规格不能为空']);
  246. }
  247. $minimum_order_quantity = request('minimum_order_quantity', 1);
  248. $sampling_cycle = request('sampling_cycle', '0');
  249. $sampling_start_time = request('sampling_start_time', '');
  250. $sampling_end_time = request('sampling_end_time', '');
  251. $all_data['sampling_cycle'] = $sampling_cycle;
  252. $all_data['sampling_start_time'] = $sampling_start_time ? strtotime($sampling_start_time . '00:00:00') : '0';
  253. $all_data['sampling_end_time'] = $sampling_end_time ? strtotime($sampling_end_time . '23:59:59') : '0';
  254. $all_data['minimum_order_quantity'] = $minimum_order_quantity;
  255. if ($all_data['sampling_start_time'] && strtotime(date('Y-m-d', $all_data['sampling_start_time']) . '23:59:59') < time()) return json_send(['code' => 'error', 'msg' => '采集开始时间必须大于当前时间']);
  256. if ($all_data['sampling_end_time'] && $all_data['sampling_end_time'] < time()) return json_send(['code' => 'error', 'msg' => '采集结束时间必须大于当前时间']);
  257. //查询是否存在
  258. $map = ['product_brand' => $product_brand, 'product_name' => $all_data['product_name']];
  259. if ($is_admin != 1 && $company_id != 0) {
  260. $map['company_id'] = $company_id;
  261. $all_data['company_id'] = $company_id;
  262. } else {
  263. $map['company_id'] = $admin_company_id;
  264. $all_data['company_id'] = $admin_company_id;
  265. }
  266. $data = $ProductModel->where($map)->first();
  267. if (!empty($data)) {
  268. //继续校验规格是否存在
  269. $product_specs_tring = $all_data['product_specs'];
  270. $product_specs = $product_specs_tring ? explode(',', $product_specs_tring) : '';
  271. $product_specs = $product_specs ? array_unique($product_specs) : '';
  272. //继续校平台是否存在
  273. $platforms = $platform_string ? explode(',', $platform_string) : '';
  274. $platforms = $platforms ? array_unique($platforms) : '';
  275. $platform_data = $ProductModel->platform_data();
  276. foreach ($platforms as $platform) {
  277. $product_specs_log = $ProductModel
  278. ->whereRaw("FIND_IN_SET(?, platform)", [$platform])
  279. ->where(['product_brand' => $product_brand, 'product_name' => $all_data['product_name']])
  280. ->where(function ($query) use ($product_specs) {
  281. // 平台条件(固定)
  282. $query->where(function ($query_li) use ($product_specs) {
  283. foreach ($product_specs as $product_spec) {
  284. if (empty($product_specs)) continue;
  285. $query_li->orWhereRaw("FIND_IN_SET(?, product_specs)", [$product_spec]);
  286. }
  287. });
  288. })->first();
  289. $platform_name = isset($platform_data[$platform]) ? $platform_data[$platform] : '';
  290. if (!empty($product_specs_log)) {
  291. return json_send(['code' => 'error', 'msg' => $platform_name.'存在重复的商品规格记录']);
  292. }
  293. }
  294. }
  295. // 写入数据表
  296. $result = $ProductModel->addProduct($all_data);
  297. // 如果操作失败
  298. if (!$result) return json_send(['code' => 'error', 'msg' => '新增失败']);
  299. // 记录行为
  300. $admin_id = request('access_token.uid', 0); //用户ID
  301. $table_name = $ProductModel->getTable();
  302. $notes_type = 1; //操作类型,1添加,2修改,3=删除
  303. $this->addAdminHistory('采集配置-商品管理', $company_id, $admin_id, $is_admin, $table_name, $notes_type, [], $all_data, '新增了商品' . $all_data['product_name'] . '信息');
  304. // 告知结果
  305. return json_send(['code' => 'success', 'msg' => '新增成功']);
  306. }
  307. /**
  308. * 修改
  309. * @author 唐远望
  310. * @version 1.0
  311. * @date 2025-12-30
  312. *
  313. */
  314. public function edit(Request $request, ProductModel $ProductModel)
  315. {
  316. $request->scene('edit')->validate();
  317. $admin_company_id = request('admin_company_id', '0');
  318. $company_id = request('access_token.company_id', '0');
  319. $is_admin = request('access_token.is_admin', '0'); //是否管理员操作 0=是1=否
  320. // 接收参数
  321. $id = request('id', 0);
  322. // 接收数据
  323. $all_data = request()->all();
  324. $product_brand = request('product_brand', '');
  325. $product_keyword = request('product_keyword', '');
  326. $platform_string = $all_data['platform'];
  327. if(empty($platform_string)) return json_send(['code' => 'error', 'msg' => '平台不能为空']);
  328. $all_data['product_brand'] = $product_brand;
  329. $all_data['product_keyword'] = $product_keyword;
  330. if (trim($product_keyword) != '') {
  331. $product_keyword_count = count(explode(',', $product_keyword));
  332. if ($product_keyword_count > 5) {
  333. return json_send(['code' => 'error', 'msg' => '商品关键词不能超过5个']);
  334. }
  335. }
  336. //采集信息配置
  337. $enable_full_quantity = request('enable_full_quantity', 1); //全量,0启用,1禁用
  338. $all_data['enable_full_quantity'] = $enable_full_quantity;
  339. if ($enable_full_quantity == 1 && !isset($all_data['product_specs'])) {
  340. return json_send(['code' => 'error', 'msg' => '非全量采集时,商品规格不能为空']);
  341. }
  342. $minimum_order_quantity = request('minimum_order_quantity', 1);
  343. $sampling_cycle = request('sampling_cycle', '0');
  344. $sampling_start_time = request('sampling_start_time', '');
  345. $sampling_end_time = request('sampling_end_time', '');
  346. $all_data['sampling_cycle'] = $sampling_cycle;
  347. $all_data['sampling_start_time'] = $sampling_start_time ? strtotime($sampling_start_time . '00:00:00') : '0';
  348. $all_data['sampling_end_time'] = $sampling_end_time ? strtotime($sampling_end_time . '23:59:59') : '0';
  349. $all_data['minimum_order_quantity'] = $minimum_order_quantity;
  350. if ($all_data['sampling_start_time'] && strtotime(date('Y-m-d', $all_data['sampling_start_time']) . '23:59:59') < time()) return json_send(['code' => 'error', 'msg' => '采集开始时间必须大于当前时间']);
  351. if ($all_data['sampling_end_time'] && $all_data['sampling_end_time'] < time()) return json_send(['code' => 'error', 'msg' => '采集结束时间必须大于当前时间']);
  352. //查询是否存在
  353. $map = ['product_brand' => $product_brand, 'product_name' => $all_data['product_name']];
  354. if ($is_admin != 1 && $company_id != 0) {
  355. $map['company_id'] = $company_id;
  356. } else {
  357. $map['company_id'] = $admin_company_id;
  358. }
  359. $data = $ProductModel->where($map)->where('id', '!=', $id)->first();
  360. if (!empty($data)) {
  361. //继续校验规格是否存在
  362. $product_specs_tring = $all_data['product_specs'];
  363. $product_specs = $product_specs_tring ? explode(',', $product_specs_tring) : '';
  364. $product_specs = $product_specs ? array_unique($product_specs) : '';
  365. //继续校平台是否存在
  366. $platforms = $platform_string ? explode(',', $platform_string) : '';
  367. $platforms = $platforms ? array_unique($platforms) : '';
  368. $platform_data = $ProductModel->platform_data();
  369. foreach ($platforms as $platform) {
  370. $product_specs_log = $ProductModel
  371. ->whereRaw("FIND_IN_SET(?, platform)", [$platform])
  372. ->where(['product_brand' => $product_brand, 'product_name' => $all_data['product_name']])
  373. ->where('id', '!=', $id)
  374. ->where(function ($query) use ($product_specs) {
  375. // 平台条件(固定)
  376. $query->where(function ($query_li) use ($product_specs) {
  377. foreach ($product_specs as $product_spec) {
  378. if (empty($product_specs)) continue;
  379. $query_li->orWhereRaw("FIND_IN_SET(?, product_specs)", [$product_spec]);
  380. }
  381. });
  382. })->first();
  383. $platform_name = isset($platform_data[$platform]) ? $platform_data[$platform] : '';
  384. if (!empty($product_specs_log)) {
  385. return json_send(['code' => 'error', 'msg' => $platform_name.'存在重复的商品规格记录']);
  386. }
  387. }
  388. }
  389. // 更新数据表
  390. $where = ['id' => $id];
  391. // 权限判断
  392. if ($is_admin != 1 && $company_id != 0) {
  393. $where['company_id'] = $company_id;
  394. } else {
  395. $where['company_id'] = $admin_company_id;
  396. }
  397. $Product = $ProductModel->where($where)->first();
  398. if (!$Product) return json_send(['code' => 'error', 'msg' => '记录不存在']);
  399. $oldData = $Product->toarray();
  400. $result = $ProductModel->editProduct_content($Product, $all_data);
  401. // 如果操作失败
  402. if (!$result) return json_send(['code' => 'error', 'msg' => '修改失败']);
  403. // 记录行为
  404. $admin_id = request('access_token.uid', 0); //用户ID
  405. $table_name = $ProductModel->getTable();
  406. $notes_type = 2; //操作类型,1添加,2修改,3=删除
  407. $this->addAdminHistory('采集配置-商品管理', $company_id, $admin_id, $is_admin, $table_name, $notes_type, $oldData, $all_data, '修改了商品' . $oldData['product_name'] . '信息');
  408. // 告知结果
  409. return json_send(['code' => 'success', 'msg' => '修改成功']);
  410. }
  411. /**
  412. * 修改状态
  413. * @author 唐远望
  414. * @version 1.0
  415. * @date 2025-12-30
  416. *
  417. */
  418. public function set_status(Request $request, ProductModel $ProductModel)
  419. {
  420. // 验证参数
  421. $request->scene('set_status')->validate();
  422. $admin_company_id = request('admin_company_id', '0');
  423. $company_id = request('access_token.company_id', '0');
  424. $is_admin = request('access_token.is_admin', '0'); //是否管理员操作 0=是1=否
  425. // 接收数据
  426. $id = request('id', 0);
  427. $status = request('status', 0);
  428. if ($status == 0) {
  429. //获取商品启用数量
  430. // $product_count = $ProductModel->where('status', 0)->count();
  431. //判断是否超过限制
  432. // if ($product_count >= 50) {
  433. // return json_send(['code' => 'error', 'msg' => '启用数量超过限制,不能超过50条']);
  434. // }
  435. }
  436. // 查询用户
  437. $where = ['id' => $id];
  438. if ($is_admin != 1 && $company_id != 0) {
  439. $where['company_id'] = $company_id;
  440. } else {
  441. $where['company_id'] = $admin_company_id;
  442. }
  443. $Product = $ProductModel->where($where)->first();
  444. if (!$Product) return json_send(['code' => 'error', 'msg' => '记录不存在']);
  445. // 执行修改
  446. $result = $ProductModel->changeStatus($Product, $status);
  447. // 提示新增失败
  448. if (!$result) return json_send(['code' => 'error', 'msg' => '设置失败']);
  449. // 记录行为
  450. $admin_id = request('access_token.uid', 0); //用户ID
  451. $table_name = $ProductModel->getTable();
  452. $notes_type = 2; //操作类型,1添加,2修改,3=删除
  453. $this->addAdminHistory('采集配置-商品管理', $company_id, $admin_id, $is_admin, $table_name, $notes_type, [], ['status' => $status], '修改了商品' . $Product->product_name . '状态');
  454. // 告知结果
  455. return json_send(['code' => 'success', 'msg' => '设置成功']);
  456. }
  457. /**
  458. * 删除
  459. * @author 唐远望
  460. * @version 1.0
  461. * @date 2025-12-30
  462. *
  463. */
  464. public function delete(Request $request, ProductModel $ProductModel)
  465. {
  466. // 验证参数
  467. $request->scene('delete')->validate();
  468. $admin_company_id = request('admin_company_id', '0');
  469. $company_id = request('access_token.company_id', '0');
  470. $is_admin = request('access_token.is_admin', '0'); //是否管理员操作 0=是1=否
  471. // 接收数据
  472. $id = request('id', 0);
  473. // 查询用户
  474. $where = ['id' => $id];
  475. if ($is_admin != 1 && $company_id != 0) {
  476. $where['company_id'] = $company_id;
  477. } else {
  478. $where['company_id'] = $admin_company_id;
  479. }
  480. // 执行删除
  481. $Product = $ProductModel->where($where)->first();
  482. if (!$Product) {
  483. return json_send(['code' => 'error', 'msg' => '删除失败,记录不存在']);
  484. }
  485. DB::beginTransaction();
  486. try {
  487. $Product->delete();
  488. // 记录行为
  489. $admin_id = request('access_token.uid', 0); //用户ID
  490. $table_name = $ProductModel->getTable();
  491. $notes_type = 3; //操作类型,1添加,2修改,3=删除
  492. $this->addAdminHistory('采集配置-商品管理', $company_id, $admin_id, $is_admin, $table_name, $notes_type, $Product->toarray(), [], '删除了商品' . $Product->product_name . '信息');
  493. // 告知结果
  494. DB::commit();
  495. return json_send(['code' => 'success', 'msg' => '删除成功']);
  496. // 成功处理...
  497. } catch (\Exception $e) {
  498. DB::rollBack();
  499. // 错误处理...
  500. return json_send(['code' => 'error', 'msg' => '删除失败']);
  501. }
  502. }
  503. }