ViolationProduct.php 52 KB

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