YychengProductJobs.php 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. /**
  13. * 采集数据-医药城数据同步
  14. * @author 唐远望
  15. * @version 1.0
  16. * @date 2026-02-06
  17. */
  18. class YychengProductJobs implements ShouldQueue
  19. {
  20. use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
  21. protected $message_data;
  22. /**
  23. * Create a new job instance.
  24. *
  25. * @return void
  26. */
  27. public function __construct(array $message_data)
  28. {
  29. $this->message_data = $message_data;
  30. }
  31. /**
  32. * Execute the job.
  33. *
  34. * @return void
  35. */
  36. public function handle()
  37. {
  38. $page = isset($this->message_data['page']) ? $this->message_data['page'] : 1;
  39. $limit = isset($this->message_data['limit']) ? $this->message_data['limit'] : 50;
  40. $field = [
  41. 'id', //ID
  42. 'manufacturer', //公司名称
  43. 'drugname', //药品名称
  44. 'specification', //规格
  45. 'approval', //批准文号
  46. 'comStoreId', //供应商(店铺)ID
  47. 'storeName', //供应商(店铺)名称
  48. 'minPrice', //最低价
  49. 'real_crawler_time', //真实采集时间
  50. 'url', //药品详情页url
  51. ];
  52. try {
  53. $YychengProductModel = new YychengProductModel();
  54. //获取分页数据,多个字段进行分组去重
  55. $list_config_data = $YychengProductModel->where([['real_crawler_time', '<', time() - 86400]])
  56. ->orderby('id', 'desc')->paginate($limit, $field, 'page', $page)->toarray();
  57. if (!$list_config_data || empty($list_config_data['data'])) {
  58. $totle_data = isset($this->message_data['total']) ? $this->message_data['total'] : 0;
  59. Log::info('job_info', '采集数据-医药城数据同步队列,执行完毕', ['data' => ['page' => $page, 'limit' => $limit, 'totle' => $totle_data], 'message' => '没有数据可同步']);
  60. return true;
  61. }
  62. $total = $list_config_data['total'];
  63. $request_data['data'] = $list_config_data['data'];
  64. $request_data['queue_page'] = $page;
  65. $request_data['queue_limit'] = $limit;
  66. $request_data['queue_total'] = $total;
  67. YychengStoreJobs::dispatch($request_data);
  68. // YychengStoreJobs::dispatchSync($request_data);
  69. Log::info('job_info', '采集数据-医药城数据同步队列日志', ['data' => ['page' => $page, 'limit' => $limit, 'totle' => $total]]);
  70. } catch (\Exception $e) {
  71. Log::info('job_error', '采集数据-医药城数据同步队列失败', ['error' => $e->getMessage()]);
  72. }
  73. }
  74. }