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