ViolationStoreDataJobs.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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\Process\ViolationStore as ViolationStoreModel;
  11. use App\Models\Manager\Personnel\Employee as EmployeeModel;
  12. use App\Models\Api\Process\ExecuteLog as ExecuteLogModel;
  13. /**
  14. * 数据清洗-违规店铺清洗数据队列
  15. * @author 唐远望
  16. * @version 1.0
  17. * @date 2025-12-11
  18. */
  19. class ViolationStoreDataJobs implements ShouldQueue
  20. {
  21. use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
  22. protected $message_data;
  23. /**
  24. * Create a new job instance.
  25. *
  26. * @return void
  27. */
  28. public function __construct(array $message_data)
  29. {
  30. $this->message_data = $message_data;
  31. }
  32. /**
  33. * Execute the job.
  34. *
  35. * @return void
  36. */
  37. public function handle()
  38. {
  39. try {
  40. $this->getViolationStoreData($this->message_data);
  41. } catch (\Exception $e) {
  42. Log::info('job_error', '数据清洗-违规店铺清洗数据队列失败', ['data' => $this->message_data, 'error' => $e->getMessage()]);
  43. }
  44. }
  45. /**
  46. * 采集商品数据清洗
  47. * @author 唐远望
  48. * @version 1.0
  49. * @date 2025-12-11
  50. */
  51. public function getViolationStoreData($message_data)
  52. {
  53. $EmployeeModel = new EmployeeModel();
  54. $ViolationStoreModel = new ViolationStoreModel();
  55. $platform = $message_data['platform']; ////多个平台配置
  56. $store_name = $message_data['store_name']; //店铺名称
  57. $company_name = $message_data['company_name']; //公司名称
  58. $social_credit_code = $message_data['social_credit_code']; //信用代码
  59. $store_type = $message_data['store_type']; //店铺类型:1=黑名单2=白名单
  60. $executeLog_id = $message_data['executeLog_id'];
  61. $limit = isset($message_data['limit']) ? $message_data['limit'] : 50;
  62. $page = isset($message_data['page']) ? $message_data['page'] : 1;
  63. $product_datas = []; //商品数据
  64. if (empty($product_datas)) {
  65. (new ExecuteLogModel())->where('id', $executeLog_id)->update(['status' => 0]);
  66. return false;
  67. }
  68. foreach ($product_datas as $product_data) {
  69. $insert_product_data = [
  70. 'platform' => $product_data['platform'],
  71. 'company_name' => $product_data['company_name'],
  72. 'social_credit_code' => $product_data['social_credit_code'],
  73. 'store_name' => $product_data['store_name'],
  74. 'link_url' => $product_data['link_url'],
  75. 'store_name' => $product_data['store_name'],
  76. ];
  77. //查询配置的第一责任人
  78. $where_query1[] = ['city_ids', 'like', '%,' . $product_data['city_id'] . ',%'];
  79. $where_query1[] = ['status', '=', 1];
  80. $where_query1[] = ['duty_type', 'in', 1]; //责任类型1=第一责任人,2=责任人
  81. $first_responsible_person = $EmployeeModel->where($where_query1)->pluck('id')->implode(',');
  82. $insert_product_data['first_responsible_person'] = $first_responsible_person;
  83. //查询配置的责任人
  84. $where_query2[] = ['city_ids', 'like', '%,' . $product_data['city_id'] . ',%'];
  85. $where_query2[] = ['status', '=', 1];
  86. $where_query2[] = ['duty_type', 'in', 2]; //责任类型1=第一责任人,2=责任人
  87. $responsible_person = $EmployeeModel->where($where_query2)->pluck('id')->implode(',');
  88. $insert_product_data['responsible_person'] = $responsible_person;
  89. //溯源责任人
  90. $source_responsible_person = '';
  91. if ($first_responsible_person && $responsible_person) {
  92. $source_responsible_person = $first_responsible_person . ',' . $responsible_person;
  93. }
  94. $insert_product_data['source_responsible_person'] = $source_responsible_person;
  95. //插入数据
  96. $ViolationStoreModel->addViolationStore($insert_product_data);
  97. }
  98. //继续执行下一页
  99. $message_data['page'] = $page + 1;
  100. $message_data['limit'] = $limit;
  101. ViolationStoreDataJobs::dispatch($message_data);
  102. }
  103. public function failed(\Throwable $exception)
  104. {
  105. Log::info('job_error', '数据清洗-违规店铺清洗数据队列完全失败', ['data' => $this->message_data, 'error' => $exception]);
  106. }
  107. }