ViolationStoreJobs.php 3.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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\Api\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. if($page == 1){
  47. $ExecuteLogModel = new ExecuteLogModel();
  48. $insert_data =['name' =>'违规挂网店铺', 'code' => 'ViolationStoreJobs', 'admin_id' => $admin_id,'is_admin' => $is_admin];
  49. $executeLog_id=$ExecuteLogModel->addExecuteLog_content($insert_data);
  50. }
  51. $list_config_data = $ViolationStoreModel->leftjoin('washconfig_company_category', 'washconfig_company_category.id', '=', 'washconfig_violation_store.category_id')
  52. ->where('washconfig_violation_store.status', 0)->where('store_type', 1)->select(['washconfig_violation_store.*','washconfig_company_category.name as category_name'])->paginate($limit, ['*'], 'page', $page)->toarray();
  53. if (!$list_config_data || empty($list_config_data['data'])) {
  54. return true;
  55. }
  56. $list_data = $list_config_data['data'];
  57. foreach ($list_data as $key => $value) {
  58. $message_data = [
  59. 'id' => $value['id'],
  60. 'platform' => $value['platform'],
  61. 'store_name'=> $value['store_name'],
  62. 'store_type' => $value['store_type'],
  63. 'company_name' => $value['company_name'],
  64. 'social_credit_code' => $value['social_credit_code'],
  65. 'executeLog_id' => $executeLog_id,
  66. 'company_category_name' => $value['category_name'],
  67. 'specify_responsible_person' => $value['specify_responsible_person'],
  68. ];
  69. ViolationStoreDataJobs::dispatch($message_data);
  70. // ViolationStoreDataJobs::dispatchSync($message_data);
  71. }
  72. $now_message_data = [
  73. 'limit' => $limit,
  74. 'page' => $page + 1,
  75. 'executeLog_id' => $executeLog_id,
  76. ];
  77. ViolationStoreJobs::dispatch($now_message_data);
  78. } catch (\Exception $e) {
  79. Log::info('job_error', '数据清洗-违规挂网店铺队列失败', ['data' => $this->message_data, 'error' => $e->getMessage()]);
  80. }
  81. }
  82. public function failed(\Throwable $exception)
  83. {
  84. Log::info('job_error', '数据清洗-违规挂网店铺队列完全失败', ['data' => $this->message_data, 'error' => $exception]);
  85. }
  86. }