ViolationProduct.php 53 KB

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