ViolationProduct.php 54 KB

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