ViolationProduct.php 55 KB

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