ViolationStoreJobs.php 4.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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\ViolationStore as ViolationStoreModel;
  11. use App\Models\Manager\Process\ExecuteLog as ExecuteLogModel;
  12. use App\Jobs\Manager\Process\ViolationStoreDataJobs;
  13. /**
  14. * 数据清洗-违规挂网店铺配置队列
  15. * @author 唐远望
  16. * @version 1.0
  17. * @date 2025-12-11
  18. */
  19. class ViolationStoreJobs 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. $ViolationStoreModel = new ViolationStoreModel();
  41. $limit = isset($this->message_data['limit']) ? $this->message_data['limit'] : 50;
  42. $page = isset($this->message_data['page']) ? $this->message_data['page'] : 1;
  43. $executeLog_id = isset($this->message_data['executeLog_id']) ? $this->message_data['executeLog_id'] : 0;
  44. $admin_id = isset($this->message_data['admin_id']) ? $this->message_data['admin_id'] : 0;
  45. $is_admin = isset($this->message_data['is_admin']) ? $this->message_data['is_admin'] : 0;
  46. $company_id = isset($this->message_data['company_id']) ? $this->message_data['company_id'] : 0;
  47. if($page == 1){
  48. $ExecuteLogModel = new ExecuteLogModel();
  49. $insert_data =['company_id'=>$company_id,'name' =>'违规挂网店铺', 'code' => 'ViolationStoreJobs', 'admin_id' => $admin_id,'is_admin' => $is_admin];
  50. $executeLog_id=$ExecuteLogModel->addExecuteLog_content($insert_data);
  51. }
  52. $ViolationStoreModel = $ViolationStoreModel->leftjoin('washconfig_company_category', 'washconfig_company_category.id', '=', 'washconfig_violation_store.category_id')
  53. ->where('washconfig_violation_store.status', 0)->where('store_type', 1)->select(['washconfig_violation_store.*','washconfig_company_category.name as category_name']);
  54. if($company_id){
  55. $ViolationStoreModel = $ViolationStoreModel->where('washconfig_violation_store.company_id', $company_id);
  56. }
  57. $list_config_data = $ViolationStoreModel->paginate($limit, ['*'], 'page', $page)->toarray();
  58. if (!$list_config_data || empty($list_config_data['data'])) {
  59. return true;
  60. }
  61. $list_data = $list_config_data['data'];
  62. foreach ($list_data as $key => $value) {
  63. $message_data = [
  64. 'company_id' => $value['company_id'],
  65. 'id' => $value['id'],
  66. 'platform' => $value['platform'],
  67. 'store_name'=> $value['store_name'],
  68. 'store_type' => $value['store_type'],
  69. 'company_name' => $value['company_name'],
  70. 'social_credit_code' => $value['social_credit_code'],
  71. 'executeLog_id' => $executeLog_id,
  72. 'company_category_name' => $value['category_name'],
  73. 'specify_responsible_person' => $value['specify_responsible_person'],
  74. ];
  75. ViolationStoreDataJobs::dispatch($message_data);
  76. // ViolationStoreDataJobs::dispatchSync($message_data);
  77. }
  78. $now_message_data = [
  79. 'limit' => $limit,
  80. 'page' => $page + 1,
  81. 'executeLog_id' => $executeLog_id,
  82. ];
  83. ViolationStoreJobs::dispatch($now_message_data);
  84. } catch (\Exception $e) {
  85. Log::info('job_error', '数据清洗-违规挂网店铺队列失败', ['data' => $this->message_data, 'error' => $e->getMessage()]);
  86. }
  87. }
  88. public function failed(\Throwable $exception)
  89. {
  90. Log::info('job_error', '数据清洗-违规挂网店铺队列完全失败', ['data' => $this->message_data, 'error' => $exception]);
  91. }
  92. }