ViolationProduct.php 53 KB

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