|
|
@@ -31,7 +31,7 @@ use app\common\model\ImportList;
|
|
|
use app\admin\service\JuShuiTanService;
|
|
|
|
|
|
use think\facade\Cache;
|
|
|
-
|
|
|
+use app\common\controller\Http;
|
|
|
//抖音
|
|
|
class FengSu extends Command
|
|
|
{
|
|
|
@@ -52,9 +52,9 @@ class FengSu extends Command
|
|
|
protected $type_id = 1;
|
|
|
|
|
|
//时间间隔
|
|
|
- protected $start_end_space_time=10*60;
|
|
|
+ protected $start_end_space_time = 10 * 60;
|
|
|
//下一次时间间隔
|
|
|
- protected $next_time_space=7*60;
|
|
|
+ protected $next_time_space = 7 * 60;
|
|
|
|
|
|
|
|
|
// 指令配置
|
|
|
@@ -70,19 +70,19 @@ class FengSu extends Command
|
|
|
|
|
|
$resquet = $this->getOrderList('');
|
|
|
if ($resquet['code'] == 0) {
|
|
|
- $fengsu=[];
|
|
|
- $fengsu=Cache::get('fengsu');
|
|
|
- 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']
|
|
|
+ $fengsu = [];
|
|
|
+ $fengsu = Cache::get('fengsu');
|
|
|
+ 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',$fengsu);
|
|
|
+ Cache::set('fengsu', $fengsu);
|
|
|
|
|
|
|
|
|
$list = $resquet['data']['list'];
|
|
|
@@ -93,10 +93,10 @@ class FengSu extends Command
|
|
|
} else {
|
|
|
|
|
|
$now_time = time();
|
|
|
- if ($fengsu['startTime']>=$now_time||($now_time - $fengsu['startTime']) < ($this->next_time_space)) {
|
|
|
+ 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 = [
|
|
|
@@ -105,7 +105,7 @@ class FengSu extends Command
|
|
|
'pageNum' => 1,
|
|
|
'next_time_space' => $fengsu['next_time_space']
|
|
|
];
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
$fengsu = [
|
|
|
'startTime' => $fengsu['startTime'] + $fengsu['next_time_space'],
|
|
|
'endTime' => $fengsu['endTime'] + $fengsu['next_time_space'],
|
|
|
@@ -115,7 +115,7 @@ class FengSu extends Command
|
|
|
}
|
|
|
|
|
|
|
|
|
- Cache::set('fengsu',$fengsu);
|
|
|
+ Cache::set('fengsu', $fengsu);
|
|
|
|
|
|
|
|
|
$output->writeln('没有数据');
|
|
|
@@ -155,30 +155,30 @@ class FengSu extends Command
|
|
|
|
|
|
$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
|
|
|
+ $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');
|
|
|
-
|
|
|
- if(empty($fengsu_cache_data)||$fengsu_cache_data==null){
|
|
|
- Cache::set('fengsu',$fengsu);
|
|
|
+ $fengsu_cache_data = Cache::get('fengsu');
|
|
|
+
|
|
|
+ if (empty($fengsu_cache_data) || $fengsu_cache_data == null) {
|
|
|
+ Cache::set('fengsu', $fengsu);
|
|
|
}
|
|
|
- $fengsu=Cache::get('fengsu');
|
|
|
-
|
|
|
+ $fengsu = Cache::get('fengsu');
|
|
|
+
|
|
|
// 无数据时,获取数据的开始时间会大于现在的时间,这是一个错误的,会导致一直无法获取数据,开始时间一直往后
|
|
|
//当开始时间大于现在时间,将开始时间向前调整3分钟
|
|
|
$now_time = time();
|
|
|
- if ($fengsu['startTime']>=$now_time||($now_time - $fengsu['startTime']) < ($this->start_end_space_time - $this->next_time_space)) {
|
|
|
+ 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;
|
|
|
-
|
|
|
+ $pre_time_stamp = $this->next_time_space;
|
|
|
+
|
|
|
$startTime_stamp = $now_time - $pre_time_stamp;
|
|
|
$endTime_stamp = $startTime_stamp + $this->start_end_space_time;
|
|
|
$fengsu = [
|
|
|
@@ -191,7 +191,7 @@ class FengSu extends Command
|
|
|
Cache::set('fengsu', $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'];
|
|
|
+ $pageNum = (int)$fengsu['pageNum'];
|
|
|
// dump($startTime);
|
|
|
// dump($fengsu);
|
|
|
// $body = [
|
|
|
@@ -207,41 +207,62 @@ class FengSu extends Command
|
|
|
// 'goodsFlag' => 2
|
|
|
// ];
|
|
|
$body = [
|
|
|
- 'startTime' =>$startTime,
|
|
|
+ 'startTime' => $startTime,
|
|
|
// 'startTime' =>'2026-01-03 00:23:00',
|
|
|
'endTime' => $endTime,
|
|
|
// 'endTime' => '2026-01-07 23:30:00',
|
|
|
'current' => $pageNum,
|
|
|
// 'current' => 1,
|
|
|
-
|
|
|
+
|
|
|
'goodType' => 2,
|
|
|
'goodsFlag' => 1,
|
|
|
'orderPrefixSelect' => 'waybillNos',
|
|
|
- 'prepareShip'=>0,
|
|
|
+ 'prepareShip' => 0,
|
|
|
'size' => 50,
|
|
|
'sort' => 'CONSIGN_TIME',
|
|
|
'sortAsc' => true,
|
|
|
-
|
|
|
+
|
|
|
'timeType' => 2,
|
|
|
'tradeStatus' => 2,
|
|
|
'skuOuterIdExact' => false,
|
|
|
'skuPropExact' => false,
|
|
|
'tradeSources' => []
|
|
|
];
|
|
|
- // 'waybillNos' => ['73589756512463']
|
|
|
+ // 'waybillNos' => ['73589756512463']
|
|
|
$body = json_encode($body);
|
|
|
-
|
|
|
+
|
|
|
$request = new Request('POST', 'https://fsdy2.fengsutb.com/amount/ship-list-new', $headers, $body);
|
|
|
+
|
|
|
// $request = new Request('POST', 'https://fsdy2.fengsutb.com/trade/print-list', $headers, $body);
|
|
|
-
|
|
|
- $res = $client->sendAsync($request)->wait();
|
|
|
- $json = [];
|
|
|
- if ($res->getStatusCode() == 200) {
|
|
|
- $json = json_decode($res->getBody()->getContents(), true);
|
|
|
- } else {
|
|
|
- dump($res->getStatusCode(), '接口返回结果');
|
|
|
+ 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->set_fengsu_Authorization($client);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ var_dump($e->getMessage());
|
|
|
+ return null;
|
|
|
}
|
|
|
- return $json;
|
|
|
}
|
|
|
public function insertOrder($order_list)
|
|
|
{
|
|
|
@@ -316,6 +337,44 @@ class FengSu extends Command
|
|
|
// 更新最后执行时间
|
|
|
CrontabLog::create(['type_id' => 2, 'last_time' => date('Y-m-d H:i:s')]);
|
|
|
}
|
|
|
+ //更新风速授权token
|
|
|
+ public function set_fengsu_Authorization($client)
|
|
|
+ {
|
|
|
+ $url = 'https://fx.fengsutb.com/gw/user/login';
|
|
|
+ $headers = [
|
|
|
+ 'Accept' => '*/*',
|
|
|
+ 'Accept-Encoding' => 'gzip, deflate, br',
|
|
|
+ 'User-Agent' => 'PostmanRuntime-ApipostRuntime/1.1.0',
|
|
|
+ 'Connection' => 'keep-alive',
|
|
|
+ 'Content-Type' => 'application/json'
|
|
|
+ ];
|
|
|
+
|
|
|
+ $params = [
|
|
|
+ "mobile" => "data_sync",
|
|
|
+ "password" => "6YZKdG6iO!",
|
|
|
+ "verificationCode" => "2588",
|
|
|
+ "loginType" => "passwordLogin"
|
|
|
+ ];
|
|
|
+
|
|
|
+ $params = json_encode($params);
|
|
|
+
|
|
|
+ $request_login = new Request('POST', $url, $headers, $params);
|
|
|
+ $res = $client->sendAsync($request_login)->wait();
|
|
|
+ $json = [];
|
|
|
+ if ($res->getStatusCode() == 200) {
|
|
|
+ $json = json_decode($res->getBody()->getContents(), true);
|
|
|
+ } else {
|
|
|
+ dump($res->getStatusCode(), '接口返回结果');
|
|
|
+ }
|
|
|
+ if(!empty($json)){
|
|
|
+ if($json['code']==0&&$json['message']=='登录成功!'&&!empty($json['data'])){
|
|
|
+ site_config("addonsd.authorization_token",$json['data']);
|
|
|
+ dump('token更新成功');
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
}
|
|
|
//风速接口返回格式
|
|
|
// {
|