ViolationProduct.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507
  1. <?php
  2. namespace App\Http\Controllers\Manager\WashConfig;
  3. use App\Http\Controllers\Controller;
  4. use App\Http\Requests\Manager\WashConfig\ViolationProduct as Request;
  5. use App\Models\Manager\WashConfig\ViolationProduct as ViolationProductModel;
  6. use App\Models\Manager\WashConfig\ViolationStore as ViolationStoreModel;
  7. use App\Models\Manager\WashConfig\ViolationProductCompany as ViolationProductCompanyModel;
  8. use App\Models\Manager\WashConfig\ProductCategory as ProductCategoryModel;
  9. use Illuminate\Support\Facades\DB;
  10. use App\Models\Manager\WashConfig\LowPriceGoods as LowPriceGoodsModel;
  11. use Illuminate\Support\Carbon;
  12. use PhpOffice\PhpSpreadsheet\Spreadsheet;
  13. use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
  14. use PhpOffice\PhpSpreadsheet\Style\Alignment;
  15. use PhpOffice\PhpSpreadsheet\IOFactory;
  16. /**
  17. * 数据清洗-禁止产品配置
  18. * @author 唐远望
  19. * @version 1.0
  20. * @date 2025-12-03
  21. */
  22. class ViolationProduct extends Controller
  23. {
  24. /**
  25. * 列表
  26. * @author 唐远望
  27. * @version 1.0
  28. * @date 2025-12-03
  29. *
  30. */
  31. public function list(Request $request, ViolationProductModel $ViolationProductModel, ViolationStoreModel $ViolationStoreModel, ViolationProductCompanyModel $ViolationProductCompanyModel, ProductCategoryModel $ProductCategoryModel)
  32. {
  33. $request->scene('list')->validate();
  34. $admin_company_id = request('admin_company_id', '0');
  35. $company_id = request('access_token.company_id', '0');
  36. $is_admin = request('access_token.is_admin', '0'); //是否管理员操作 0=是1=否
  37. // 查询条件
  38. $map = [];
  39. $limit = request('limit', config('page_num', 10));
  40. $status = request('status', '');
  41. $start_time = request('start_time', '');
  42. $end_time = request('end_time', '');
  43. $product_name = request('product_name', '');
  44. $platform = request('platform', '');
  45. $store_scope = request('store_scope', '');
  46. $company_scope = request('company_scope', '');
  47. $category_id = request('category_id', '');
  48. // 时间条件
  49. if ($start_time) $map[] = ['insert_time', '>=', strtotime($start_time)];
  50. if ($end_time) $map[] = ['insert_time', '<=', strtotime($end_time)];
  51. // 其他条件
  52. if (is_numeric($status)) $map[] = ['status', '=', $status];
  53. if ($product_name) $map[] = ['product_name', 'like', "%$product_name%"];
  54. if ($platform) $map[] = ['platform', 'like', "%$platform%"];
  55. if ($store_scope) $map[] = ['store_scope', '=', $store_scope];
  56. if ($company_scope) $map[] = ['company_scope', '=', $company_scope];
  57. if ($category_id) $map[] = ['category_id', '=', $category_id];
  58. // 查询数据
  59. if ($is_admin != 1 && $company_id != 0) {
  60. $map[] = ['company_id', '=', $company_id];
  61. } else {
  62. $map[] = ['company_id', '=', $admin_company_id];
  63. }
  64. $result = $ViolationProductModel->query()
  65. ->where($map)
  66. ->orderByDesc('id')
  67. ->paginate($limit)->toarray();
  68. // 分配数据
  69. if (!$result) return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => []]);
  70. if (isset($result['data']) && count($result['data']) > 0) {
  71. foreach ($result['data'] as $key => $value) {
  72. $result['data'][$key]['platform'] = isset($value['platform']) ? explode(',', $value['platform']) : '';
  73. $category_name = $value['category_id'] > 0 ? $ProductCategoryModel->where('id', $value['category_id'])->value('name') : '';
  74. $result['data'][$key]['category_name'] = $category_name;
  75. //查询店铺名称
  76. if (trim($value['store_scope']) == '') {
  77. $result['data'][$key]['store_name'] = ['全部店铺'];
  78. } else {
  79. $result['data'][$key]['store_name'] = '';
  80. }
  81. //查询公司名称
  82. if ($value['company_scope'] == '1') {
  83. $result['data'][$key]['company_name'] = ['全部公司'];
  84. } else {
  85. $company_data = $ViolationProductCompanyModel->where('violation_product_logid', $value['id'])
  86. ->join('washconfig_violation_store', 'washconfig_violation_store.id', '=', 'washconfig_violation_product_company.company_id')
  87. ->select(['washconfig_violation_store.id', 'washconfig_violation_store.company_name', 'washconfig_violation_product_company.company_id'])->get()->toArray();
  88. $result['data'][$key]['company_name'] = !empty($company_data) ? array_column($company_data, 'company_name') : '';
  89. }
  90. }
  91. }
  92. // 加载模板
  93. return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => $result]);
  94. }
  95. /**
  96. * 详情
  97. * @author 唐远望
  98. * @version 1.0
  99. * @date 2025-12-03
  100. */
  101. public function detail(Request $request, ViolationProductModel $ViolationProductModel, ViolationProductCompanyModel $ViolationProductCompanyModel, ProductCategoryModel $ProductCategoryModel)
  102. {
  103. $request->scene('detail')->validate();
  104. $admin_company_id = request('admin_company_id', '0');
  105. $company_id = request('access_token.company_id', '0');
  106. $is_admin = request('access_token.is_admin', '0'); //是否管理员操作 0=是1=否
  107. // 接收参数
  108. $id = request('id', 0);
  109. $map = ['id' => $id];
  110. if ($is_admin != 1 && $company_id != 0) {
  111. $map['company_id'] = $company_id;
  112. } else {
  113. $map['company_id'] = $admin_company_id;
  114. }
  115. $data = $ViolationProductModel->where($map)->first();
  116. if (!$data) return json_send(['code' => 'error', 'msg' => '记录不存在']);
  117. //查询店铺名称
  118. if (trim($data['store_scope']) == '') {
  119. $data['store_name'] = ['全部店铺'];
  120. } else {
  121. $data['store_name'] = '';
  122. }
  123. //查询公司名称
  124. if ($data->company_scope == '1') {
  125. $data->company_name = ['全部公司'];
  126. $data->company_ids = '';
  127. } else {
  128. $company_data = $ViolationProductCompanyModel->where('violation_product_logid', $data->id)
  129. ->join('washconfig_violation_store', 'washconfig_violation_store.id', '=', 'washconfig_violation_product_company.company_id')
  130. ->select(['washconfig_violation_store.id', 'washconfig_violation_store.company_name', 'washconfig_violation_product_company.company_id'])->get()->toArray();
  131. $data->company_name = !empty($company_data) ? array_column($company_data, 'company_name') : '';
  132. $data->company_ids = !empty($company_data) ? array_column($company_data, 'company_id') : '';
  133. }
  134. $data->platform = isset($data->platform) ? explode(',', $data->platform) : '';
  135. $data->category_name = $data->category_id > 0 ? $ProductCategoryModel->where('id', $data->category_id)->value('name') : '';
  136. // 加载模板
  137. return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => $data]);
  138. }
  139. /**
  140. * 添加
  141. * @author 唐远望
  142. * @version 1.0
  143. * @date 2025-12-03
  144. *
  145. */
  146. public function add(Request $request, ViolationProductModel $ViolationProductModel, LowPriceGoodsModel $LowPriceGoodsModel)
  147. {
  148. $request->scene('add')->validate();
  149. $admin_company_id = request('admin_company_id', '0');
  150. $company_id = request('access_token.company_id', '0');
  151. $is_admin = request('access_token.is_admin', '0'); //是否管理员操作 0=是1=否
  152. $status_where = ['status' => 0];
  153. if ($is_admin != 1 && $company_id != 0) {
  154. $status_where['company_id'] = $company_id;
  155. } else {
  156. $status_where['company_id'] = $admin_company_id;
  157. }
  158. //获取禁止商品启动数量
  159. $violation_product_count = $ViolationProductModel->where($status_where)->count();
  160. //获取低价挂网商品启用数量
  161. $lowprice_product_count = $LowPriceGoodsModel->where($status_where)->count();
  162. //计算总数量
  163. $product_totle = $violation_product_count + $lowprice_product_count;
  164. //判断是否超过限制
  165. if ($product_totle >= 50) {
  166. return json_send(['code' => 'error', 'msg' => '启用数量超过限制,低价挂网和禁止商品不能超过50条']);
  167. }
  168. // 接收数据
  169. $all_data = request()->all();
  170. $store_scope = request('store_scope', '');
  171. $all_data['store_scope'] = $store_scope;
  172. $company_scope = request('company_scope', '');
  173. $all_data['company_scope'] = $company_scope;
  174. $category_id = request('category_id', '0');
  175. $all_data['category_id'] = $category_id;
  176. $specify_responsible_person = request('specify_responsible_person', '0');
  177. $all_data['specify_responsible_person'] = $specify_responsible_person;
  178. //查询是否存在
  179. $map = ['product_name' => $all_data['product_name'], 'product_specs' => $all_data['product_specs'], 'platform' => $all_data['platform']];
  180. if ($is_admin != 1 && $company_id != 0) {
  181. $map['company_id'] = $company_id;
  182. $all_data['company_id'] = $company_id;
  183. } else {
  184. $map['company_id'] = $admin_company_id;
  185. $all_data['company_id'] = $admin_company_id;
  186. }
  187. $data = $ViolationProductModel->where($map)->first();
  188. if ($data) return json_send(['code' => 'error', 'msg' => '记录已存在']);
  189. // 写入数据表
  190. $result = $ViolationProductModel->addViolationProduct($all_data);
  191. // 如果操作失败
  192. if (!$result) return json_send(['code' => 'error', 'msg' => '新增失败']);
  193. // 记录行为
  194. $admin_id = request('access_token.uid', 0); //用户ID
  195. $table_name = $ViolationProductModel->getTable();
  196. $notes_type = 1; //操作类型,1添加,2修改,3=删除
  197. $this->addAdminHistory('清洗配置-禁止商品管理', $company_id, $admin_id, $is_admin, $table_name, $notes_type, [], $all_data, '新增了禁止商品' . $all_data['product_name'] . '信息');
  198. // 告知结果
  199. return json_send(['code' => 'success', 'msg' => '新增成功']);
  200. }
  201. /**
  202. * 修改
  203. * @author 唐远望
  204. * @version 1.0
  205. * @date 2025-12-03
  206. *
  207. */
  208. public function edit(Request $request, ViolationProductModel $ViolationProductModel)
  209. {
  210. $request->scene('edit')->validate();
  211. $admin_company_id = request('admin_company_id', '0');
  212. $company_id = request('access_token.company_id', '0');
  213. $is_admin = request('access_token.is_admin', '0'); //是否管理员操作 0=是1=否
  214. // 接收参数
  215. $id = request('id', 0);
  216. // 接收数据
  217. $all_data = request()->all();
  218. $store_scope = request('store_scope', '');
  219. $all_data['store_scope'] = $store_scope;
  220. $company_scope = request('company_scope', '');
  221. $all_data['company_scope'] = $company_scope;
  222. $category_id = request('category_id', '0');
  223. $all_data['category_id'] = $category_id;
  224. $specify_responsible_person = request('specify_responsible_person', '0');
  225. $all_data['specify_responsible_person'] = $specify_responsible_person;
  226. //查询是否存在
  227. $map = ['product_name' => $all_data['product_name'], 'product_specs' => $all_data['product_specs'], 'platform' => $all_data['platform']];
  228. if ($is_admin != 1 && $company_id != 0) {
  229. $map['company_id'] = $company_id;
  230. $all_data['company_id'] = $company_id;
  231. } else {
  232. $map['company_id'] = $admin_company_id;
  233. $all_data['company_id'] = $admin_company_id;
  234. }
  235. $data = $ViolationProductModel->where($map)->where('id', '!=', $id)->first();
  236. if ($data) return json_send(['code' => 'error', 'msg' => '记录已存在']);
  237. // 更新数据表
  238. $where = ['id' => $id];
  239. if ($is_admin != 1 && $company_id != 0) {
  240. $where['company_id'] = $company_id;
  241. } else {
  242. $where['company_id'] = $admin_company_id;
  243. }
  244. $ViolationProduct = $ViolationProductModel->where($where)->first();
  245. if (!$ViolationProduct) return json_send(['code' => 'error', 'msg' => '记录不存在']);
  246. $oldData = $ViolationProduct->toarray();
  247. $result = $ViolationProductModel->editViolationProduct_content($ViolationProduct, $all_data);
  248. // 如果操作失败
  249. if (!$result) return json_send(['code' => 'error', 'msg' => '修改失败']);
  250. // 记录行为
  251. $admin_id = request('access_token.uid', 0); //用户ID
  252. $table_name = $ViolationProductModel->getTable();
  253. $notes_type = 2; //操作类型,1添加,2修改,3=删除
  254. $this->addAdminHistory('清洗配置-禁止商品管理', $company_id, $admin_id, $is_admin, $table_name, $notes_type, $oldData, $all_data, '修改了禁止商品' . $oldData['product_name'] . '信息');
  255. // 告知结果
  256. return json_send(['code' => 'success', 'msg' => '修改成功']);
  257. }
  258. /**
  259. * 修改状态
  260. * @author 唐远望
  261. * @version 1.0
  262. * @date 2025-12-03
  263. *
  264. */
  265. public function set_status(Request $request, ViolationProductModel $ViolationProductModel, LowPriceGoodsModel $LowPriceGoodsModel)
  266. {
  267. // 验证参数
  268. $request->scene('set_status')->validate();
  269. $admin_company_id = request('admin_company_id', '0');
  270. $company_id = request('access_token.company_id', '0');
  271. $is_admin = request('access_token.is_admin', '0'); //是否管理员操作 0=是1=否
  272. // 接收数据
  273. $id = request('id', 0);
  274. $status = request('status', 0);
  275. if ($status == 0) {
  276. //获取禁止商品启动数量
  277. $violation_product_count = $ViolationProductModel->where('status', 0)->count();
  278. //获取低价挂网商品启用数量
  279. $lowprice_product_count = $LowPriceGoodsModel->where('status', 0)->count();
  280. //计算总数量
  281. $product_totle = $violation_product_count + $lowprice_product_count;
  282. //判断是否超过限制
  283. if ($product_totle >= 50) {
  284. return json_send(['code' => 'error', 'msg' => '启用数量超过限制,低价挂网和禁止商品不能超过50条']);
  285. }
  286. }
  287. // 查询用户
  288. $where = ['id' => $id];
  289. if ($is_admin != 1 && $company_id != 0) {
  290. $where['company_id'] = $company_id;
  291. } else {
  292. $where['company_id'] = $admin_company_id;
  293. }
  294. $ViolationProduct = $ViolationProductModel->where($where)->first();
  295. if (!$ViolationProduct) return json_send(['code' => 'error', 'msg' => '记录不存在']);
  296. // 执行修改
  297. $result = $ViolationProductModel->changeStatus($ViolationProduct, $status);
  298. // 提示新增失败
  299. if (!$result) return json_send(['code' => 'error', 'msg' => '设置失败']);
  300. // 记录行为
  301. $admin_id = request('access_token.uid', 0); //用户ID
  302. $table_name = $ViolationProductModel->getTable();
  303. $notes_type = 2; //操作类型,1添加,2修改,3=删除
  304. $this->addAdminHistory('清洗配置-禁止商品管理', $company_id, $admin_id, $is_admin, $table_name, $notes_type, [], ['status' => $status], '修改了禁止商品' . $ViolationProduct->product_name . '状态');
  305. // 告知结果
  306. return json_send(['code' => 'success', 'msg' => '设置成功']);
  307. }
  308. /**
  309. * 删除
  310. * @author 唐远望
  311. * @version 1.0
  312. * @date 2025-12-03
  313. *
  314. */
  315. public function delete(Request $request, ViolationProductModel $ViolationProductModel)
  316. {
  317. // 验证参数
  318. $request->scene('delete')->validate();
  319. $admin_company_id = request('admin_company_id', '0');
  320. $company_id = request('access_token.company_id', '0');
  321. $is_admin = request('access_token.is_admin', '0'); //是否管理员操作 0=是1=否
  322. // 接收数据
  323. $id = request('id', 0);
  324. // 查询用户
  325. $where = ['id' => $id];
  326. if ($is_admin != 1 && $company_id != 0) {
  327. $where['company_id'] = $company_id;
  328. } else {
  329. $where['company_id'] = $admin_company_id;
  330. }
  331. // 执行删除
  332. $ViolationProduct = $ViolationProductModel->where($where)->first();
  333. if (!$ViolationProduct) {
  334. return false;
  335. }
  336. $ViolationProduct_log = $ViolationProduct->toArray();
  337. DB::beginTransaction();
  338. try {
  339. $ViolationProductCompanyModel = new ViolationProductCompanyModel();
  340. $company_id_log = $ViolationProductCompanyModel->where('violation_product_logid', $ViolationProduct->id)->get();
  341. if (!empty($company_id_log)) {
  342. $ViolationProductCompanyModel->where('violation_product_logid', $ViolationProduct->id)->delete();
  343. }
  344. $ViolationProductModel->where($where)->delete();
  345. // 记录行为
  346. $admin_id = request('access_token.uid', 0); //用户ID
  347. $table_name = $ViolationProductModel->getTable();
  348. $notes_type = 3; //操作类型,1添加,2修改,3=删除
  349. $this->addAdminHistory('清洗配置-禁止商品管理', $company_id, $admin_id, $is_admin, $table_name, $notes_type, $ViolationProduct_log, [], '删除了禁止商品' . $ViolationProduct_log['product_name'] . '信息');
  350. // 告知结果
  351. DB::commit();
  352. return json_send(['code' => 'success', 'msg' => '删除成功']);
  353. // 成功处理...
  354. } catch (\Exception $e) {
  355. DB::rollBack();
  356. // 错误处理...
  357. return json_send(['code' => 'error', 'msg' => '删除失败', 'data' => $e->getMessage(), 'k' => $ViolationProduct_log]);
  358. }
  359. }
  360. /**
  361. * 下载导入模板
  362. * @author 唐远望
  363. * @version 1.0
  364. * @date 2026-02-28
  365. *
  366. */
  367. public function download_template()
  368. {
  369. // 创建一个新的 Spreadsheet 对象
  370. $spreadsheet = new Spreadsheet();
  371. $sheet = $spreadsheet->getActiveSheet();
  372. //合并单元格
  373. $sheet->mergeCells('A1:R1');
  374. $sheet->setCellValue('A1', '禁止挂网商品清洗导入模板'); // 设置合并后的单元格内容
  375. // 获取合并后的单元格样式对象
  376. $style = $sheet->getStyle('A1');
  377. // 设置水平居中和垂直居中
  378. $style->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER)->setVertical(Alignment::VERTICAL_CENTER);
  379. // 然后设置行高以适应两行文本
  380. $sheet->getRowDimension(1)->setRowHeight(40); // 设置行高,单位是磅(point)
  381. // 设置表头
  382. $sheet->setCellValue('A2', '商品名称*');
  383. $sheet->setCellValue('B2', '商品分类名称');
  384. $sheet->setCellValue('C2', '商品规格*');
  385. $sheet->setCellValue('D2', '平台名称(多个逗号隔开,为空全部)');
  386. $sheet->setCellValue('E2', '指定公司(多个逗号隔开,为空全部)');
  387. $sheet->setCellValue('F2', '指派责任人(是/否)*');
  388. // 生成 Excel 文件
  389. $writer = new Xlsx($spreadsheet);
  390. // 直接输出到浏览器(下载)
  391. $filename = '禁止挂网商品清洗导入模板.xlsx';
  392. header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
  393. header('Content-Disposition: attachment;filename="' . $filename . '"');
  394. header('Cache-Control: max-age=0');
  395. $writer->save('php://output');
  396. exit;
  397. }
  398. /**
  399. * 导入Excel数据
  400. * @author 唐远望
  401. * @version 1.0
  402. * @date 2026-02-28
  403. *
  404. */
  405. public function import_data(Request $request, ViolationProductModel $ViolationProductModel, ViolationStoreModel $ViolationStoreModel, ProductCategoryModel $ProductCategoryModel)
  406. {
  407. $request->scene('import_data')->validate();
  408. $admin_company_id = request('admin_company_id', '0');
  409. $company_id = request('access_token.company_id', '0');
  410. $is_admin = request('access_token.is_admin', '0'); //是否管理员操作 0=是1=否
  411. $file = $request->file('file');
  412. // 加载Excel文件
  413. $spreadsheet = IOFactory::load($file->getPathname());
  414. $sheet = $spreadsheet->getActiveSheet();
  415. // 获取所有数据
  416. $data = $sheet->toArray();
  417. if (empty($data) || count($data) < 2) return json_send(['code' => 'error', 'msg' => '导入数据为空']);
  418. $platform_data = $ViolationProductModel->platform_data();
  419. DB::beginTransaction();
  420. try {
  421. foreach ($data as $key => $item) {
  422. if ($key < 2) continue;
  423. //强制必传参数校验
  424. $res_data = $this->import_data_check($key, $item);
  425. if ($res_data) return json_send($res_data);
  426. $category_id = '0';
  427. if (isset($item[1])) {
  428. $category_data = $ProductCategoryModel->where('name', $item[1])->first();
  429. $category_id = $category_data ? $category_data->id : '0';
  430. }
  431. $platform_text = isset($item[3]) ? explode(',', $item[3]) : '0'; // 平台
  432. $platform_id_text = '';
  433. if (!empty($platform_text)) {
  434. foreach ($platform_text as $key => $value) {
  435. if (isset($platform_data[$value])) {
  436. $platform_id_text = $platform_data[$value] . ',' . $platform_id_text;
  437. }
  438. }
  439. }
  440. $company_scope = isset($item[4]) ? explode(',', $item[4]) : '0'; // 公司范围
  441. $company_id_text = '';
  442. if (!empty($company_scope)) {
  443. //查询所有公司ID逗号隔开
  444. $company_id_text = $ViolationStoreModel->whereIn('company_name', $company_scope)->pluck('id')->implode(',');
  445. }
  446. // 权限判断
  447. if ($is_admin != 1 && $company_id != 0) {
  448. $insert_product_data['company_id'] = $company_id;
  449. } else {
  450. $insert_product_data['company_id'] = $admin_company_id;
  451. }
  452. $insert_product_data['product_name'] = $item[0]; // 商品名称
  453. $insert_product_data['category_id'] =$category_id; // 商品分类
  454. $insert_product_data['product_specs'] = $item[2]; // 商品规格
  455. $insert_product_data['platform'] = $platform_id_text != '' ? substr($platform_id_text, 0, -1) : '0'; // 平台:0=全部,1=淘宝,2=京东,3=拼多多,4=美团,5=药师帮,6=1药城,7=药久久
  456. $insert_product_data['store_scope'] = ''; // 店铺范围(为空时全部,指定时为店铺ID多个逗号隔开)
  457. $insert_product_data['company_scope'] = $company_id_text; // 公司范围(为空时全部,指定时为公司ID多个逗号隔开)
  458. $insert_product_data['specify_responsible_person'] = trim($item[5]) == '是' ? 0 : 1; // 指派责任人 0=开启 1=关闭
  459. //插入数据
  460. $ViolationProductModel->addViolationProduct($insert_product_data);
  461. }
  462. DB::commit();
  463. return json_send(['code' => 'success', 'msg' => '导入成功']);
  464. // 成功处理...
  465. } catch (\Exception $e) {
  466. DB::rollBack();
  467. // 错误处理...
  468. return json_send(['code' => 'error', 'msg' => '导入失败', 'data' => $e->getMessage()]);
  469. }
  470. }
  471. /**
  472. * 导入Excel数据必传参数校验
  473. * @author 唐远望
  474. * @version 1.0
  475. * @date 2025-12-31
  476. *
  477. */
  478. private function import_data_check($key, $item)
  479. {
  480. $key = $key + 1;
  481. if (!$item[0]) {
  482. return ['code' => 'error', 'msg' => "第{$key}行商品名称不能为空", 'data' => $item];
  483. }
  484. if (!$item[2]) {
  485. return ['code' => 'error', 'msg' => "第{$key}行商品规格不能为空", 'data' => $item];
  486. }
  487. if (!$item[5]) {
  488. return ['code' => 'error', 'msg' => "第{$key}行指派责任人不能为空", 'data' => $item];
  489. }
  490. }
  491. }