ViolationProduct.php 50 KB

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