ViolationProduct.php 50 KB

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