message_data = $message_data; } /** * Execute the job. * * @return void */ public function handle() { $page = isset($this->message_data['page']) ? $this->message_data['page'] : 1; $limit = isset($this->message_data['limit']) ? $this->message_data['limit'] : 50; $field = [ 'id', //ID 'manufacturer', //公司名称 'drugname', //药品名称 'specification', //规格 'approval', //批准文号 'comStoreId', //供应商(店铺)ID 'storeName', //供应商(店铺)名称 'minPrice', //最低价 'real_crawler_time', //真实采集时间 'url', //药品详情页url ]; try { $YychengProductModel = new YychengProductModel(); //获取分页数据,多个字段进行分组去重 $yesterdayStart = Carbon::yesterday()->startOfDay()->getTimestamp(); // 昨天开始时间 00:00:00 $yesterdayEnd = Carbon::yesterday()->endOfDay()->getTimestamp(); // 昨天结束时间 23:59:59 $list_config_data = $YychengProductModel->where([['real_crawler_time', '<=', $yesterdayEnd], ['real_crawler_time', '>=', $yesterdayStart]]) ->orderby('id', 'desc')->paginate($limit, $field, 'page', $page)->toarray(); if (!$list_config_data || empty($list_config_data['data'])) { $totle_data = isset($this->message_data['total']) ? $this->message_data['total'] : 0; Log::info('job_info', '采集数据-医药城数据同步队列,执行完毕', ['data' => ['page' => $page, 'limit' => $limit, 'totle' => $totle_data], 'message' => '没有数据可同步']); return true; } $total = $list_config_data['total']; $request_data['data'] = $list_config_data['data']; $request_data['queue_page'] = $page; $request_data['queue_limit'] = $limit; $request_data['queue_total'] = $total; YychengStoreJobs::dispatch($request_data); // YychengStoreJobs::dispatchSync($request_data); $message_data['page'] = (int)$page + 1; $message_data['limit'] = $limit; $message_data['total'] = $total; YychengProductJobs::dispatch($message_data)->delay(now()->addSeconds(10)); //延时10秒执行、防止队列堵塞; Log::info('job_info', '采集数据-医药城数据同步队列日志', ['data' => ['page' => $page, 'limit' => $limit, 'totle' => $total]]); } catch (\Exception $e) { Log::info('job_error', '采集数据-医药城数据同步队列失败', ['error' => $e->getMessage()]); } } public function failed(\Throwable $exception) { Log::info('job_error', '采集数据-医药城数据处理队列完全失败', ['data' => $this->message_data, 'error' => $exception]); } }