ViolationProduct.php 52 KB

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