'fsdy2.fengsutb.com', 'Accept' => 'application/json, text/plain, */*', 'Authorization' => 'Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiIxODYwNTQ1MTExNSIsImRhdGFfcGVybWlzc2lvbiI6InByb2R1Y3RDb3N0IiwibmlrZSI6IjE4NjA1NDUxMTE1IiwiY3JlYXRlZCI6MTc2NDEyNTQwMzQ0OSwiZHBJZCI6MTAwNjczLCJleHAiOjE3NjQ3MzAyMDMsImVuYWJsZWQiOnRydWUsImF1dGhvcml0aWVzIjpbInpodXlvbmdodSJdLCJkcEFjY291bnRJZCI6MTAwNjczfQ.ihv6NRfD2hzU1NQoqttTaZ-mPxqAEXIUICM8MuxVx2tVLEPW9j-uPhHoFz4T3-lH07wTt2ORf1k_SPOQP4PuQg', 'Content-Type' => 'application/json', 'platform' => 'dy', ]; protected $platform='dy'; // 打单平台 1:风速 2:聚水潭 protected $type_id = 1; //时间间隔 protected $start_end_space_time = 10 * 60; //下一次时间间隔 protected $next_time_space = 7 * 60; protected $fengSu_command=null; // 指令配置 protected function configure() { $this->setName('task_'.$this->platform)->setDescription('the task command'); } //根据shop_id protected function execute(Input $input, Output $output) { $output->writeln('开始同步订单'); $this->fengSu_command=new FengSu(); $resquet = $this->getOrderList(''); if ($resquet['code'] == 0) { $fengsu = []; $fengsu = Cache::get('fengsu_'.$this->platform); if ($resquet['data']['list'] != null && !empty($resquet['data']['list'])) { $fengsu_pageNum = $fengsu['pageNum']; $fengsu_pageNum = $fengsu_pageNum + 1; $fengsu = [ 'startTime' => $fengsu['startTime'], 'endTime' => $fengsu['endTime'], 'pageNum' => $fengsu_pageNum, 'next_time_space' => $fengsu['next_time_space'] ]; Cache::set('fengsu_'.$this->platform, $fengsu); $list = $resquet['data']['list']; // dump($list); // return; $this->fengSu_command->insertOrder($list); //dump($resquet); } else { $now_time = time(); if ($fengsu['startTime'] >= $now_time || ($now_time - $fengsu['startTime']) < ($this->next_time_space)) { // dump("超时了"); $pre_time_stamp = $this->next_time_space; $startTime_stamp = $now_time - $pre_time_stamp; $endTime_stamp = $startTime_stamp + $this->start_end_space_time; $fengsu = [ 'startTime' => $startTime_stamp, 'endTime' => $endTime_stamp, 'pageNum' => 1, 'next_time_space' => $fengsu['next_time_space'] ]; } else { $fengsu = [ 'startTime' => $fengsu['startTime'] + $fengsu['next_time_space'], 'endTime' => $fengsu['endTime'] + $fengsu['next_time_space'], 'pageNum' => 1, 'next_time_space' => $fengsu['next_time_space'] ]; } Cache::set('fengsu_'.$this->platform, $fengsu); $output->writeln('没有数据'); } } else { $output->writeln('接口错误: ' . $resquet['message']); } $output->writeln('ok'); } public function getOrderList($platform = 'pdd') { $client = new \GuzzleHttp\Client([ 'verify' => false, // 或指定证书路径 // 'verify' => '/path/to/cacert.pem' ]); $this->headers['Authorization']=site_config("addonsd.authorization_token"); //时间间隔 // $start_end_space_time=10*60; //下一次时间间隔 // $next_time_space=7*60; //将查询分为,"2026-01-05 00:00:00~2026-01-05 00:05:00",查询该区间的订单,但是该时间区间单独数量可能超过50条,为了性能又不能一次性查询太多,从而进行分页查询, //查询不到数据,就往下一个时间区间查询 $todayTime = date("Y-m-d"); $startTime_stamp = strtotime($todayTime . ' 00:00:00'); // $startTime_stamp = strtotime($todayTime . ' 07:20:00'); $endTime_stamp = $startTime_stamp + $this->start_end_space_time; $pageNum = 1; $fengsu = [ 'startTime' => $startTime_stamp, 'endTime' => $endTime_stamp, 'pageNum' => $pageNum, 'next_time_space' => $this->next_time_space ]; $fengsu_cache_data = Cache::get('fengsu_'.$this->platform); if (empty($fengsu_cache_data) || $fengsu_cache_data == null) { Cache::set('fengsu_'.$this->platform, $fengsu); } $fengsu = Cache::get('fengsu_'.$this->platform); // 无数据时,获取数据的开始时间会大于现在的时间,这是一个错误的,会导致一直无法获取数据,开始时间一直往后 //当开始时间大于现在时间,将开始时间向前调整3分钟 $now_time = time(); if ($fengsu['startTime'] >= $now_time || ($now_time - $fengsu['startTime']) < ($this->start_end_space_time - $this->next_time_space)) { // dump("超时了"); $pre_time_stamp = $this->next_time_space; $startTime_stamp = $now_time - $pre_time_stamp; $endTime_stamp = $startTime_stamp + $this->start_end_space_time; $fengsu = [ 'startTime' => $startTime_stamp, 'endTime' => $endTime_stamp, 'pageNum' => 1, 'next_time_space' => $this->next_time_space ]; } Cache::set('fengsu_'.$this->platform, $fengsu); $startTime = date('Y-m-d H:i:s', $fengsu['startTime']); $endTime = date('Y-m-d H:i:s', $fengsu['endTime']); $pageNum = (int)$fengsu['pageNum']; // dump($startTime); $body = [ 'startTime' => $startTime, 'endTime' => $endTime, 'current' => $pageNum, 'goodType' => 2, 'goodsFlag' => 1, 'orderPrefixSelect' => 'waybillNos', 'prepareShip' => 0, 'size' => 200, 'sort' => 'CONSIGN_TIME', 'sortAsc' => true, 'timeType' => 2, 'tradeStatus' => 2, 'skuOuterIdExact' => false, 'skuPropExact' => false, 'tradeSources' => [] ]; // 'waybillNos' => ['73589756512463'] $body = json_encode($body); $request = new Request('POST', $this->url, $this->headers, $body); try { $res = $client->sendAsync($request)->wait(); $json = []; if ($res->getStatusCode() == 200) { $json = json_decode($res->getBody()->getContents(), true); } else { dump($res->getStatusCode(), '接口返回结果'); } return $json; } catch (\Exception $e) { $errorStr = $e->getMessage(); // 定位response:位置 $pos = strpos($errorStr, 'response:'); if ($pos !== false) { // 从response:后开始截取 $jsonPart = substr($errorStr, $pos + strlen('response:')); // 清理空白字符 $jsonPart = preg_replace('/^\s+|\s+$/', '', $jsonPart); $jsonPart = json_decode($jsonPart, true); if (!empty($jsonPart)) { if ($jsonPart['code'] == 401 && $jsonPart['message'] == 'token失效') { $this->fengSu_command->set_fengsu_Authorization($client); } } } var_dump($e->getMessage()); return null; } } }