ViolationProduct.php 51 KB

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