LowPriceGoodsJobs.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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\LowPriceGoods as ConfigLowPriceGoodsModel;
  11. use App\Models\Api\Process\ExecuteLog as ExecuteLogModel;
  12. use App\Jobs\Manager\Process\LowPriceGoodsDataJobs;
  13. use App\Models\Manager\WashConfig\ViolationStore as ViolationStoreModel;
  14. use App\Models\Manager\WashConfig\LowPriceGoodsCompany as LowPriceGoodsCompanyModel;
  15. /**
  16. * 数据清洗-低价挂网商品配置队列
  17. * @author 唐远望
  18. * @version 1.0
  19. * @date 2025-12-10
  20. */
  21. class LowPriceGoodsJobs implements ShouldQueue
  22. {
  23. use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
  24. protected $message_data;
  25. /**
  26. * Create a new job instance.
  27. *
  28. * @return void
  29. */
  30. public function __construct(array $message_data)
  31. {
  32. $this->message_data = $message_data;
  33. }
  34. /**
  35. * Execute the job.
  36. *
  37. * @return void
  38. */
  39. public function handle()
  40. {
  41. try {
  42. $ConfigLowPriceGoodsModel = new ConfigLowPriceGoodsModel();
  43. $LowPriceGoodsCompanyModel = new LowPriceGoodsCompanyModel();
  44. $limit = isset($this->message_data['limit']) ? $this->message_data['limit'] : 50;
  45. $page = isset($this->message_data['page']) ? $this->message_data['page'] : 1;
  46. $executeLog_id = isset($this->message_data['executeLog_id']) ? $this->message_data['executeLog_id'] : 0;
  47. $admin_id = isset($this->message_data['admin_id']) ? $this->message_data['admin_id'] : 0;
  48. if ($page == 1) {
  49. $ExecuteLogModel = new ExecuteLogModel();
  50. $insert_data = ['name' => '低价挂网商品', 'code' => 'LowPriceGoodsJobs', 'admin_id' => $admin_id];
  51. $executeLog_id = $ExecuteLogModel->addExecuteLog_content($insert_data);
  52. }
  53. $list_config_data = $ConfigLowPriceGoodsModel->where('status', 0)->paginate($limit, ['*'], 'page', $page)->toarray();
  54. if (!$list_config_data || empty($list_config_data['data'])) {
  55. return true;
  56. }
  57. $list_data = $list_config_data['data'];
  58. foreach ($list_data as $key => $value) {
  59. $company_data = $LowPriceGoodsCompanyModel->where('lowprice_product_logid', $value['id'])
  60. ->join('washconfig_violation_store', 'washconfig_violation_store.id', '=', 'washconfig_lowprice_product_company.company_id')
  61. ->select(['washconfig_violation_store.id', 'washconfig_violation_store.social_credit_code', 'washconfig_lowprice_product_company.company_id'])->get()->toArray();
  62. $social_credit_code = !empty($company_data) ? array_column($company_data, 'social_credit_code') : '';
  63. $message_data = [
  64. 'id' => $value['id'],
  65. 'platform' => $value['platform'],
  66. 'product_name' => $value['product_name'],
  67. 'product_specs' => $value['product_specs'],
  68. 'suggested_price' => $value['suggested_price'],
  69. 'store_scope' => $value['store_scope'],
  70. 'company_scope' => $value['company_scope'],
  71. 'social_credit_code' => $social_credit_code,
  72. 'executeLog_id' => $executeLog_id,
  73. ];
  74. LowPriceGoodsDataJobs::dispatch($message_data);
  75. // LowPriceGoodsDataJobs::dispatchSync($message_data);
  76. }
  77. $now_message_data = [
  78. 'limit' => $limit,
  79. 'page' => $page + 1,
  80. 'executeLog_id' => $executeLog_id,
  81. ];
  82. $this->dispatchSync($now_message_data);
  83. } catch (\Exception $e) {
  84. Log::info('job_error', '数据清洗-低价挂网商品配置队列失败', ['data' => $this->message_data, 'error' => $e->getMessage()]);
  85. }
  86. }
  87. public function failed(\Throwable $exception)
  88. {
  89. Log::info('job_error', '数据清洗-低价挂网商品配置队列完全失败', ['data' => $this->message_data, 'error' => $exception]);
  90. }
  91. }