writeln("开始更新快递信息====>" . getDateFull()); $nextPage = 1; while (is_numeric($nextPage)) { $resp = (new SaasOrderExpress)->where(["status" => 0])->with(['orders' => function ($query) { $query->with(['poi']); }])->page($nextPage,10)->select(); if ($resp->isEmpty()) { $output->writeln("没有任务啦==".getDateFull()); $nextPage = null; return true; } foreach ($resp as $item) { if (empty($item['orders']['poi'])) { echo getDateFull()."=={$item['order_sn']}==订单对应商家不存在===\n"; continue; } $startTime = $item['orders']['poi']['order_start']??'09:00'; $endTime = $item['orders']['poi']['order_end']??'22:30'; $startTimeStamp = strtotime("Y-m-d {$startTime}:00"); $endTimeStamp = strtotime("Y-m-d {$endTime}:00"); if (time() > $startTimeStamp && time() < $endTimeStamp) { [$state,$expressData] = $this->getExpressData($item['express_sn'],$item['mobile']); if ($state && $item['orders']['is_error'] == 0) { $isDone = false; foreach ($expressData['logisticsTraceDetailList'] as $sk){ if (in_array($sk['logisticsStatus'],['DELIVERING','AGENT_SIGN','SIGN'])) { $isDone = true; } } // if (in_array($expressData['logisticsStatusDesc'],['派件中',"已签收"])) { // 核销订单 if ($isDone) { // 核销订单 $output->writeln("订单进入核销=={$item['order_sn']}=={$item['express_sn']}==".getDateFull()); (new SaasOrderExpress)->where("id",$item['id'])->update(['status' => 1,'last_at' => getDateFull(),'last_msg' => $expressData['logisticsStatusDesc'],'content' => json_encode($expressData['logisticsTraceDetailList'])]); Redis::send("order-done",['order' => $item['order_sn']]); } else { (new SaasOrderExpress)->where("id",$item['id'])->update(['last_msg' => $expressData['logisticsStatusDesc'],'last_at' => getDateFull(),'content' => json_encode($expressData['logisticsTraceDetailList'])]); $output->writeln("查询物流成功=={$item['order_sn']}=={$expressData['logisticsStatusDesc']}==".getDateFull()); } } else { $output->writeln("查询快递信息失败=={$item['order_sn']}=={$item['express_sn']}==".getDateFull()); } } else { echo getDateFull()."==={$item['order_sn']}===不在核销时段==\n"; } } $nextPage = $nextPage+1; $output->writeln("进入下一页=={$nextPage}==".getDateFull()); } } catch (\Throwable $throwable) { echo getDateFull()."===更新快递信息报错\n"; echo $throwable->getFile()."\n"; echo $throwable->getLine()."\n"; echo $throwable->getMessage()."\n"; } return self::SUCCESS; } protected function getExpressData(string $expressNo = "",string $mobile = ""): array { $url = "https://kzexpress.market.alicloudapi.com/api-mall/api/express/query"; $param = [ "expressNo" => $expressNo, "mobile" => substr($mobile,-4) ]; $resp = Http::withHeaders([ "Authorization" => "APPCODE ".sConf("wechat.kd_code") ])->post($url,$param)->array(); if ($resp['code'] <> 200) { return [0,'']; } return [1,$resp['data']]; } }