ViolationCompanyDataJobs.php 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539
  1. <?php
  2. namespace App\Jobs\Manager\Process;
  3. use Illuminate\Bus\Queueable;
  4. use Illuminate\Contracts\Queue\ShouldBeUnique;
  5. use Illuminate\Contracts\Queue\ShouldQueue;
  6. use Illuminate\Foundation\Bus\Dispatchable;
  7. use Illuminate\Queue\InteractsWithQueue;
  8. use Illuminate\Queue\SerializesModels;
  9. use App\Facades\Servers\Logs\Log;
  10. use App\Models\Manager\WashConfig\ViolationCompany as ViolationCompanyModel;
  11. use App\Models\Manager\Personnel\Employee as EmployeeModel;
  12. use App\Models\Api\Process\ExecuteLog as ExecuteLogModel;
  13. use App\Models\Manager\Process\ScrapeData as ScrapeDataModel;
  14. use App\Models\Manager\WashConfig\ViolationCompanyMember as ViolationCompanyMemberModel;
  15. use App\Models\Manager\Citys as CitysModel;
  16. use App\Models\Manager\Personnel\EmployeePlatform as EmployeePlatformModel;
  17. use App\Models\Manager\Personnel\EmployeeArea as EmployeeAreaModel;
  18. use App\Models\Manager\WashConfig\ViolationStore as ViolationStoreModel;
  19. use App\Models\Manager\Process\ViolationStore as ProcessViolationStoreModel;
  20. /**
  21. * 数据清洗-违规公司店铺清洗数据队列
  22. * @author 唐远望
  23. * @version 1.0
  24. * @date 2025-12-11
  25. */
  26. class ViolationCompanyDataJobs implements ShouldQueue
  27. {
  28. use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
  29. public $tries = 3; // 限制重试次数
  30. public $timeout = 600; // 5分钟超时
  31. protected $message_data;
  32. /**
  33. * Create a new job instance.
  34. *
  35. * @return void
  36. */
  37. public function __construct(array $message_data)
  38. {
  39. $this->message_data = $message_data;
  40. }
  41. /**
  42. * Execute the job.
  43. *
  44. * @return void
  45. */
  46. public function handle()
  47. {
  48. try {
  49. $this->getViolationStoreData($this->message_data);
  50. } catch (\Exception $e) {
  51. Log::info('job_error', '数据清洗-违规公司店铺清洗数据队列失败', ['data' => $this->message_data, 'error' => $e->getMessage()]);
  52. }
  53. }
  54. /**
  55. * 采集商品数据清洗
  56. * @author 唐远望
  57. * @version 1.0
  58. * @date 2025-12-11
  59. */
  60. public function getViolationStoreData($message_data)
  61. {
  62. $CitysModel = new CitysModel();
  63. $EmployeeModel = new EmployeeModel();
  64. $ViolationCompanyModel = new ViolationCompanyModel();
  65. $ProcessViolationStoreModel = new ProcessViolationStoreModel();
  66. $ViolationCompanyMemberModel = new ViolationCompanyMemberModel();
  67. $EmployeePlatformModel = new EmployeePlatformModel();
  68. $EmployeeAreaModel = new EmployeeAreaModel();
  69. $platform = $message_data['platform']; //多个平台配置
  70. $company_name = $message_data['company_name']; //公司名称
  71. $social_credit_code = $message_data['social_credit_code']; //社会信用代码
  72. $company_type = $message_data['company_type']; //公司类型:1=黑名单2=白名单
  73. $executeLog_id = $message_data['executeLog_id'];
  74. $company_category_name = $message_data['company_category_name']; //公司类别名称
  75. $specify_responsible_person = $message_data['specify_responsible_person']; //指派责任人 0=开启 1=关闭
  76. $company_id = isset($message_data['company_id']) ? $message_data['company_id'] : 0; //品牌方公司ID
  77. $product_data = isset($this->message_data['product_data']) ? $this->message_data['product_data'] : [];
  78. $index_number = isset($this->message_data['index_number']) ? $this->message_data['index_number'] : 0;
  79. $data_totle = isset($this->message_data['data_totle']) ? $this->message_data['data_totle'] : 0;
  80. //-------------------------------------- 清洗规则(开始) --------------------------------------
  81. //过滤没有链接数据
  82. if (trim($product_data['link_url']) == '') return true;
  83. //数据是否命中指定公司
  84. $hit_company_scope = false;
  85. if ($social_credit_code == '') return true;
  86. if ($product_data['qualification_number'] == $social_credit_code) {
  87. $hit_company_scope = true;
  88. }
  89. if ($hit_company_scope != true) return true;
  90. //-------------------------------------- 清洗规则(结束) --------------------------------------
  91. $store_name = $product_data['store_name'];
  92. $anonymous_store_name = $product_data['anonymous_store_name'];
  93. if ($anonymous_store_name != '') {
  94. $store_name = $anonymous_store_name;
  95. }
  96. //-------------------------------------- 处理营业执照地区信息(开始) --------------------------------------
  97. $province_name = $product_data['province_name'];
  98. $city_name = $product_data['city_name'];
  99. //特殊地区1级移除市
  100. if ($province_name && in_array($province_name, ['北京市', '天津市', '上海市', '重庆市'])) {
  101. //移除市这个字符
  102. $province_name = trim(str_replace('市', '', $province_name));
  103. } else if ($province_name && in_array($province_name, ['北京', '天津', '上海', '重庆'])) {
  104. } else if ($province_name && in_array($province_name, ['内蒙古', '广西', '西藏', '新疆', '宁夏'])) {
  105. switch ($province_name) {
  106. case '内蒙古':
  107. $province_name = '内蒙古自治区';
  108. break;
  109. case '广西':
  110. $province_name = '广西壮族自治区';
  111. break;
  112. case '西藏':
  113. $province_name = '西藏自治区';
  114. break;
  115. case '新疆':
  116. $province_name = '新疆维吾尔自治区';
  117. break;
  118. case '宁夏':
  119. $province_name = '宁夏回族自治区';
  120. break;
  121. }
  122. } else if ($province_name && in_array($province_name, ['内蒙古自治区', '广西壮族自治区', '西藏自治区', '新疆维吾尔自治区', '宁夏回族自治区'])) {
  123. //完整匹配不做处理
  124. } else if (trim($province_name) != '' && strpos($province_name, '省') === false) {
  125. //是否存在市省,如果不存在则补全
  126. $province_name = $province_name . '省';
  127. }
  128. if (trim($province_name) != '') {
  129. //根据最新处理后的省份名称获取省份ID
  130. $db_province_id = $CitysModel->where([['name', '=', $province_name], ['level', '=', '1']])->value('id');
  131. if (!empty($db_province_id)) {
  132. $product_data['province_id'] = $db_province_id;
  133. } else {
  134. //逆推省份ID失败,则修改为未知名称
  135. $province_name = '未知';
  136. }
  137. } else {
  138. //尝试从地区详情里面匹配省份名称
  139. $db_province_data_list = $CitysModel->where([['level', '=', '1']])->select(['id', 'name'])->get()->toarray();
  140. foreach ($db_province_data_list as $db_province_data) {
  141. $db_province_name = $db_province_data['name'];
  142. if (strpos($product_data['area_info'], $db_province_name) !== false) {
  143. $province_name = $db_province_name;
  144. $product_data['province_id'] = $db_province_data['id'];
  145. break;
  146. }
  147. }
  148. }
  149. if (trim($city_name) != '') {
  150. $db_city_id = $CitysModel->where([['name', '=', $city_name], ['level', '=', '2']])->value('id');
  151. if (!empty($db_city_id)) {
  152. $product_data['city_id'] = $db_city_id;
  153. } else {
  154. if (trim($city_name) != '' && strpos($city_name, '市') === false) {
  155. //是否存在市
  156. $city_name = $city_name . '市';
  157. //根据最新处理后的市名称获取市ID
  158. $db_city_id = $CitysModel->where([['name', '=', $city_name], ['level', '=', '2']])->value('id');
  159. if (!empty($db_city_id)) {
  160. $product_data['city_id'] = $db_city_id;
  161. } else {
  162. $city_name = '未知';
  163. }
  164. }else{
  165. $city_name = '未知';
  166. }
  167. }
  168. } else {
  169. if (trim($product_data['area_info']) != '') {
  170. //尝试从地区详情里面匹配市名称
  171. $db_city_name_list = $CitysModel->where([['level', '=', '2']])->pluck('name')->toarray();
  172. foreach ($db_city_name_list as $db_city_name) {
  173. if (strpos($product_data['area_info'], $db_city_name) !== false) {
  174. $db_city_id = $CitysModel->where([['name', '=', $db_city_name], ['level', '=', '2']])->value('id');
  175. $product_data['city_id'] = $db_city_id;
  176. $product_data['city_name'] = $db_city_name;
  177. $city_name = $db_city_name;
  178. break;
  179. }
  180. }
  181. }
  182. }
  183. //如果存在市区city_id 则逆推省份ID以及名称
  184. if (!empty($product_data['city_id']) && empty($product_data['province_id'])) {
  185. $db_province_id = $CitysModel->where([['id', '=', $product_data['city_id']], ['level', '=', '2']])->value('pid');
  186. $db_province_name = $CitysModel->where([['id', '=', $db_province_id], ['level', '=', '1']])->value('name');
  187. $product_data['province_id'] = $db_province_id;
  188. $product_data['province_name'] = $db_province_name;
  189. $province_name = $db_province_name;
  190. }
  191. if (trim($product_data['area_info']) == '' && trim($city_name) != '' && trim($province_name) != '') {
  192. $product_data['area_info'] = $province_name . $city_name;
  193. }
  194. //-------------------------------------- 处理营业执照地区信息(结束) --------------------------------------
  195. //-------------------------------------- 处理发货省份地区信息(开始) --------------------------------------
  196. $shipment_province_name = $product_data['shipment_province_name'];
  197. $shipment_city_name = $product_data['shipment_city_name'];
  198. //特殊地区1级移除市
  199. if ($shipment_province_name && in_array($shipment_province_name, ['北京市', '天津市', '上海市', '重庆市'])) {
  200. //移除市这个字符
  201. $shipment_province_name = trim(str_replace('市', '', $shipment_province_name));
  202. } else if ($shipment_province_name && in_array($shipment_province_name, ['北京', '天津', '上海', '重庆'])) {
  203. } else if ($shipment_province_name && in_array($shipment_province_name, ['内蒙古', '广西', '西藏', '新疆', '宁夏'])) {
  204. switch ($shipment_province_name) {
  205. case '内蒙古':
  206. $shipment_province_name = '内蒙古自治区';
  207. break;
  208. case '广西':
  209. $shipment_province_name = '广西壮族自治区';
  210. break;
  211. case '西藏':
  212. $shipment_province_name = '西藏自治区';
  213. break;
  214. case '新疆':
  215. $shipment_province_name = '新疆维吾尔自治区';
  216. break;
  217. case '宁夏':
  218. $shipment_province_name = '宁夏回族自治区';
  219. break;
  220. }
  221. } else if ($shipment_province_name && in_array($shipment_province_name, ['内蒙古自治区', '广西壮族自治区', '西藏自治区', '新疆维吾尔自治区', '宁夏回族自治区'])) {
  222. //完整匹配不做处理
  223. } else if (trim($shipment_province_name) != '' && strpos($shipment_province_name, '省') === false) {
  224. //是否存在市省,如果不存在则补全
  225. $shipment_province_name = $shipment_province_name . '省';
  226. }
  227. if (trim($shipment_province_name) != '') {
  228. //根据最新处理后的省份名称获取省份ID
  229. $db_shipment_province_id = $CitysModel->where([['name', '=', $shipment_province_name], ['level', '=', '1']])->value('id');
  230. if (!empty($db_shipment_province_id)) {
  231. $product_data['shipment_province_id'] = $db_shipment_province_id;
  232. } else {
  233. //逆推省份ID失败,则修改为未知名称
  234. $shipment_province_name = '未知';
  235. }
  236. }
  237. if (trim($shipment_city_name) != '') {
  238. $db_shipment_city_id = $CitysModel->where([['name', '=', $shipment_city_name], ['level', '=', '2']])->value('id');
  239. if (!empty($db_shipment_city_id)) {
  240. $product_data['shipment_city_id'] = $db_shipment_city_id;
  241. } else {
  242. if (trim($shipment_city_name) != '' && strpos($shipment_city_name, '市') === false) {
  243. //是否存在市
  244. $shipment_city_name = $shipment_city_name . '市';
  245. //根据最新处理后的市名称获取市ID
  246. $db_shipment_city_id = $CitysModel->where([['name', '=', $shipment_city_name], ['level', '=', '2']])->value('id');
  247. if (!empty($db_shipment_city_id)) {
  248. $product_data['shipment_city_id'] = $db_shipment_city_id;
  249. } else {
  250. //逆推市ID失败,则修改为未知名称
  251. $shipment_city_name = '未知';
  252. }
  253. }else{
  254. $city_name = '未知';
  255. }
  256. }
  257. }
  258. //如果存在市区shipment_city_id 则逆推省份ID以及名称
  259. if (!empty($product_data['shipment_city_id']) && empty($product_data['shipment_province_id'])) {
  260. $db_shipment_province_id = $CitysModel->where([['id', '=', $product_data['shipment_city_id']], ['level', '=', '2']])->value('pid');
  261. $db_shipment_province_name = $CitysModel->where([['id', '=', $db_shipment_province_id], ['level', '=', '1']])->value('name');
  262. $product_data['shipment_province_id'] = $db_shipment_province_id;
  263. $product_data['shipment_province_name'] = $db_shipment_province_name;
  264. }
  265. //-------------------------------------- 处理发货省份地区信息(结束) --------------------------------------
  266. //处理链接信息
  267. preg_match('/https?:\/\/[^\s\'"<>]+/i', $product_data['link_url'], $matches);
  268. if (!empty($matches)) {
  269. $product_data['link_url'] = $matches[0];
  270. }
  271. //合并省份市区ID
  272. $merge_city_id = 0;
  273. $merge_province_id = 0;
  274. $merge_city_name = '';
  275. $merge_province_name = '';
  276. if (!empty($product_data['city_id']) && !empty($product_data['province_id'])) {
  277. $merge_city_id = $product_data['city_id'];
  278. $merge_province_id = $product_data['province_id'];
  279. $merge_city_name = $city_name;
  280. $merge_province_name = $province_name;
  281. } else if (!empty($product_data['shipment_city_id']) && !empty($product_data['shipment_province_id'])) {
  282. $merge_city_id = $product_data['shipment_city_id'];
  283. $merge_province_id = $product_data['shipment_province_id'];
  284. $merge_city_name = $shipment_city_name;
  285. $merge_province_name = $shipment_province_name;
  286. }
  287. $insert_product_data = [
  288. 'company_id' => $company_id,
  289. 'source_id' => $product_data['id'],
  290. 'platform' => $product_data['platform_id'],
  291. 'company_name' => $product_data['company_name'],
  292. 'link_url' => $product_data['link_url'],
  293. 'store_name' => $store_name,
  294. 'social_credit_code' => $social_credit_code,
  295. 'province_id' => $product_data['province_id'],
  296. 'province_name' => $province_name,
  297. 'city_id' => $product_data['city_id'],
  298. 'city_name' => $city_name,
  299. 'area_info' => $product_data['area_info'],
  300. 'company_category_name' => $company_category_name,
  301. 'first_responsible_person' => '',
  302. 'responsible_person' => '',
  303. 'source_responsible_person' => '',
  304. 'scrape_date' => $product_data['scrape_date'],
  305. 'collection_time' => strtotime($product_data['insert_time']),
  306. 'merge_city_id' => $merge_city_id,
  307. 'merge_province_id' => $merge_province_id,
  308. 'merge_city_name' => $merge_city_name,
  309. 'merge_province_name' => $merge_province_name,
  310. 'specify_responsible_person' => $specify_responsible_person,
  311. ];
  312. //获取指定人员信息
  313. if ($specify_responsible_person == 0) {
  314. //获取店铺责任人信息
  315. $ViolationStoreModel = new ViolationStoreModel();
  316. $store_data_info = $ViolationStoreModel->where('company_id', $company_id)->where('store_name', $product_data['store_name'])->where('status','0')->first();
  317. if (!empty($store_data_info) && trim($store_data_info->employee_ids) != '') {
  318. //查询店铺第一责任人信息
  319. $EmployeeModel = new EmployeeModel();
  320. $store_where_query = [];
  321. $employee_id_store = explode(',', $store_data_info->employee_ids);
  322. $store_where_query[] = ['company_id', '=', $company_id];
  323. $store_where_query[] = ['status', '=', 0];
  324. $store_where_query[] = ['duty_type', '=', 1]; //责任类型1=第一责任人,2=责任人
  325. $first_responsible_person = $EmployeeModel->whereIn('id',$employee_id_store)->where($store_where_query)->pluck('id')->implode(',');
  326. $insert_product_data['first_responsible_person'] = $first_responsible_person;
  327. //查询店铺责任人信息
  328. $EmployeeModel = new EmployeeModel();
  329. $store_where_query = [];
  330. $employee_id_store = explode(',', $store_data_info->employee_ids);
  331. $store_where_query[] = ['company_id', '=', $company_id];
  332. $store_where_query[] = ['status', '=', 0];
  333. $store_where_query[] = ['duty_type', '=', 2]; //责任类型1=第一责任人,2=责任人
  334. $responsible_person = $EmployeeModel->whereIn('id',$employee_id_store)->where($store_where_query)->pluck('id')->implode(',');
  335. $insert_product_data['responsible_person'] = $responsible_person;
  336. //溯源责任人
  337. $source_responsible_person = '';
  338. if ($first_responsible_person && $responsible_person) {
  339. //转换成数组,合并后在去重
  340. $first_responsible_person = explode(',', $first_responsible_person);
  341. $responsible_person = explode(',', $responsible_person);
  342. $source_responsible_person = array_unique(array_merge($first_responsible_person, $responsible_person));
  343. $source_responsible_person = ',' . implode(',', $source_responsible_person) . ',';
  344. } else if ($first_responsible_person) {
  345. $source_responsible_person = $first_responsible_person;
  346. } else if ($responsible_person) {
  347. $source_responsible_person = $responsible_person;
  348. }
  349. $insert_product_data['source_responsible_person'] = $source_responsible_person;
  350. } else {
  351. //获取公司绑定责任人信息
  352. $company_data = $ViolationCompanyModel->leftjoin('washconfig_company_category', 'washconfig_company_category.id', '=', 'washconfig_violation_company.category_id')
  353. ->where('washconfig_violation_company.social_credit_code', $product_data['qualification_number'])
  354. ->where('washconfig_violation_company.company_id', $company_id)
  355. ->select(['washconfig_violation_company.id', 'washconfig_company_category.name as category_name'])->first();
  356. $employee_id_list = [];
  357. if ($company_data) {
  358. $employee_id_list = $ViolationCompanyMemberModel->where('company_logid', $company_data->id)->pluck('employee_id')->toarray();
  359. $insert_product_data['company_category_name'] = $company_data->category_name ? $company_data->category_name : '';
  360. }
  361. $where_query1 = [];
  362. $where_query2 = [];
  363. $where_query3 = [];
  364. //查询指定公司第一责任人
  365. if (!empty($employee_id_list)) {
  366. $where_query1[] = ['company_id', '=', $company_id];
  367. $where_query1[] = ['id', 'in', $employee_id_list];
  368. $where_query1[] = ['status', '=', 0];
  369. $where_query1[] = ['duty_type', '=', 1]; //责任类型1=第一责任人,2=责任人
  370. }
  371. //查询地区配置的第一责任人
  372. $employee_id_area = $EmployeeAreaModel->where('city_id', $product_data['city_id'])->pluck('employee_id')->toarray();
  373. if (!empty($employee_id_area)) {
  374. $where_query2[] = ['company_id', '=', $company_id];
  375. $where_query2[] = ['id', 'in', $employee_id_area];
  376. $where_query2[] = ['status', '=', 0];
  377. $where_query2[] = ['duty_type', '=', 1]; //责任类型1=第一责任人,2=责任人
  378. }
  379. //查询平台配置的第一责任人
  380. $employee_id_platform = $EmployeePlatformModel->where('platform_id', $product_data['platform_id'])->pluck('employee_id')->toarray();
  381. if (!empty($employee_id_platform)) {
  382. $where_query3[] = ['company_id', '=', $company_id];
  383. $where_query3[] = ['id', 'in', $employee_id_platform];
  384. $where_query3[] = ['status', '=', 0];
  385. $where_query3[] = ['duty_type', '=', 1]; //责任类型1=第一责任人,2=责任人
  386. }
  387. //并行查询第一责任人
  388. $EmployeeModel = new EmployeeModel();
  389. $EmployeeModel = $EmployeeModel
  390. ->orWhere(function ($q) use ($employee_id_list, $company_id) {
  391. if (!empty($employee_id_list)) {
  392. $q->where('company_id', $company_id)
  393. ->orWhereIn('id', $employee_id_list)
  394. ->where('duty_type', 1)
  395. ->where('status', 0);
  396. }
  397. })->orWhere(function ($q) use ($employee_id_area, $company_id) {
  398. if (!empty($employee_id_area)) {
  399. $q->where('company_id', $company_id)
  400. ->whereIn('id', $employee_id_area)
  401. ->where('duty_type', 1)
  402. ->where('status', 0);
  403. }
  404. })->orWhere(function ($q) use ($employee_id_platform, $company_id) {
  405. if (!empty($employee_id_platform)) {
  406. $q->where('company_id', $company_id)
  407. ->whereIn('id', $employee_id_platform)
  408. ->where('duty_type', 1)
  409. ->where('status', 0);
  410. }
  411. });
  412. $first_responsible_person = $EmployeeModel->pluck('id')->implode(',');
  413. //当以上规则匹配不到责任人时,则去查询发货地区信息关联责任人
  414. if (trim($first_responsible_person) == '' && trim($product_data['shipment_city_id']) != '') {
  415. $employee_id_area = $EmployeeAreaModel->where('company_id',$company_id)->where('city_id', $product_data['shipment_city_id'])->pluck('employee_id')->toarray();
  416. if (!empty($employee_id_area)) {
  417. $where_city =[];
  418. $where_city[] = ['company_id', '=', $company_id];
  419. $where_city[] = ['status', '=', 0];
  420. $where_city[] = ['duty_type', '=', 1]; //责任类型1=第一责任人,2=责任人
  421. $EmployeeModel = new EmployeeModel();
  422. $first_responsible_person = $EmployeeModel->whereIn('id',$employee_id_area)->where($where_city)->pluck('id')->implode(',');
  423. }
  424. }
  425. //调试记录查询条件
  426. $insert_product_data['first_responsible_person'] = $first_responsible_person;
  427. //查询责任人
  428. $where_query1 = [];
  429. $where_query2 = [];
  430. $where_query3 = [];
  431. //查询指定公司责任人
  432. if (!empty($employee_id_list)) {
  433. $where_query1[] = ['company_id', '=', $company_id];
  434. $where_query1[] = ['id', 'in', $employee_id_list];
  435. $where_query1[] = ['status', '=', 0];
  436. $where_query1[] = ['duty_type', '=', 2]; //责任类型1=第一责任人,2=责任人
  437. }
  438. //查询地区配置的员工
  439. $employee_id_area = $EmployeeAreaModel->where('city_id', $product_data['city_id'])->pluck('employee_id')->toarray();
  440. if (!empty($employee_id_area)) {
  441. $where_query2[] = ['company_id', '=', $company_id];
  442. $where_query2[] = ['id', 'in', $employee_id_area];
  443. $where_query2[] = ['status', '=', 0];
  444. $where_query2[] = ['duty_type', '=', 2]; //责任类型1=第一责任人,2=责任人
  445. }
  446. //查询平台配置的员工
  447. $employee_id_platform = $EmployeePlatformModel->where('platform_id', $product_data['platform_id'])->pluck('employee_id')->toarray();
  448. if (!empty($employee_id_platform)) {
  449. $where_query3[] = ['company_id', '=', $company_id];
  450. $where_query3[] = ['id', 'in', $employee_id_platform];
  451. $where_query3[] = ['status', '=', 0];
  452. $where_query3[] = ['duty_type', '=', 2]; //责任类型1=第一责任人,2=责任人
  453. }
  454. //并行查询责任人
  455. $EmployeeModel = new EmployeeModel();
  456. $EmployeeModel = $EmployeeModel
  457. ->orWhere(function ($q) use ($employee_id_list, $company_id) {
  458. if (!empty($employee_id_list)) {
  459. $q->where('company_id', $company_id)
  460. ->orWhereIn('id', $employee_id_list)
  461. ->where('duty_type', 2)
  462. ->where('status', 0);
  463. }
  464. })->orWhere(function ($q) use ($employee_id_area, $company_id) {
  465. if (!empty($employee_id_area)) {
  466. $q->where('company_id', $company_id)
  467. ->whereIn('id', $employee_id_area)
  468. ->where('duty_type', 2)
  469. ->where('status', 0);
  470. }
  471. })->orWhere(function ($q) use ($employee_id_platform, $company_id) {
  472. if (!empty($employee_id_platform)) {
  473. $q->where('company_id', $company_id)
  474. ->whereIn('id', $employee_id_platform)
  475. ->where('duty_type', 2)
  476. ->where('status', 0);
  477. }
  478. });
  479. $responsible_person = $EmployeeModel->pluck('id')->implode(',');
  480. //当以上规则匹配不到责任人时,则去查询发货地区信息关联责任人
  481. if (trim($responsible_person) == '' && trim($product_data['shipment_city_id']) != '') {
  482. $employee_id_area = $EmployeeAreaModel->where('company_id',$company_id)->where('city_id', $product_data['shipment_city_id'])->pluck('employee_id')->toarray();
  483. if (!empty($employee_id_area)) {
  484. $where_city =[];
  485. $where_city[] = ['company_id', '=', $company_id];
  486. $where_city[] = ['status', '=', 0];
  487. $where_city[] = ['duty_type', '=', 2]; //责任类型1=第一责任人,2=责任人
  488. $EmployeeModel = new EmployeeModel();
  489. $responsible_person = $EmployeeModel->whereIn('id',$employee_id_area)->where($where_city)->pluck('id')->implode(',');
  490. }
  491. }
  492. $insert_product_data['responsible_person'] = $responsible_person;
  493. //溯源责任人
  494. $source_responsible_person = '';
  495. if ($first_responsible_person && $responsible_person) {
  496. //转换成数组,合并后在去重
  497. $first_responsible_person = explode(',', $first_responsible_person);
  498. $responsible_person = explode(',', $responsible_person);
  499. $source_responsible_person = array_unique(array_merge($first_responsible_person, $responsible_person));
  500. $source_responsible_person = ',' . implode(',', $source_responsible_person) . ',';
  501. } else if ($first_responsible_person) {
  502. $source_responsible_person = $first_responsible_person;
  503. } else if ($responsible_person) {
  504. $source_responsible_person = $responsible_person;
  505. }
  506. $insert_product_data['source_responsible_person'] = $source_responsible_person;
  507. }
  508. }
  509. //插入数据
  510. $ProcessViolationStoreModel->addViolationStore($insert_product_data);
  511. if ($index_number == $data_totle) {
  512. (new ExecuteLogModel())->where('id', $executeLog_id)->update(['status' => 0, 'update_time' => time()]);
  513. }
  514. }
  515. public function failed(\Throwable $exception)
  516. {
  517. Log::info('job_error', '数据清洗-违规公司店铺清洗数据队列完全失败', ['data' => $this->message_data, 'error' => $exception->getMessage()]);
  518. }
  519. }