ViolationProduct.php 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995
  1. <?php
  2. namespace App\Http\Controllers\Manager\Process;
  3. use App\Http\Controllers\Controller;
  4. use App\Http\Requests\Manager\Process\ViolationProduct as Request;
  5. use App\Models\Manager\Process\ViolationProduct as ViolationProductModel;
  6. use App\Jobs\Manager\Process\ViolationProductJobs;
  7. use App\Models\Manager\Personnel\Employee as EmployeeModel;
  8. use PhpOffice\PhpSpreadsheet\Spreadsheet;
  9. use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
  10. use PhpOffice\PhpSpreadsheet\Style\Alignment;
  11. use PhpOffice\PhpSpreadsheet\IOFactory;
  12. use App\Models\Manager\Process\ViolationProductMember as ViolationProductMemberModel;
  13. use App\Models\Manager\Citys as CitysModel;
  14. use Illuminate\Support\Facades\DB;
  15. /**
  16. * 违规处理-违规商品
  17. * @author 唐远望
  18. * @version 1.0
  19. * @date 2025-12-08
  20. */
  21. class ViolationProduct extends Controller
  22. {
  23. /**
  24. * 列表
  25. * @author 唐远望
  26. * @version 1.0
  27. * @date 2025-12-08
  28. *
  29. */
  30. public function list(Request $request, ViolationProductModel $ViolationProductModel, EmployeeModel $EmployeeModel, ViolationProductMemberModel $ViolationProductMemberModel)
  31. {
  32. $request->scene('list')->validate();
  33. $admin_company_id = request('admin_company_id', '0');
  34. $company_id = request('access_token.company_id', '0');
  35. $is_admin = request('access_token.is_admin', '0'); //是否管理员操作 0=是1=否
  36. $user_id = request('access_token.uid', 0);
  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. $product_names = request('product_names', '');
  45. $first_responsible_person = request('first_responsible_person', '');
  46. $responsible_person = request('responsible_person', '');
  47. $platform = request('platform', '');
  48. $company_name = request('company_name', '');
  49. $company_names = request('company_names', '');
  50. $store_name = request('store_name', '');
  51. $store_names = request('store_names', '');
  52. $source_responsible_person = request('source_responsible_person', '');
  53. $processing_status = request('processing_status', '');
  54. $product_specs = request('product_specs', '');
  55. $online_posting_count = request('online_posting_count', '');
  56. $category_name = request('category_name', '');
  57. $id = request('id', '');
  58. // 时间条件
  59. if ($start_time) $map[] = ['insert_time', '>=', strtotime($start_time)];
  60. if ($end_time) $map[] = ['insert_time', '<=', strtotime($end_time)];
  61. // 其他条件
  62. if ($product_name) $map[] = ['product_name', 'like', "%$product_name%"];
  63. if ($store_name) $map[] = ['store_name', 'like', "%$store_name%"];
  64. if ($category_name) $map[] = ['category_name', 'like', "%$category_name%"];
  65. if ($company_name) $map[] = ['company_name', 'like', "%$company_name%"];
  66. if ($id) $map[] = ['id', '=', $id];
  67. $violation_product_where = [];
  68. // 权限判断
  69. if ($is_admin != 1 && $company_id != 0) {
  70. $violation_product_where['company_id'] = $company_id;
  71. } else {
  72. $violation_product_where['company_id'] = $admin_company_id;
  73. }
  74. $ViolationProductModel = $ViolationProductModel->where($violation_product_where);
  75. //多选平台查询
  76. if ($platform && is_string($platform)) {
  77. $platform = explode(',', $platform);
  78. $ViolationProductModel = $ViolationProductModel->whereIn('platform', $platform);
  79. }
  80. //多选处理状态查询
  81. if ($processing_status && is_string($processing_status)) {
  82. $processing_status = explode(',', $processing_status);
  83. $ViolationProductModel = $ViolationProductModel->whereIn('processing_status', $processing_status);
  84. }
  85. //多选状态查询
  86. if ($status && is_string($status)) {
  87. $status = explode(',', $status);
  88. $ViolationProductModel = $ViolationProductModel->whereIn('status', $status);
  89. }
  90. //多选店铺名称查询
  91. if ($store_names && is_string($store_names)) {
  92. $store_names = explode(',', $store_names);
  93. $ViolationProductModel = $ViolationProductModel->whereIn('store_name', $store_names);
  94. }
  95. //多选违规挂网次数查询
  96. if ($online_posting_count && is_string($online_posting_count)) {
  97. $online_posting_count = explode(',', $online_posting_count);
  98. $ViolationProductModel = $ViolationProductModel->whereIn('online_posting_count', $online_posting_count);
  99. }
  100. //多选规格查询
  101. if ($product_specs && is_string($product_specs)) {
  102. $product_specs = explode(',', $product_specs);
  103. $ViolationProductModel = $ViolationProductModel->whereIn('product_specs', $product_specs);
  104. }
  105. //多选商品查询
  106. if ($product_names && is_string($product_names)) {
  107. $product_names = explode(',', $product_names);
  108. $ViolationProductModel = $ViolationProductModel->whereIn('product_name', $product_names);
  109. }
  110. //多选公司查询
  111. if ($company_names && is_string($company_names)) {
  112. $company_names = explode(',', $company_names);
  113. $ViolationProductModel = $ViolationProductModel->whereIn('company_name', $company_names);
  114. }
  115. //多选第一责任人
  116. if ($first_responsible_person && is_string($first_responsible_person)) {
  117. $first_responsible_person = explode(',', $first_responsible_person);
  118. $subQuery = $ViolationProductMemberModel->whereIn('employee_id', $first_responsible_person)->distinct('violation_product_logid')->select('violation_product_logid');
  119. $ViolationProductModel = $ViolationProductModel->whereIn('id', function ($query1) use ($subQuery) {
  120. $query1->select('violation_product_logid')->fromSub($subQuery, 'sub1');
  121. });
  122. }
  123. //多选责任人
  124. if ($responsible_person && is_string($responsible_person)) {
  125. $responsible_person = explode(',', $responsible_person);
  126. $subQuery = $ViolationProductMemberModel->whereIn('employee_id', $responsible_person)->distinct('violation_product_logid')->select('violation_product_logid');
  127. $ViolationProductModel = $ViolationProductModel->whereIn('id', function ($query1) use ($subQuery) {
  128. $query1->select('violation_product_logid')->fromSub($subQuery, 'sub1');
  129. });
  130. }
  131. //多选溯源责任人
  132. if ($source_responsible_person && is_string($source_responsible_person)) {
  133. $source_responsible_person = explode(',', $source_responsible_person);
  134. $subQuery = $ViolationProductMemberModel->whereIn('employee_id', $source_responsible_person)->distinct('violation_product_logid')->select('violation_product_logid');
  135. $ViolationProductModel = $ViolationProductModel->whereIn('id', function ($query1) use ($subQuery) {
  136. $query1->select('violation_product_logid')->fromSub($subQuery, 'sub1');
  137. });
  138. }
  139. if ($is_admin != 1 && $company_id != 0) {
  140. $result = $ViolationProductModel->where(function ($q) use ($user_id) {
  141. $q->where('first_responsible_person', 'like', "%,$user_id,%")
  142. ->orWhere('responsible_person', 'like', "%,$user_id,%")
  143. ->orWhere('source_responsible_person', 'like', "%,$user_id,%");
  144. })
  145. ->where($map)
  146. ->orderByDesc('id')
  147. ->paginate($limit)->toarray();
  148. } else {
  149. $result = $ViolationProductModel
  150. ->where($map)
  151. ->orderByDesc('id')
  152. ->paginate($limit)->toarray();
  153. }
  154. // 分配数据
  155. if (!$result) json_send(['code' => 'success', 'msg' => '获取成功', 'data' => []]);
  156. if (isset($result['data']) && count($result['data']) > 0) {
  157. foreach ($result['data'] as $key => $value) {
  158. //查询第一责任人名称
  159. $first_responsible_person = explode(',', $value['first_responsible_person']);
  160. $first_responsible_person_name = $EmployeeModel->whereIn('id', $first_responsible_person)->pluck('name')->toarray();
  161. $result['data'][$key]['first_responsible_person_name'] = $first_responsible_person_name;
  162. //查询责任人名称
  163. $responsible_person = explode(',', $value['responsible_person']);
  164. $responsible_person_name = $EmployeeModel->whereIn('id', $responsible_person)->pluck('name')->toarray();
  165. $result['data'][$key]['responsible_person_name'] = $responsible_person_name;
  166. //查询来源责任人名称
  167. $source_responsible_person = explode(',', $value['source_responsible_person']);
  168. $source_responsible_person_name = $EmployeeModel->whereIn('id', $source_responsible_person)->pluck('name')->toarray();
  169. $result['data'][$key]['source_responsible_person_name'] = $source_responsible_person_name;
  170. }
  171. }
  172. // 加载模板
  173. return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => $result]);
  174. }
  175. /**
  176. * 列表导出
  177. * @author 唐远望
  178. * @version 1.0
  179. * @date 2025-06-17
  180. */
  181. public function export_excel(Request $request, ViolationProductModel $ViolationProductModel, EmployeeModel $EmployeeModel, ViolationProductMemberModel $ViolationProductMemberModel)
  182. {
  183. $request->scene('export_excel')->validate();
  184. $admin_company_id = request('admin_company_id', '0');
  185. $company_id = request('access_token.company_id', '0');
  186. $is_admin = request('access_token.is_admin', '0'); //是否管理员操作 0=是1=否
  187. $user_id = request('access_token.uid', 0);
  188. // 查询条件
  189. $map = [];
  190. $limit = request('limit', config('page_num', 10));
  191. $status = request('status', '');
  192. $start_time = request('start_time', '');
  193. $end_time = request('end_time', '');
  194. $product_name = request('product_name', '');
  195. $product_names = request('product_names', '');
  196. $first_responsible_person = request('first_responsible_person', '');
  197. $responsible_person = request('responsible_person', '');
  198. $platform = request('platform', '');
  199. $company_name = request('company_name', '');
  200. $store_name = request('store_name', '');
  201. $store_names = request('store_names', '');
  202. $source_responsible_person = request('source_responsible_person', '');
  203. $processing_status = request('processing_status', '');
  204. $product_specs = request('product_specs', '');
  205. $online_posting_count = request('online_posting_count', '');
  206. $category_name = request('category_name', '');
  207. // 时间条件
  208. if ($start_time) $map[] = ['insert_time', '>=', strtotime($start_time)];
  209. if ($end_time) $map[] = ['insert_time', '<=', strtotime($end_time)];
  210. // 其他条件
  211. if ($product_name) $map[] = ['product_name', 'like', "%$product_name%"];
  212. if ($store_name) $map[] = ['store_name', 'like', "%$store_name%"];
  213. if ($category_name) $map[] = ['category_name', 'like', "%$category_name%"];
  214. $violation_product_where = [];
  215. // 权限判断
  216. if ($is_admin != 1 && $company_id != 0) {
  217. $violation_product_where['company_id'] = $company_id;
  218. } else {
  219. $violation_product_where['company_id'] = $admin_company_id;
  220. }
  221. $ViolationProductModel = $ViolationProductModel->where($violation_product_where);
  222. //多选平台查询
  223. if ($platform && is_string($platform)) {
  224. $platform = explode(',', $platform);
  225. $ViolationProductModel = $ViolationProductModel->whereIn('platform', $platform);
  226. }
  227. //多选处理状态查询
  228. if ($processing_status && is_string($processing_status)) {
  229. $processing_status = explode(',', $processing_status);
  230. $ViolationProductModel = $ViolationProductModel->whereIn('processing_status', $processing_status);
  231. }
  232. //多选状态查询
  233. if ($status && is_string($status)) {
  234. $status = explode(',', $status);
  235. $ViolationProductModel = $ViolationProductModel->whereIn('status', $status);
  236. }
  237. //多选店铺名称查询
  238. if ($store_names && is_string($store_names)) {
  239. $store_names = explode(',', $store_names);
  240. $ViolationProductModel = $ViolationProductModel->whereIn('store_name', $store_names);
  241. }
  242. //多选违规挂网次数查询
  243. if ($online_posting_count && is_string($online_posting_count)) {
  244. $online_posting_count = explode(',', $online_posting_count);
  245. $ViolationProductModel = $ViolationProductModel->whereIn('online_posting_count', $online_posting_count);
  246. }
  247. //多选规格查询
  248. if ($product_specs && is_string($product_specs)) {
  249. $product_specs = explode(',', $product_specs);
  250. $ViolationProductModel = $ViolationProductModel->whereIn('product_specs', $product_specs);
  251. }
  252. //多选商品查询
  253. if ($product_names && is_string($product_names)) {
  254. $product_names = explode(',', $product_names);
  255. $ViolationProductModel = $ViolationProductModel->whereIn('product_name', $product_names);
  256. }
  257. //多选公司查询
  258. if ($company_name && is_string($company_name)) {
  259. $company_name = explode(',', $company_name);
  260. $ViolationProductModel = $ViolationProductModel->whereIn('company_name', $company_name);
  261. }
  262. //多选第一责任人
  263. if ($first_responsible_person && is_string($first_responsible_person)) {
  264. $first_responsible_person = explode(',', $first_responsible_person);
  265. $subQuery = $ViolationProductMemberModel->whereIn('employee_id', $first_responsible_person)->distinct('violation_product_logid')->select('violation_product_logid');
  266. $ViolationProductModel = $ViolationProductModel->whereIn('id', function ($query1) use ($subQuery) {
  267. $query1->select('violation_product_logid')->fromSub($subQuery, 'sub1');
  268. });
  269. }
  270. //多选责任人
  271. if ($responsible_person && is_string($responsible_person)) {
  272. $responsible_person = explode(',', $responsible_person);
  273. $subQuery = $ViolationProductMemberModel->whereIn('employee_id', $responsible_person)->distinct('violation_product_logid')->select('violation_product_logid');
  274. $ViolationProductModel = $ViolationProductModel->whereIn('id', function ($query1) use ($subQuery) {
  275. $query1->select('violation_product_logid')->fromSub($subQuery, 'sub1');
  276. });
  277. }
  278. //多选溯源责任人
  279. if ($source_responsible_person && is_string($source_responsible_person)) {
  280. $source_responsible_person = explode(',', $source_responsible_person);
  281. $subQuery = $ViolationProductMemberModel->whereIn('employee_id', $source_responsible_person)->distinct('violation_product_logid')->select('violation_product_logid');
  282. $ViolationProductModel = $ViolationProductModel->whereIn('id', function ($query1) use ($subQuery) {
  283. $query1->select('violation_product_logid')->fromSub($subQuery, 'sub1');
  284. });
  285. }
  286. if ($is_admin != 1 && $company_id != 0) {
  287. $result_totle = $ViolationProductModel->where(function ($q) use ($user_id) {
  288. $q->where('first_responsible_person', 'like', "%,$user_id,%")
  289. ->orWhere('responsible_person', 'like', "%,$user_id,%")
  290. ->orWhere('source_responsible_person', 'like', "%,$user_id,%");
  291. })
  292. ->where($map)
  293. ->orderByDesc('id')
  294. ->count();
  295. } else {
  296. $result_totle = $ViolationProductModel->where($map)
  297. ->orderByDesc('id')
  298. ->count();
  299. }
  300. // 数量过多时,限制导出
  301. if ($result_totle > 10000) {
  302. return json_send(['code' => 'error', 'msg' => '导出数据过多,请缩小查询条件']);
  303. }
  304. if ($is_admin != 1 && $company_id != 0) {
  305. $result = $ViolationProductModel->where(function ($q) use ($user_id) {
  306. $q->where('first_responsible_person', 'like', "%,$user_id,%")
  307. ->orWhere('responsible_person', 'like', "%,$user_id,%")
  308. ->orWhere('source_responsible_person', 'like', "%,$user_id,%");
  309. })
  310. ->where($map)
  311. ->orderByDesc('id')
  312. ->get()->toarray();
  313. } else {
  314. $result = $ViolationProductModel->where($map)
  315. ->orderByDesc('id')
  316. ->get()->toarray();
  317. }
  318. // 分配数据
  319. if (!$result) return json_send(['code' => 'error', 'msg' => '暂无数据']);
  320. // 处理责任人展示信息
  321. $list_data = $this->processing_responsible_person($result);
  322. // 导出数据
  323. $this->export_download($list_data);
  324. }
  325. /**
  326. * 处理责任人展示信息
  327. * @author 唐远望
  328. * @version 1.0
  329. * @date 2025-12-17
  330. */
  331. public function processing_responsible_person($result)
  332. {
  333. $EmployeeModel = new EmployeeModel();
  334. //获取所有员工
  335. $employeee_data = $EmployeeModel->select(['id', 'name'])->get()->toarray();
  336. $employeee_list = [];
  337. if (!empty($employeee_data)) {
  338. foreach ($employeee_data as $key => $value) {
  339. $employeee_list[$value['id']] = $value['name'];
  340. }
  341. }
  342. if (isset($result) && count($result) > 0) {
  343. foreach ($result as $key => $value) {
  344. //查询第一责任人名称
  345. $first_responsible_person = $value['first_responsible_person'] != '' ? explode(',', $value['first_responsible_person']) : [];
  346. $first_responsible_person_name = [];
  347. if (!empty($first_responsible_person)) {
  348. foreach ($first_responsible_person as $k => $v) {
  349. if (isset($employeee_list[$v])) {
  350. $first_responsible_person_name[] = $employeee_list[$v];
  351. }
  352. }
  353. }
  354. $result[$key]['first_responsible_person_name'] = $first_responsible_person_name;
  355. //查询责任人名称
  356. $responsible_person = $value['responsible_person'] != '' ? explode(',', $value['responsible_person']) : [];
  357. $responsible_person_name = [];
  358. if (!empty($responsible_person)) {
  359. foreach ($responsible_person as $k => $v) {
  360. if (isset($employeee_list[$v])) {
  361. $responsible_person_name[] = $employeee_list[$v];
  362. }
  363. }
  364. }
  365. $result[$key]['responsible_person_name'] = $responsible_person_name;
  366. //查询来源责任人名称
  367. $source_responsible_person = $value['source_responsible_person'] != '' ? explode(',', $value['source_responsible_person']) : [];
  368. $source_responsible_person_name = [];
  369. if (!empty($source_responsible_person)) {
  370. foreach ($source_responsible_person as $k => $v) {
  371. if (isset($employeee_list[$v])) {
  372. $source_responsible_person_name[] = $employeee_list[$v];
  373. }
  374. }
  375. }
  376. $result[$key]['source_responsible_person_name'] = $source_responsible_person_name;
  377. }
  378. }
  379. return $result;
  380. }
  381. /**
  382. * 导出下载
  383. * @author 唐远望
  384. * @version 1.0
  385. * @date 2025-06-17
  386. */
  387. public function export_download($data)
  388. {
  389. // 创建一个新的 Spreadsheet 对象
  390. $spreadsheet = new Spreadsheet();
  391. $sheet = $spreadsheet->getActiveSheet();
  392. //合并单元格
  393. $sheet->mergeCells('A1:Q1');
  394. $sheet->setCellValue('A1', '禁止挂网商品导出(导出时间:' . date('Y-m-d H:i:s', time()) . ')'); // 设置合并后的单元格内容
  395. // 获取合并后的单元格样式对象
  396. $style = $sheet->getStyle('A1');
  397. // 设置水平居中和垂直居中
  398. $style->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER)->setVertical(Alignment::VERTICAL_CENTER);
  399. // 然后设置行高以适应两行文本
  400. $sheet->getRowDimension(1)->setRowHeight(40); // 设置行高,单位是磅(point)
  401. // 设置表头
  402. $sheet->setCellValue('A2', '第一责任人');
  403. $sheet->setCellValue('B2', '责任人');
  404. $sheet->setCellValue('C2', '平台');
  405. $sheet->setCellValue('D2', '商品分类');
  406. $sheet->setCellValue('E2', '商品名称');
  407. $sheet->setCellValue('F2', '库存');
  408. $sheet->setCellValue('G2', '销量');
  409. $sheet->setCellValue('H2', '快照URL');
  410. $sheet->setCellValue('I2', '商品规格');
  411. $sheet->setCellValue('J2', '累计挂网次数');
  412. $sheet->setCellValue('K2', '连续挂网次数');
  413. $sheet->setCellValue('L2', '链接地址');
  414. $sheet->setCellValue('M2', '店铺名称');
  415. $sheet->setCellValue('N2', '公司名称');
  416. $sheet->setCellValue('O2', '公司分类');
  417. $sheet->setCellValue('P2', '信用代码');
  418. $sheet->setCellValue('Q2', '省份');
  419. $sheet->setCellValue('R2', '城市');
  420. $sheet->setCellValue('S2', '溯源责任人');
  421. $sheet->setCellValue('T2', '处理状态');
  422. $sheet->setCellValue('U2', '任务状态');
  423. $sheet->setCellValue('V2', '记录时间');
  424. $platform_data = [
  425. '0' => '全部',
  426. '1' => '淘宝',
  427. '2' => '京东',
  428. '3' => '拼多多',
  429. '4' => '美团',
  430. '5' => '药师帮',
  431. '6' => '1药城',
  432. '7' => '药久久',
  433. ];
  434. $processing_status_text = [
  435. '1' => '待处理',
  436. ];
  437. $status_text = [
  438. '0' => '有效',
  439. '1' => '无效',
  440. ];
  441. // 填充数据
  442. $row = 3; // 从第2行开始
  443. foreach ($data as $item) {
  444. $first_responsible_person_name = !empty($item['first_responsible_person_name']) ? implode(',', $item['first_responsible_person_name']) : '';
  445. $responsible_person_name = !empty($item['responsible_person_name']) ? implode(',', $item['responsible_person_name']) : '';
  446. $source_responsible_person_name = !empty($item['source_responsible_person_name']) ? implode(',', $item['source_responsible_person_name']) : '';
  447. $sheet->setCellValue('A' . $row, $first_responsible_person_name);
  448. $sheet->setCellValue('B' . $row, $responsible_person_name);
  449. $sheet->setCellValue('C' . $row, isset($platform_data[$item['platform']]) ? $platform_data[$item['platform']] : '');
  450. $sheet->setCellValue('D' . $row, $item['category_name']);
  451. $sheet->setCellValue('E' . $row, $item['product_name']);
  452. $sheet->setCellValue('F' . $row, $item['inventory']);
  453. $sheet->setCellValue('G' . $row, $item['sales']);
  454. $sheet->setCellValue('H' . $row, $item['snapshot_url']);
  455. $sheet->setCellValue('I' . $row, $item['product_specs']);
  456. $sheet->setCellValue('J' . $row, $item['online_posting_count']);
  457. $sheet->setCellValue('K' . $row, $item['continuous_listing_count']);
  458. $sheet->setCellValue('L' . $row, $item['link_url']);
  459. $sheet->setCellValue('M' . $row, $item['store_name']);
  460. $sheet->setCellValue('N' . $row, $item['company_name']);
  461. $sheet->setCellValue('O' . $row, $item['company_category_name']);
  462. $sheet->setCellValue('P' . $row, $item['social_credit_code']);
  463. $sheet->setCellValue('Q' . $row, $item['province_name']);
  464. $sheet->setCellValue('R' . $row, $item['city_name']);
  465. $sheet->setCellValue('S' . $row, $source_responsible_person_name);
  466. $sheet->setCellValue('T' . $row, isset($processing_status_text[$item['processing_status']]) ? $processing_status_text[$item['processing_status']] : '');
  467. $sheet->setCellValue('U' . $row, isset($status_text[$item['status']]) ? $status_text[$item['status']] : '');
  468. $sheet->setCellValue('V' . $row, date('Y-m-d H:i:s', $item['insert_time']));
  469. $row++;
  470. }
  471. foreach (range('A', 'P') as $column) {
  472. $sheet->getColumnDimension($column)->setAutoSize(true);
  473. }
  474. // 生成 Excel 文件
  475. $writer = new Xlsx($spreadsheet);
  476. // 直接输出到浏览器(下载)
  477. $filename = '禁止挂网商品数据' . date('YmdHis') . '.xlsx';
  478. header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
  479. header('Content-Disposition: attachment;filename="' . $filename . '"');
  480. header('Cache-Control: max-age=0');
  481. $writer->save('php://output');
  482. exit;
  483. }
  484. /**
  485. * 详情
  486. * @author 唐远望
  487. * @version 1.0
  488. * @date 2025-12-08
  489. */
  490. public function detail(Request $request, ViolationProductModel $ViolationProductModel, EmployeeModel $EmployeeModel)
  491. {
  492. $request->scene('detail')->validate();
  493. $admin_company_id = request('admin_company_id', '0');
  494. $company_id = request('access_token.company_id', '0');
  495. $is_admin = request('access_token.is_admin', '0'); //是否管理员操作 0=是1=否
  496. // 接收参数
  497. $id = request('id', 0);
  498. $map = ['id' => $id];
  499. // 权限判断
  500. if ($is_admin != 1 && $company_id != 0) {
  501. $map['company_id'] = $company_id;
  502. } else {
  503. $map['company_id'] = $admin_company_id;
  504. }
  505. $data = $ViolationProductModel->where($map)->first();
  506. if (!$data) return json_send(['code' => 'error', 'msg' => '记录不存在']);
  507. //查询第一责任人名称
  508. $first_responsible_person = explode(',', $data->first_responsible_person);
  509. $first_responsible_person_name = $EmployeeModel->whereIn('id', $first_responsible_person)->pluck('name')->toarray();
  510. $data->first_responsible_person_name = $first_responsible_person_name;
  511. //查询责任人名称
  512. $responsible_person = explode(',', $data->responsible_person);
  513. $responsible_person_name = $EmployeeModel->whereIn('id', $responsible_person)->pluck('name')->toarray();
  514. $data->responsible_person_name = $responsible_person_name;
  515. //查询来源责任人名称
  516. $source_responsible_person = explode(',', $data->source_responsible_person);
  517. $source_responsible_person_name = $EmployeeModel->whereIn('id', $source_responsible_person)->pluck('name')->toarray();
  518. $data->source_responsible_person_name = $source_responsible_person_name;
  519. // 加载模板
  520. return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => $data]);
  521. }
  522. /**
  523. * 添加
  524. * @author 唐远望
  525. * @version 1.0
  526. * @date 2025-12-08
  527. *
  528. */
  529. public function add(Request $request, ViolationProductModel $ViolationProductModel)
  530. {
  531. $request->scene('add')->validate();
  532. $admin_company_id = request('admin_company_id', '0');
  533. $company_id = request('access_token.company_id', '0');
  534. $is_admin = request('access_token.is_admin', '0'); //是否管理员操作 0=是1=否
  535. // 接收数据
  536. $all_data = request()->all();
  537. $store_scope = request('store_scope', '');
  538. $all_data['store_scope'] = $store_scope;
  539. //查询是否存在
  540. $map = ['product_name' => $all_data['product_name'], 'product_specs' => $all_data['product_specs']];
  541. // 权限判断
  542. if ($is_admin != 1 && $company_id != 0) {
  543. $map['company_id'] = $company_id;
  544. $all_data['company_id'] = $company_id;
  545. } else {
  546. $map['company_id'] = $admin_company_id;
  547. $all_data['company_id'] = $admin_company_id;
  548. }
  549. $data = $ViolationProductModel->where($map)->first();
  550. if ($data) return json_send(['code' => 'error', 'msg' => '记录已存在']);
  551. // 写入数据表
  552. $result = $ViolationProductModel->addLowPriceGoods($all_data);
  553. // 如果操作失败
  554. if (!$result) return json_send(['code' => 'error', 'msg' => '新增失败']);
  555. // 告知结果
  556. return json_send(['code' => 'success', 'msg' => '新增成功']);
  557. }
  558. /**
  559. * 修改
  560. * @author 唐远望
  561. * @version 1.0
  562. * @date 2025-12-08
  563. *
  564. */
  565. public function edit(Request $request, ViolationProductModel $ViolationProductModel)
  566. {
  567. $request->scene('edit')->validate();
  568. $admin_company_id = request('admin_company_id', '0');
  569. $company_id = request('access_token.company_id', '0');
  570. $is_admin = request('access_token.is_admin', '0'); //是否管理员操作 0=是1=否
  571. // 接收参数
  572. $id = request('id', 0);
  573. // 接收数据
  574. $all_data = request()->all();
  575. $store_scope = request('store_scope', '');
  576. $all_data['store_scope'] = $store_scope;
  577. //查询是否存在
  578. $map = ['product_name' => $all_data['product_name'], 'product_specs' => $all_data['product_specs']];
  579. // 权限判断
  580. if ($is_admin != 1 && $company_id != 0) {
  581. $map['company_id'] = $company_id;
  582. $all_data['company_id'] = $company_id;
  583. } else {
  584. $map['company_id'] = $admin_company_id;
  585. $all_data['company_id'] = $admin_company_id;
  586. }
  587. $data = $ViolationProductModel->where($map)->where('id', '!=', $id)->first();
  588. if ($data) return json_send(['code' => 'error', 'msg' => '记录已存在']);
  589. // 更新数据表
  590. $where = ['id' => $id];
  591. $result = $ViolationProductModel->updateLowPriceGoods($where, $all_data);
  592. // 如果操作失败
  593. if (!$result) return json_send(['code' => 'error', 'msg' => '修改失败']);
  594. // 告知结果
  595. return json_send(['code' => 'success', 'msg' => '修改成功']);
  596. }
  597. /**
  598. * 修改状态
  599. * @author 唐远望
  600. * @version 1.0
  601. * @date 2025-12-08
  602. *
  603. */
  604. public function set_status(Request $request, ViolationProductModel $ViolationProductModel)
  605. {
  606. // 验证参数
  607. $request->scene('set_status')->validate();
  608. $admin_company_id = request('admin_company_id', '0');
  609. $company_id = request('access_token.company_id', '0');
  610. $is_admin = request('access_token.is_admin', '0'); //是否管理员操作 0=是1=否
  611. // 接收数据
  612. $id = request('id', 0);
  613. $status = request('status', 0);
  614. // 查询用户
  615. $where = ['id' => $id];
  616. // 权限判断
  617. if ($is_admin != 1 && $company_id != 0) {
  618. $where['company_id'] = $company_id;
  619. } else {
  620. $where['company_id'] = $admin_company_id;
  621. }
  622. $ViolationProduct = $ViolationProductModel->where($where)->first();
  623. if (!$ViolationProduct) return json_send(['code' => 'error', 'msg' => '记录不存在']);
  624. $ViolationProduct->status = $status;
  625. $ViolationProduct->update_time = time();
  626. // 执行修改
  627. $result = $ViolationProduct->save();
  628. // 提示新增失败
  629. if (!$result) return json_send(['code' => 'error', 'msg' => '设置失败']);
  630. // 告知结果
  631. return json_send(['code' => 'success', 'msg' => '设置成功']);
  632. }
  633. /**
  634. * 修改处理状态
  635. * @author 唐远望
  636. * @version 1.0
  637. * @date 2025-12-08
  638. *
  639. */
  640. public function set_processing_status(Request $request, ViolationProductModel $ViolationProductModel)
  641. {
  642. // 验证参数
  643. $request->scene('set_processing_status')->validate();
  644. $admin_company_id = request('admin_company_id', '0');
  645. $company_id = request('access_token.company_id', '0');
  646. $is_admin = request('access_token.is_admin', '0'); //是否管理员操作 0=是1=否
  647. // 接收数据
  648. $id = request('id', 0);
  649. $processing_status = request('processing_status', 0);
  650. // 查询用户
  651. $where = ['id' => $id];
  652. // 权限判断
  653. if ($is_admin != 1 && $company_id != 0) {
  654. $where['company_id'] = $company_id;
  655. } else {
  656. $where['company_id'] = $admin_company_id;
  657. }
  658. $ViolationProduct = $ViolationProductModel->where($where)->first();
  659. if (!$ViolationProduct) return json_send(['code' => 'error', 'msg' => '记录不存在']);
  660. $ViolationProduct->processing_status = $processing_status;
  661. $ViolationProduct->update_time = time();
  662. // 执行修改
  663. $result = $ViolationProduct->save();
  664. // 提示新增失败
  665. if (!$result) return json_send(['code' => 'error', 'msg' => '设置失败']);
  666. // 告知结果
  667. return json_send(['code' => 'success', 'msg' => '设置成功']);
  668. }
  669. /**
  670. * 删除
  671. * @author 唐远望
  672. * @version 1.0
  673. * @date 2025-12-08
  674. *
  675. */
  676. public function delete(Request $request, ViolationProductModel $ViolationProductModel)
  677. {
  678. // 验证参数
  679. $request->scene('delete')->validate();
  680. $admin_company_id = request('admin_company_id', '0');
  681. $company_id = request('access_token.company_id', '0');
  682. $is_admin = request('access_token.is_admin', '0'); //是否管理员操作 0=是1=否
  683. // 接收数据
  684. $id = request('id', 0);
  685. // 查询用户
  686. $where = ['id' => $id];
  687. // 权限判断
  688. if ($is_admin != 1 && $company_id != 0) {
  689. $where['company_id'] = $company_id;
  690. } else {
  691. $where['company_id'] = $admin_company_id;
  692. }
  693. $ViolationProduct = $ViolationProductModel->where($where)->first();
  694. if (!$ViolationProduct) return json_send(['code' => 'error', 'msg' => '记录不存在']);
  695. // 执行删除
  696. $result = $ViolationProduct->delete();
  697. // 提示删除失败
  698. if (!$result) return json_send(['code' => 'error', 'msg' => '删除失败']);
  699. // 告知结果
  700. return json_send(['code' => 'success', 'msg' => '删除成功']);
  701. }
  702. /**
  703. * 执行数据清洗
  704. * @author 唐远望
  705. * @version 1.0
  706. * @date 2025-12-11
  707. *
  708. */
  709. public function data_cleaning(Request $request)
  710. {
  711. // 验证参数
  712. $request->scene('data_cleaning')->validate();
  713. $admin_company_id = request('admin_company_id', '0');
  714. $company_id = request('access_token.company_id', '0');
  715. $is_admin = request('access_token.is_admin', '0'); //是否管理员操作 0=是1=否
  716. $admin_id = request('access_token.uid', 0); //用户ID
  717. // 权限判断
  718. if ($is_admin != 1 && $company_id != 0) {
  719. } else {
  720. $company_id = $admin_company_id;
  721. }
  722. $message_data = ['page' => '1', 'limit' => 50, 'admin_id' => $admin_id, 'is_admin' => $is_admin, 'company_id' => $company_id];
  723. ViolationProductJobs::dispatch($message_data);
  724. // ViolationProductJobs::dispatchSync($message_data);
  725. // 告知结果
  726. return json_send(['code' => 'success', 'msg' => '执行成功']);
  727. }
  728. /**
  729. * 下载导入模板
  730. * @author 唐远望
  731. * @version 1.0
  732. * @date 2025-12-31
  733. *
  734. */
  735. public function download_template()
  736. {
  737. // 创建一个新的 Spreadsheet 对象
  738. $spreadsheet = new Spreadsheet();
  739. $sheet = $spreadsheet->getActiveSheet();
  740. //合并单元格
  741. $sheet->mergeCells('A1:P1');
  742. $sheet->setCellValue('A1', '禁止挂网商品导入模板'); // 设置合并后的单元格内容
  743. // 获取合并后的单元格样式对象
  744. $style = $sheet->getStyle('A1');
  745. // 设置水平居中和垂直居中
  746. $style->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER)->setVertical(Alignment::VERTICAL_CENTER);
  747. // 然后设置行高以适应两行文本
  748. $sheet->getRowDimension(1)->setRowHeight(40); // 设置行高,单位是磅(point)
  749. // 设置表头
  750. $sheet->setCellValue('A2', '第一责任人名称');
  751. $sheet->setCellValue('B2', '责任人名称');
  752. $sheet->setCellValue('C2', '平台名称*');
  753. $sheet->setCellValue('D2', '商品分类名称');
  754. $sheet->setCellValue('E2', '商品名称*');
  755. $sheet->setCellValue('F2', '商品规格*');
  756. $sheet->setCellValue('G2', '累计挂网次数');
  757. $sheet->setCellValue('H2', '连续挂网次数');
  758. $sheet->setCellValue('I2', '销量');
  759. $sheet->setCellValue('J2', '库存');
  760. $sheet->setCellValue('K2', '快照URL');
  761. $sheet->setCellValue('L2', '链接地址*');
  762. $sheet->setCellValue('M2', '店铺名称*');
  763. $sheet->setCellValue('N2', '公司名称*');
  764. $sheet->setCellValue('O2', '公司分类名称');
  765. $sheet->setCellValue('P2', '信用代码*');
  766. $sheet->setCellValue('Q2', '省份*');
  767. $sheet->setCellValue('R2', '城市*');
  768. $sheet->setCellValue('S2', '溯源责任人');
  769. // 生成 Excel 文件
  770. $writer = new Xlsx($spreadsheet);
  771. // 直接输出到浏览器(下载)
  772. $filename = '禁止挂网商品导入模板.xlsx';
  773. header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
  774. header('Content-Disposition: attachment;filename="' . $filename . '"');
  775. header('Cache-Control: max-age=0');
  776. $writer->save('php://output');
  777. exit;
  778. }
  779. /**
  780. * 导入Excel数据
  781. * @author 唐远望
  782. * @version 1.0
  783. * @date 2025-12-31
  784. *
  785. */
  786. public function import_data(Request $request, ViolationProductModel $ViolationProductModel, EmployeeModel $EmployeeModel, CitysModel $CitysModel)
  787. {
  788. $request->scene('import_data')->validate();
  789. $admin_company_id = request('admin_company_id', '0');
  790. $company_id = request('access_token.company_id', '0');
  791. $is_admin = request('access_token.is_admin', '0'); //是否管理员操作 0=是1=否
  792. $file = $request->file('file');
  793. // 加载Excel文件
  794. $spreadsheet = IOFactory::load($file->getPathname());
  795. $sheet = $spreadsheet->getActiveSheet();
  796. // 获取所有数据
  797. $data = $sheet->toArray();
  798. if (empty($data) || count($data) < 2) return json_send(['code' => 'error', 'msg' => '导入数据为空']);
  799. $result = $EmployeeModel->select(['id', 'name'])->get()->keyBy('name')->toarray();
  800. $platform_data = $ViolationProductModel->platform_data();
  801. $province_id_data = $CitysModel->get_province_id_list();
  802. $city_id_data = $CitysModel->get_city_id_list();
  803. DB::beginTransaction();
  804. try {
  805. foreach ($data as $key => $item) {
  806. $key_num = $key + 1;
  807. if ($key < 2) continue;
  808. //强制必传参数校验
  809. $res_data = $this->import_data_check($key, $item);
  810. if ($res_data) return json_send($res_data);
  811. $first_responsible_person_id = [];
  812. $first_responsible_person_name = $item[0];
  813. if ($first_responsible_person_name) {
  814. $first_responsible_person_name = explode(',', $first_responsible_person_name);
  815. foreach ($first_responsible_person_name as $k => $v) {
  816. if (isset($result[$v])) {
  817. $first_responsible_person_id[] = $result[$v]['id'];
  818. }
  819. }
  820. }
  821. $responsible_person_id = [];
  822. $responsible_person_name = $item[1];
  823. if ($responsible_person_name) {
  824. $responsible_person_name = explode(',', $responsible_person_name);
  825. foreach ($responsible_person_name as $k => $v) {
  826. if (isset($result[$v])) {
  827. $responsible_person_id[] = $result[$v]['id'];
  828. }
  829. }
  830. }
  831. $source_responsible_person_id = [];
  832. $source_responsible_person_name = $item[18];
  833. if ($source_responsible_person_name) {
  834. $source_responsible_person_name = explode(',', $source_responsible_person_name);
  835. foreach ($source_responsible_person_name as $k => $v) {
  836. if (isset($result[$v])) {
  837. $source_responsible_person_id[] = $result[$v]['id'];
  838. }
  839. }
  840. }
  841. $province_name = $item[16];
  842. //特殊地区1级移除市
  843. if ($province_name && in_array($province_name, ['北京市', '天津市', '上海市', '重庆市'])) {
  844. //移除市这个字符
  845. $province_name = trim(str_replace('市', '', $province_name));
  846. }else if ($province_name && in_array($province_name, ['北京', '天津', '上海', '重庆'])) {
  847. } else if ($province_name && in_array($province_name, ['内蒙古', '广西', '西藏', '新疆', '宁夏'])) {
  848. switch ($province_name) {
  849. case '内蒙古':
  850. $province_name = '内蒙古自治区';
  851. break;
  852. case '广西':
  853. $province_name = '广西壮族自治区';
  854. break;
  855. case '西藏':
  856. $province_name = '西藏自治区';
  857. break;
  858. case '新疆':
  859. $province_name = '新疆维吾尔自治区';
  860. break;
  861. case '宁夏':
  862. $province_name = '宁夏回族自治区';
  863. break;
  864. }
  865. } else if ($province_name && in_array($province_name, ['内蒙古自治区', '广西壮族自治区', '西藏自治区', '新疆维吾尔自治区', '宁夏回族自治区'])) {
  866. } else if (strpos($province_name, '省') === false) {
  867. //是否存在市省,如果不存在则补全
  868. if (strpos($province_name, '省') === false) {
  869. $province_name = $province_name . '省';
  870. }
  871. }
  872. if (!isset($province_id_data[$province_name])) return json_send(['code' => 'error', 'msg' => "第{$key_num}行省份信息不完整", 'data' => $item]);
  873. $city_name = $item[14];
  874. if (!isset($city_id_data[$city_name])) return json_send(['code' => 'error', 'msg' => "第{$key_num}行城市信息不完整", 'data' => $item]);
  875. // 权限判断
  876. if ($is_admin != 1 && $company_id != 0) {
  877. $insert_product_data['company_id'] = $company_id;
  878. } else {
  879. $insert_product_data['company_id'] = $admin_company_id;
  880. }
  881. $insert_product_data['first_responsible_person'] = !empty($first_responsible_person_id) ? implode(',', $first_responsible_person_id) : ''; //第一责任人ID集合
  882. $insert_product_data['responsible_person'] = !empty($responsible_person_id) ? implode(',', $responsible_person_id) : ''; //责任人ID集合
  883. $insert_product_data['platform'] = isset($platform_data[$item[2]]) ? $platform_data[$item[2]] : '0'; // 平台
  884. $insert_product_data['category_name'] = $item[3] ? $item[4] : ''; // 商品分类
  885. $insert_product_data['product_name'] = $item[4]; // 商品名称
  886. $insert_product_data['product_specs'] = $item[5]; // 商品规格
  887. $insert_product_data['online_posting_count'] = isset($item[6]) ? $item[6] : 1; // 累计挂网次数
  888. $insert_product_data['continuous_listing_count'] = isset($item[7]) ? $item[7] : 1; // 连续挂网次数
  889. $insert_product_data['sales'] = isset($item[8]) ? $item[8] : 0; // 销量
  890. $insert_product_data['inventory'] = isset($item[9]) ? $item[9] : 0; // 库存
  891. $insert_product_data['snapshot_url'] = isset($item[10]) ? $item[10] : ''; // 快照URL
  892. $insert_product_data['link_url'] = $item[11]; // 链接地址
  893. $insert_product_data['store_name'] = $item[12]; // 店铺名称
  894. $insert_product_data['company_name'] = $item[13]; // 公司名称
  895. $insert_product_data['company_category_name'] = isset($item[14]) ? $item[14] : ''; // 公司分类
  896. $insert_product_data['social_credit_code'] = $item[15]; // 信用代码
  897. $insert_product_data['province_name'] = $item[16]; // 省份
  898. $insert_product_data['province_id'] = isset($province_id_data[$province_name]) ? $province_id_data[$province_name]['id'] : 0; // 省份ID
  899. $insert_product_data['city_name'] = $item[17]; // 城市
  900. $insert_product_data['city_id'] = isset($city_id_data[$city_name]) ? $city_id_data[$city_name]['id'] : 0; // 城市ID
  901. $insert_product_data['area_info'] = ''; // 详细地址
  902. $insert_product_data['source_responsible_person'] = !empty($source_responsible_person_id) ? implode(',', $source_responsible_person_id) : ''; //溯源责任人ID集合
  903. $insert_product_data['processing_status'] = 1; //处理状态1=待处理2=购买中3=已溯源4=回收凭据已上传5=已回收6=拒绝回收7=已下架8=无法处理
  904. $insert_product_data['status'] = 0; //状态0=有效=无效
  905. $insert_product_data['insert_time'] = time();
  906. $insert_product_data['source_id'] = 0; // 原始数据ID
  907. //插入数据
  908. $ViolationProductModel->addViolationProduct($insert_product_data, true);
  909. }
  910. DB::commit();
  911. return json_send(['code' => 'success', 'msg' => '导入成功']);
  912. // 成功处理...
  913. } catch (\Exception $e) {
  914. DB::rollBack();
  915. // 错误处理...
  916. return json_send(['code' => 'error', 'msg' => '导入失败', 'data' => $e->getMessage()]);
  917. }
  918. }
  919. /**
  920. * 导入Excel数据必传参数校验
  921. * @author 唐远望
  922. * @version 1.0
  923. * @date 2025-12-31
  924. *
  925. */
  926. private function import_data_check($key, $item)
  927. {
  928. $key = $key + 1;
  929. if (!$item[2]) {
  930. return ['code' => 'error', 'msg' => "第{$key}行平台不能为空", 'data' => $item];
  931. }
  932. if (!$item[4]) {
  933. return ['code' => 'error', 'msg' => "第{$key}行商品名称不能为空", 'data' => $item];
  934. }
  935. if (!$item[5]) {
  936. return ['code' => 'error', 'msg' => "第{$key}行商品规格不能为空", 'data' => $item];
  937. }
  938. if (!$item[11]) {
  939. return ['code' => 'error', 'msg' => "第{$key}行链接地址不能为空", 'data' => $item];
  940. }
  941. if (!$item[12]) {
  942. return ['code' => 'error', 'msg' => "第{$key}行店铺名称不能为空", 'data' => $item];
  943. }
  944. if (!$item[13]) {
  945. return ['code' => 'error', 'msg' => "第{$key}行公司名称不能为空", 'data' => $item];
  946. }
  947. if (!$item[15]) {
  948. return ['code' => 'error', 'msg' => "第{$key}行信用代码不能为空", 'data' => $item];
  949. }
  950. if (!$item[16]) {
  951. return ['code' => 'error', 'msg' => "第{$key}行省份不能为空", 'data' => $item];
  952. }
  953. if (!$item[17]) {
  954. return ['code' => 'error', 'msg' => "第{$key}行城市不能为空", 'data' => $item];
  955. }
  956. }
  957. }