ViolationProduct.php 25 KB

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