ViolationProduct.php 49 KB

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