ViolationProduct.php 50 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989
  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'];
  256. $company_id = $message_data['company_id'];
  257. $is_admin = $message_data['is_admin']; //是否管理员操作 0=是1=否
  258. $user_id = $message_data['user_id'];
  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. $key_name = 'ExportViolationProductJobs_' . $violation_product_where['company_id'];
  397. //创建缓存
  398. Cache::put($key_name, [], 60 * 60 * 24);
  399. // 生成唯一文件ID
  400. $fileId = make_snow_flake();
  401. $message_data['file_id'] = $fileId;
  402. $fileName = '禁止挂网商品数据' . $fileId . '.xlsx';
  403. $message_data['company_id'] = $violation_product_where['company_id'];
  404. $message_data['user_id'] = $message_data['user_id'];
  405. ExportViolationProductJobs::dispatch($message_data);
  406. // ExportViolationProductJobs::dispatchSync($message_data);
  407. return json_send(['code' => 'success', 'msg' => '导出任务添加成功', 'data' => ['file_id' => $fileId, 'file_name' => $fileName]]);
  408. }
  409. /**
  410. * 详情
  411. * @author 唐远望
  412. * @version 1.0
  413. * @date 2025-12-08
  414. */
  415. public function detail(Request $request, ViolationProductModel $ViolationProductModel, EmployeeModel $EmployeeModel)
  416. {
  417. $request->scene('detail')->validate();
  418. $admin_company_id = request('admin_company_id', '0');
  419. $company_id = request('access_token.company_id', '0');
  420. $is_admin = request('access_token.is_admin', '0'); //是否管理员操作 0=是1=否
  421. // 接收参数
  422. $id = request('id', 0);
  423. $map = ['id' => $id];
  424. // 权限判断
  425. if ($is_admin != 1 && $company_id != 0) {
  426. $map['company_id'] = $company_id;
  427. } else {
  428. $map['company_id'] = $admin_company_id;
  429. }
  430. $data = $ViolationProductModel->where($map)->first();
  431. if (!$data) return json_send(['code' => 'error', 'msg' => '记录不存在']);
  432. //查询第一责任人名称
  433. $first_responsible_person = explode(',', $data->first_responsible_person);
  434. $first_responsible_person_name = $EmployeeModel->whereIn('id', $first_responsible_person)->pluck('name')->toarray();
  435. $data->first_responsible_person_name = $first_responsible_person_name;
  436. //查询责任人名称
  437. $responsible_person = explode(',', $data->responsible_person);
  438. $responsible_person_name = $EmployeeModel->whereIn('id', $responsible_person)->pluck('name')->toarray();
  439. $data->responsible_person_name = $responsible_person_name;
  440. //查询来源责任人名称
  441. $source_responsible_person = explode(',', $data->source_responsible_person);
  442. $source_responsible_person_name = $EmployeeModel->whereIn('id', $source_responsible_person)->pluck('name')->toarray();
  443. $data->source_responsible_person_name = $source_responsible_person_name;
  444. // 加载模板
  445. return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => $data]);
  446. }
  447. /**
  448. * 添加
  449. * @author 唐远望
  450. * @version 1.0
  451. * @date 2025-12-08
  452. *
  453. */
  454. public function add(Request $request, ViolationProductModel $ViolationProductModel)
  455. {
  456. $request->scene('add')->validate();
  457. $admin_company_id = request('admin_company_id', '0');
  458. $company_id = request('access_token.company_id', '0');
  459. $is_admin = request('access_token.is_admin', '0'); //是否管理员操作 0=是1=否
  460. // 接收数据
  461. $all_data = request()->all();
  462. $store_scope = request('store_scope', '');
  463. $all_data['store_scope'] = $store_scope;
  464. //查询是否存在
  465. $map = ['product_name' => $all_data['product_name'], 'product_specs' => $all_data['product_specs']];
  466. // 权限判断
  467. if ($is_admin != 1 && $company_id != 0) {
  468. $map['company_id'] = $company_id;
  469. $all_data['company_id'] = $company_id;
  470. } else {
  471. $map['company_id'] = $admin_company_id;
  472. $all_data['company_id'] = $admin_company_id;
  473. }
  474. $data = $ViolationProductModel->where($map)->first();
  475. if ($data) return json_send(['code' => 'error', 'msg' => '记录已存在']);
  476. // 写入数据表
  477. $result = $ViolationProductModel->addLowPriceGoods($all_data);
  478. // 如果操作失败
  479. if (!$result) return json_send(['code' => 'error', 'msg' => '新增失败']);
  480. // 告知结果
  481. return json_send(['code' => 'success', 'msg' => '新增成功']);
  482. }
  483. /**
  484. * 修改
  485. * @author 唐远望
  486. * @version 1.0
  487. * @date 2025-12-08
  488. *
  489. */
  490. public function edit(Request $request, ViolationProductModel $ViolationProductModel)
  491. {
  492. $request->scene('edit')->validate();
  493. $admin_company_id = request('admin_company_id', '0');
  494. $company_id = request('access_token.company_id', '0');
  495. $is_admin = request('access_token.is_admin', '0'); //是否管理员操作 0=是1=否
  496. // 接收参数
  497. $id = request('id', 0);
  498. // 接收数据
  499. $all_data = request()->all();
  500. $store_scope = request('store_scope', '');
  501. $all_data['store_scope'] = $store_scope;
  502. //查询是否存在
  503. $map = ['product_name' => $all_data['product_name'], 'product_specs' => $all_data['product_specs']];
  504. // 权限判断
  505. if ($is_admin != 1 && $company_id != 0) {
  506. $map['company_id'] = $company_id;
  507. $all_data['company_id'] = $company_id;
  508. } else {
  509. $map['company_id'] = $admin_company_id;
  510. $all_data['company_id'] = $admin_company_id;
  511. }
  512. $data = $ViolationProductModel->where($map)->where('id', '!=', $id)->first();
  513. if ($data) return json_send(['code' => 'error', 'msg' => '记录已存在']);
  514. // 更新数据表
  515. $where = ['id' => $id];
  516. $result = $ViolationProductModel->updateLowPriceGoods($where, $all_data);
  517. // 如果操作失败
  518. if (!$result) return json_send(['code' => 'error', 'msg' => '修改失败']);
  519. // 告知结果
  520. return json_send(['code' => 'success', 'msg' => '修改成功']);
  521. }
  522. /**
  523. * 修改状态
  524. * @author 唐远望
  525. * @version 1.0
  526. * @date 2025-12-08
  527. *
  528. */
  529. public function set_status(Request $request, ViolationProductModel $ViolationProductModel)
  530. {
  531. // 验证参数
  532. $request->scene('set_status')->validate();
  533. $admin_company_id = request('admin_company_id', '0');
  534. $company_id = request('access_token.company_id', '0');
  535. $is_admin = request('access_token.is_admin', '0'); //是否管理员操作 0=是1=否
  536. // 接收数据
  537. $id = request('id', 0);
  538. $status = request('status', 0);
  539. // 查询用户
  540. $where = ['id' => $id];
  541. // 权限判断
  542. if ($is_admin != 1 && $company_id != 0) {
  543. $where['company_id'] = $company_id;
  544. } else {
  545. $where['company_id'] = $admin_company_id;
  546. }
  547. $ViolationProduct = $ViolationProductModel->where($where)->first();
  548. if (!$ViolationProduct) return json_send(['code' => 'error', 'msg' => '记录不存在']);
  549. $ViolationProduct->status = $status;
  550. $ViolationProduct->update_time = time();
  551. // 执行修改
  552. $result = $ViolationProduct->save();
  553. // 提示新增失败
  554. if (!$result) return json_send(['code' => 'error', 'msg' => '设置失败']);
  555. // 告知结果
  556. return json_send(['code' => 'success', 'msg' => '设置成功']);
  557. }
  558. /**
  559. * 修改处理状态
  560. * @author 唐远望
  561. * @version 1.0
  562. * @date 2025-12-08
  563. *
  564. */
  565. public function set_processing_status(Request $request, ViolationProductModel $ViolationProductModel)
  566. {
  567. // 验证参数
  568. $request->scene('set_processing_status')->validate();
  569. $admin_company_id = request('admin_company_id', '0');
  570. $company_id = request('access_token.company_id', '0');
  571. $is_admin = request('access_token.is_admin', '0'); //是否管理员操作 0=是1=否
  572. // 接收数据
  573. $id = request('id', 0);
  574. $processing_status = request('processing_status', 0);
  575. // 查询用户
  576. $where = ['id' => $id];
  577. // 权限判断
  578. if ($is_admin != 1 && $company_id != 0) {
  579. $where['company_id'] = $company_id;
  580. } else {
  581. $where['company_id'] = $admin_company_id;
  582. }
  583. $ViolationProduct = $ViolationProductModel->where($where)->first();
  584. if (!$ViolationProduct) return json_send(['code' => 'error', 'msg' => '记录不存在']);
  585. $ViolationProduct->processing_status = $processing_status;
  586. $ViolationProduct->update_time = time();
  587. // 执行修改
  588. $result = $ViolationProduct->save();
  589. // 提示新增失败
  590. if (!$result) return json_send(['code' => 'error', 'msg' => '设置失败']);
  591. // 告知结果
  592. return json_send(['code' => 'success', 'msg' => '设置成功']);
  593. }
  594. /**
  595. * 删除
  596. * @author 唐远望
  597. * @version 1.0
  598. * @date 2025-12-08
  599. *
  600. */
  601. public function delete(Request $request, ViolationProductModel $ViolationProductModel)
  602. {
  603. // 验证参数
  604. $request->scene('delete')->validate();
  605. $admin_company_id = request('admin_company_id', '0');
  606. $company_id = request('access_token.company_id', '0');
  607. $is_admin = request('access_token.is_admin', '0'); //是否管理员操作 0=是1=否
  608. // 接收数据
  609. $id = request('id', 0);
  610. // 查询用户
  611. $where = ['id' => $id];
  612. // 权限判断
  613. if ($is_admin != 1 && $company_id != 0) {
  614. $where['company_id'] = $company_id;
  615. } else {
  616. $where['company_id'] = $admin_company_id;
  617. }
  618. $ViolationProduct = $ViolationProductModel->where($where)->first();
  619. if (!$ViolationProduct) return json_send(['code' => 'error', 'msg' => '记录不存在']);
  620. // 执行删除
  621. $result = $ViolationProduct->delete();
  622. // 提示删除失败
  623. if (!$result) return json_send(['code' => 'error', 'msg' => '删除失败']);
  624. // 告知结果
  625. return json_send(['code' => 'success', 'msg' => '删除成功']);
  626. }
  627. /**
  628. * 执行数据清洗
  629. * @author 唐远望
  630. * @version 1.0
  631. * @date 2025-12-11
  632. *
  633. */
  634. public function data_cleaning(Request $request)
  635. {
  636. // 验证参数
  637. $request->scene('data_cleaning')->validate();
  638. $admin_company_id = request('admin_company_id', '0');
  639. $company_id = request('access_token.company_id', '0');
  640. $is_admin = request('access_token.is_admin', '0'); //是否管理员操作 0=是1=否
  641. $admin_id = request('access_token.uid', 0); //用户ID
  642. // 权限判断
  643. if ($is_admin != 1 && $company_id != 0) {
  644. } else {
  645. $company_id = $admin_company_id;
  646. }
  647. $message_data = ['page' => '1', 'limit' => 50, 'admin_id' => $admin_id, 'is_admin' => $is_admin, 'company_id' => $company_id];
  648. ViolationProductJobs::dispatch($message_data);
  649. // ViolationProductJobs::dispatchSync($message_data);
  650. // 告知结果
  651. return json_send(['code' => 'success', 'msg' => '执行成功']);
  652. }
  653. /**
  654. * 下载导入模板
  655. * @author 唐远望
  656. * @version 1.0
  657. * @date 2025-12-31
  658. *
  659. */
  660. public function download_template()
  661. {
  662. // 创建一个新的 Spreadsheet 对象
  663. $spreadsheet = new Spreadsheet();
  664. $sheet = $spreadsheet->getActiveSheet();
  665. //合并单元格
  666. $sheet->mergeCells('A1:P1');
  667. $sheet->setCellValue('A1', '禁止挂网商品导入模板'); // 设置合并后的单元格内容
  668. // 获取合并后的单元格样式对象
  669. $style = $sheet->getStyle('A1');
  670. // 设置水平居中和垂直居中
  671. $style->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER)->setVertical(Alignment::VERTICAL_CENTER);
  672. // 然后设置行高以适应两行文本
  673. $sheet->getRowDimension(1)->setRowHeight(40); // 设置行高,单位是磅(point)
  674. // 设置表头
  675. $sheet->setCellValue('A2', '第一责任人名称');
  676. $sheet->setCellValue('B2', '责任人名称');
  677. $sheet->setCellValue('C2', '平台名称*');
  678. $sheet->setCellValue('D2', '商品分类名称');
  679. $sheet->setCellValue('E2', '商品名称*');
  680. $sheet->setCellValue('F2', '商品规格*');
  681. $sheet->setCellValue('G2', '累计挂网次数');
  682. $sheet->setCellValue('H2', '连续挂网次数');
  683. $sheet->setCellValue('I2', '销量');
  684. $sheet->setCellValue('J2', '库存');
  685. $sheet->setCellValue('K2', '快照URL');
  686. $sheet->setCellValue('L2', '链接地址*');
  687. $sheet->setCellValue('M2', '店铺名称*');
  688. $sheet->setCellValue('N2', '公司名称*');
  689. $sheet->setCellValue('O2', '公司分类名称');
  690. $sheet->setCellValue('P2', '信用代码*');
  691. $sheet->setCellValue('Q2', '省份*');
  692. $sheet->setCellValue('R2', '城市*');
  693. $sheet->setCellValue('S2', '溯源责任人');
  694. $sheet->setCellValue('T2', '检索采集日期(Y-m-d)*');
  695. $sheet->setCellValue('U2', '发货省份');
  696. $sheet->setCellValue('V2', '发货城市');
  697. // 生成 Excel 文件
  698. $writer = new Xlsx($spreadsheet);
  699. // 直接输出到浏览器(下载)
  700. $filename = '禁止挂网商品导入模板.xlsx';
  701. header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
  702. header('Content-Disposition: attachment;filename="' . $filename . '"');
  703. header('Cache-Control: max-age=0');
  704. $writer->save('php://output');
  705. exit;
  706. }
  707. /**
  708. * 导入Excel数据
  709. * @author 唐远望
  710. * @version 1.0
  711. * @date 2025-12-31
  712. *
  713. */
  714. public function import_data(Request $request, ViolationProductModel $ViolationProductModel, EmployeeModel $EmployeeModel, CitysModel $CitysModel)
  715. {
  716. $request->scene('import_data')->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. $file = $request->file('file');
  721. // 加载Excel文件
  722. $spreadsheet = IOFactory::load($file->getPathname());
  723. $sheet = $spreadsheet->getActiveSheet();
  724. // 获取所有数据
  725. $data = $sheet->toArray();
  726. if (empty($data) || count($data) < 2) return json_send(['code' => 'error', 'msg' => '导入数据为空']);
  727. $result = $EmployeeModel->select(['id', 'name'])->get()->keyBy('name')->toarray();
  728. $platform_data = $ViolationProductModel->platform_data();
  729. $province_id_data = $CitysModel->get_province_id_list();
  730. $city_id_data = $CitysModel->get_city_id_list();
  731. // 过滤空行
  732. $data = array_filter($data, function ($row) {
  733. // 过滤掉所有值都为空的行
  734. return !empty(array_filter($row, function ($value) {
  735. return !is_null($value) && $value !== '';
  736. }));
  737. });
  738. DB::beginTransaction();
  739. try {
  740. foreach ($data as $key => $item) {
  741. $key_num = $key + 1;
  742. if ($key < 2) continue;
  743. //强制必传参数校验
  744. $res_data = $this->import_data_check($key, $item);
  745. if ($res_data) return json_send($res_data);
  746. $first_responsible_person_id = [];
  747. $first_responsible_person_name = $item[0];
  748. if ($first_responsible_person_name) {
  749. $first_responsible_person_name = explode(',', $first_responsible_person_name);
  750. foreach ($first_responsible_person_name as $k => $v) {
  751. $v = trim($v);
  752. if (isset($result[$v])) {
  753. $first_responsible_person_id[] = $result[$v]['id'];
  754. }
  755. }
  756. }
  757. $responsible_person_id = [];
  758. $responsible_person_name = $item[1];
  759. if ($responsible_person_name) {
  760. $responsible_person_name = explode(',', $responsible_person_name);
  761. foreach ($responsible_person_name as $k => $v) {
  762. $v = trim($v);
  763. if (isset($result[$v])) {
  764. $responsible_person_id[] = $result[$v]['id'];
  765. }
  766. }
  767. }
  768. $source_responsible_person_id = [];
  769. $source_responsible_person_name = $item[18];
  770. if ($source_responsible_person_name) {
  771. $source_responsible_person_name = explode(',', $source_responsible_person_name);
  772. foreach ($source_responsible_person_name as $k => $v) {
  773. $v = trim($v);
  774. if (isset($result[$v])) {
  775. $source_responsible_person_id[] = $result[$v]['id'];
  776. }
  777. }
  778. }
  779. $province_name = $item[16];
  780. //特殊地区1级移除市
  781. if ($province_name && in_array($province_name, ['北京市', '天津市', '上海市', '重庆市'])) {
  782. //移除市这个字符
  783. $province_name = trim(str_replace('市', '', $province_name));
  784. } else if ($province_name && in_array($province_name, ['北京', '天津', '上海', '重庆'])) {
  785. } else if ($province_name && in_array($province_name, ['内蒙古', '广西', '西藏', '新疆', '宁夏'])) {
  786. switch ($province_name) {
  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. case '宁夏':
  800. $province_name = '宁夏回族自治区';
  801. break;
  802. }
  803. } else if ($province_name && in_array($province_name, ['内蒙古自治区', '广西壮族自治区', '西藏自治区', '新疆维吾尔自治区', '宁夏回族自治区'])) {
  804. } else if (strpos($province_name, '省') === false) {
  805. //是否存在市省,如果不存在则补全
  806. if (strpos($province_name, '省') === false) {
  807. $province_name = $province_name . '省';
  808. }
  809. }
  810. if (!isset($province_id_data[$province_name])) return json_send(['code' => 'error', 'msg' => "第{$key_num}行省份信息不完整", 'data' => $item]);
  811. $city_name = $item[17];
  812. if (!isset($city_id_data[$city_name])) return json_send(['code' => 'error', 'msg' => "第{$key_num}行城市信息不完整", 'data' => $item]);
  813. $shipment_province_name = isset($item[20]) ? $item[20] : '';
  814. //特殊地区1级移除市
  815. if ($shipment_province_name && in_array($province_name, ['北京市', '天津市', '上海市', '重庆市'])) {
  816. //移除市这个字符
  817. $shipment_province_name = trim(str_replace('市', '', $shipment_province_name));
  818. } else if ($shipment_province_name && in_array($shipment_province_name, ['北京', '天津', '上海', '重庆'])) {
  819. } else if ($shipment_province_name && in_array($shipment_province_name, ['内蒙古', '广西', '西藏', '新疆', '宁夏'])) {
  820. switch ($shipment_province_name) {
  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. case '宁夏':
  834. $shipment_province_name = '宁夏回族自治区';
  835. break;
  836. }
  837. } else if ($shipment_province_name && in_array($shipment_province_name, ['内蒙古自治区', '广西壮族自治区', '西藏自治区', '新疆维吾尔自治区', '宁夏回族自治区'])) {
  838. } else if (strpos($shipment_province_name, '省') === false) {
  839. //是否存在市省,如果不存在则补全
  840. if (strpos($shipment_province_name, '省') === false) {
  841. $shipment_province_name = $shipment_province_name . '省';
  842. }
  843. }
  844. $shipment_province_id = '0';
  845. if (!isset($province_id_data[$shipment_province_name])) {
  846. $shipment_province_name = '';
  847. } else {
  848. $shipment_province_id = $province_id_data[$shipment_province_name]['id'];
  849. }
  850. $shipment_city_id = '0';
  851. $shipment_city_name = isset($item[21]) ? $item[21] : '';
  852. if (!isset($city_id_data[$shipment_city_name])) {
  853. $shipment_city_name = '';
  854. } else {
  855. $shipment_city_id = $city_id_data[$shipment_city_name]['id'];
  856. }
  857. // 权限判断
  858. if ($is_admin != 1 && $company_id != 0) {
  859. $insert_product_data['company_id'] = $company_id;
  860. } else {
  861. $insert_product_data['company_id'] = $admin_company_id;
  862. }
  863. $insert_product_data['first_responsible_person'] = !empty($first_responsible_person_id) ? implode(',', $first_responsible_person_id) : ''; //第一责任人ID集合
  864. $insert_product_data['responsible_person'] = !empty($responsible_person_id) ? implode(',', $responsible_person_id) : ''; //责任人ID集合
  865. $insert_product_data['platform'] = isset($platform_data[$item[2]]) ? $platform_data[$item[2]] : '0'; // 平台
  866. $insert_product_data['category_name'] = $item[3] ? $item[4] : ''; // 商品分类
  867. $insert_product_data['product_name'] = $item[4]; // 商品名称
  868. $insert_product_data['product_specs'] = $item[5]; // 商品规格
  869. $insert_product_data['online_posting_count'] = isset($item[6]) ? $item[6] : 1; // 累计挂网次数
  870. $insert_product_data['continuous_listing_count'] = isset($item[7]) ? $item[7] : 1; // 连续挂网次数
  871. $insert_product_data['sales'] = isset($item[8]) ? $item[8] : 0; // 销量
  872. $insert_product_data['inventory'] = isset($item[9]) ? $item[9] : 0; // 库存
  873. $insert_product_data['snapshot_url'] = isset($item[10]) ? $item[10] : ''; // 快照URL
  874. $insert_product_data['link_url'] = $item[11]; // 链接地址
  875. $insert_product_data['store_name'] = $item[12]; // 店铺名称
  876. $insert_product_data['company_name'] = $item[13]; // 公司名称
  877. $insert_product_data['company_category_name'] = isset($item[14]) ? $item[14] : ''; // 公司分类
  878. $insert_product_data['social_credit_code'] = $item[15]; // 信用代码
  879. $insert_product_data['province_name'] = $item[16]; // 省份
  880. $insert_product_data['province_id'] = isset($province_id_data[$province_name]) ? $province_id_data[$province_name]['id'] : 0; // 省份ID
  881. $insert_product_data['city_name'] = $item[17]; // 城市
  882. $insert_product_data['city_id'] = isset($city_id_data[$city_name]) ? $city_id_data[$city_name]['id'] : 0; // 城市ID
  883. $insert_product_data['area_info'] = ''; // 详细地址
  884. $insert_product_data['source_responsible_person'] = !empty($source_responsible_person_id) ? implode(',', $source_responsible_person_id) : ''; //溯源责任人ID集合
  885. $insert_product_data['processing_status'] = 1; //处理状态1=待处理2=购买中3=已溯源4=回收凭据已上传5=已回收6=拒绝回收7=已下架8=无法处理
  886. $insert_product_data['status'] = 0; //状态0=有效=无效
  887. $insert_product_data['insert_time'] = time();
  888. $insert_product_data['source_id'] = 0; // 原始数据ID
  889. $insert_product_data['scrape_date'] = $item[19]; // 检索采集日期
  890. $insert_product_data['shipment_province_id'] = $shipment_province_id; // 发货省份id
  891. $insert_product_data['shipment_province_name'] = $shipment_province_name; // 发货省份
  892. $insert_product_data['shipment_city_id'] = $shipment_city_id; // 发货城市id
  893. $insert_product_data['shipment_city_name'] = $shipment_city_name; // 发货城市
  894. //插入数据
  895. $ViolationProductModel->addViolationProduct($insert_product_data, true);
  896. }
  897. DB::commit();
  898. return json_send(['code' => 'success', 'msg' => '导入成功']);
  899. // 成功处理...
  900. } catch (\Exception $e) {
  901. DB::rollBack();
  902. // 错误处理...
  903. return json_send(['code' => 'error', 'msg' => '导入失败', 'data' => $e->getMessage()]);
  904. }
  905. }
  906. /**
  907. * 导入Excel数据必传参数校验
  908. * @author 唐远望
  909. * @version 1.0
  910. * @date 2025-12-31
  911. *
  912. */
  913. private function import_data_check($key, $item)
  914. {
  915. $key = $key + 1;
  916. if (!$item[2]) {
  917. return ['code' => 'error', 'msg' => "第{$key}行平台不能为空", 'data' => $item];
  918. }
  919. if (!$item[4]) {
  920. return ['code' => 'error', 'msg' => "第{$key}行商品名称不能为空", 'data' => $item];
  921. }
  922. if (!$item[5]) {
  923. return ['code' => 'error', 'msg' => "第{$key}行商品规格不能为空", 'data' => $item];
  924. }
  925. if (!$item[11]) {
  926. return ['code' => 'error', 'msg' => "第{$key}行链接地址不能为空", 'data' => $item];
  927. }
  928. if (!$item[12]) {
  929. return ['code' => 'error', 'msg' => "第{$key}行店铺名称不能为空", 'data' => $item];
  930. }
  931. if (!$item[13]) {
  932. return ['code' => 'error', 'msg' => "第{$key}行公司名称不能为空", 'data' => $item];
  933. }
  934. if (!$item[15]) {
  935. return ['code' => 'error', 'msg' => "第{$key}行信用代码不能为空", 'data' => $item];
  936. }
  937. if (!$item[16]) {
  938. return ['code' => 'error', 'msg' => "第{$key}行省份不能为空", 'data' => $item];
  939. }
  940. if (!$item[17]) {
  941. return ['code' => 'error', 'msg' => "第{$key}行城市不能为空", 'data' => $item];
  942. }
  943. if (!$item[19]) {
  944. return ['code' => 'error', 'msg' => "第{$key}行检索采集日期不能为空", 'data' => $item];
  945. } else {
  946. //校验格式是否为Y-m-d
  947. if (!preg_match('/^[0-9]{4}-[0-9]{2}-[0-9]{2}$/', $item[19])) {
  948. return ['code' => 'error', 'msg' => "第{$key}行检索采集日期格式不正确", 'data' => $item];
  949. }
  950. if (strtotime($item[19] . ' 00:00:00') > time()) {
  951. return ['code' => 'error', 'msg' => "第{$key}行检索采集日期不能大于当前日期", 'data' => $item];
  952. }
  953. }
  954. }
  955. }