ViolationStoreJobs.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. use Illuminate\Support\Carbon;
  14. /**
  15. * 数据清洗-违规挂网店铺配置队列
  16. * @author 唐远望
  17. * @version 1.0
  18. * @date 2025-12-11
  19. */
  20. class ViolationStoreJobs implements ShouldQueue
  21. {
  22. use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
  23. public $tries = 3; // 限制重试次数
  24. public $timeout = 600; // 10分钟超时
  25. protected $message_data;
  26. /**
  27. * Create a new job instance.
  28. *
  29. * @return void
  30. */
  31. public function __construct(array $message_data)
  32. {
  33. $this->message_data = $message_data;
  34. }
  35. /**
  36. * Execute the job.
  37. *
  38. * @return void
  39. */
  40. public function handle()
  41. {
  42. try {
  43. // $start_time = Carbon::today()->startOfDay()->getTimestamp(); // 今天开始时间 00:00:00
  44. $start_time = time() - 60 * 5; // 开始时间 5分钟之前
  45. $end_time = time(); //结束时间
  46. $ViolationStoreModel = new ViolationStoreModel();
  47. $limit = isset($this->message_data['limit']) ? $this->message_data['limit'] : 50;
  48. $page = isset($this->message_data['page']) ? $this->message_data['page'] : 1;
  49. $executeLog_id = isset($this->message_data['executeLog_id']) ? $this->message_data['executeLog_id'] : 0;
  50. $admin_id = isset($this->message_data['admin_id']) ? $this->message_data['admin_id'] : 0;
  51. $is_admin = isset($this->message_data['is_admin']) ? $this->message_data['is_admin'] : 0;
  52. $company_id = isset($this->message_data['company_id']) ? $this->message_data['company_id'] : 0;
  53. if($page == 1){
  54. $ExecuteLogModel = new ExecuteLogModel();
  55. $insert_data =['company_id'=>$company_id,'name' =>'违规挂网店铺', 'code' => 'ViolationStoreJobs', 'admin_id' => $admin_id,'is_admin' => $is_admin];
  56. $executeLog_id=$ExecuteLogModel->addExecuteLog_content($insert_data);
  57. }
  58. $ViolationStoreModel = $ViolationStoreModel->where('status', 0)->where('store_type', 1);
  59. if($company_id){
  60. $ViolationStoreModel = $ViolationStoreModel->where('company_id', $company_id);
  61. }
  62. $totle_page = 0;
  63. $list_config_data = $ViolationStoreModel->paginate($limit, ['*'], 'page', $page)->toarray();
  64. if (!$list_config_data || empty($list_config_data['data'])) {
  65. if($page == 1 && $executeLog_id){
  66. $ExecuteLogModel->where('id', $executeLog_id)->update(['status' => 0,'update_time'=> time()]);
  67. }
  68. return true;
  69. }
  70. $totle_page = $list_config_data['last_page'];
  71. $list_data = $list_config_data['data'];
  72. foreach ($list_data as $key => $value) {
  73. $message_data = [
  74. 'company_id' => $value['company_id'],
  75. 'id' => $value['id'],
  76. 'platform' => $value['platform'],
  77. 'store_type' => $value['store_type'],
  78. 'store_name' => $value['store_name'],
  79. 'employee_ids' => $value['employee_ids'],
  80. 'executeLog_id' => $executeLog_id,
  81. 'specify_responsible_person' => $value['specify_responsible_person'],
  82. 'item_totle_page' => $totle_page,
  83. 'item_now_page' => $page,
  84. 'start_time' => $start_time,
  85. 'end_time' => $end_time,
  86. ];
  87. ViolationStoreDataJobs::dispatch($message_data);
  88. // ViolationStoreDataJobs::dispatchSync($message_data);
  89. }
  90. $now_message_data = [
  91. 'limit' => $limit,
  92. 'page' => $page + 1,
  93. 'executeLog_id' => $executeLog_id,
  94. ];
  95. ViolationStoreJobs::dispatch($now_message_data)->delay(now()->addSeconds(3));
  96. } catch (\Exception $e) {
  97. Log::info('job_error', '数据清洗-违规挂网店铺队列失败', ['data' => $this->message_data, 'error' => $e->getMessage()]);
  98. }
  99. }
  100. public function failed(\Throwable $exception)
  101. {
  102. Log::info('job_error', '数据清洗-违规挂网店铺队列完全失败', ['data' => $this->message_data, 'error' => $exception->getMessage()]);
  103. }
  104. }