ViolationStoreJobs.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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->where('status', 0)->where('store_type', 1);
  53. if($company_id){
  54. $ViolationStoreModel = $ViolationStoreModel->where('company_id', $company_id);
  55. }
  56. $totle_page = 0;
  57. $list_config_data = $ViolationStoreModel->paginate($limit, ['*'], 'page', $page)->toarray();
  58. if (!$list_config_data || empty($list_config_data['data'])) {
  59. if($page == 1 && $executeLog_id){
  60. $ExecuteLogModel->where('id', $executeLog_id)->update(['status' => 0,'update_time'=> time()]);
  61. }
  62. return true;
  63. }
  64. $totle_page = $list_config_data['last_page'];
  65. $list_data = $list_config_data['data'];
  66. foreach ($list_data as $key => $value) {
  67. $message_data = [
  68. 'company_id' => $value['company_id'],
  69. 'id' => $value['id'],
  70. 'platform' => $value['platform'],
  71. 'store_type' => $value['store_type'],
  72. 'store_name' => $value['store_name'],
  73. 'executeLog_id' => $executeLog_id,
  74. 'specify_responsible_person' => $value['specify_responsible_person'],
  75. 'item_totle_page' => $totle_page,
  76. 'item_now_page' => $page,
  77. ];
  78. ViolationStoreDataJobs::dispatch($message_data);
  79. // ViolationStoreDataJobs::dispatchSync($message_data);
  80. }
  81. $now_message_data = [
  82. 'limit' => $limit,
  83. 'page' => $page + 1,
  84. 'executeLog_id' => $executeLog_id,
  85. ];
  86. ViolationStoreJobs::dispatch($now_message_data);
  87. } catch (\Exception $e) {
  88. Log::info('job_error', '数据清洗-违规挂网店铺队列失败', ['data' => $this->message_data, 'error' => $e->getMessage()]);
  89. }
  90. }
  91. public function failed(\Throwable $exception)
  92. {
  93. Log::info('job_error', '数据清洗-违规挂网店铺队列完全失败', ['data' => $this->message_data, 'error' => $exception]);
  94. }
  95. }