YychengProductJobs.php 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. namespace App\Jobs\Manager\CollectData\Yycheng;
  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\CollectData\Yycheng\Product as YychengProductModel;
  11. use App\Jobs\Manager\CollectData\Yycheng\YychengStoreJobs;
  12. use Illuminate\Support\Carbon;
  13. /**
  14. * 采集数据-医药城数据同步
  15. * @author 唐远望
  16. * @version 1.0
  17. * @date 2026-02-06
  18. */
  19. class YychengProductJobs 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. $page = isset($this->message_data['page']) ? $this->message_data['page'] : 1;
  40. $limit = isset($this->message_data['limit']) ? $this->message_data['limit'] : 50;
  41. $field = [
  42. 'id', //ID
  43. 'manufacturer', //公司名称
  44. 'drugname', //药品名称
  45. 'specification', //规格
  46. 'approval', //批准文号
  47. 'comStoreId', //供应商(店铺)ID
  48. 'storeName', //供应商(店铺)名称
  49. 'minPrice', //最低价
  50. 'real_crawler_time', //真实采集时间
  51. 'url', //药品详情页url
  52. ];
  53. try {
  54. $YychengProductModel = new YychengProductModel();
  55. //获取分页数据,多个字段进行分组去重
  56. $yesterdayStart = Carbon::yesterday()->startOfDay()->getTimestamp(); // 昨天开始时间 00:00:00
  57. $yesterdayEnd = Carbon::yesterday()->endOfDay()->getTimestamp(); // 昨天结束时间 23:59:59
  58. $list_config_data = $YychengProductModel->where([['real_crawler_time', '<=', $yesterdayEnd], ['real_crawler_time', '>=', $yesterdayStart]])
  59. ->orderby('id', 'desc')->paginate($limit, $field, 'page', $page)->toarray();
  60. if (!$list_config_data || empty($list_config_data['data'])) {
  61. $totle_data = isset($this->message_data['total']) ? $this->message_data['total'] : 0;
  62. Log::info('job_info', '采集数据-医药城数据同步队列,执行完毕', ['data' => ['page' => $page, 'limit' => $limit, 'totle' => $totle_data], 'message' => '没有数据可同步']);
  63. return true;
  64. }
  65. $total = $list_config_data['total'];
  66. $request_data['data'] = $list_config_data['data'];
  67. $request_data['queue_page'] = $page;
  68. $request_data['queue_limit'] = $limit;
  69. $request_data['queue_total'] = $total;
  70. YychengStoreJobs::dispatch($request_data);
  71. // YychengStoreJobs::dispatchSync($request_data);
  72. Log::info('job_info', '采集数据-医药城数据同步队列日志', ['data' => ['page' => $page, 'limit' => $limit, 'totle' => $total]]);
  73. } catch (\Exception $e) {
  74. Log::info('job_error', '采集数据-医药城数据同步队列失败', ['error' => $e->getMessage()]);
  75. }
  76. }
  77. }