Procházet zdrojové kódy

添加抖音、拼多多、京东、淘宝、快手、小红书、微信小店同步数据

dong025 před 2 dny
rodič
revize
23a67e7072

+ 9 - 11
app/admin/command/FengSu.php

@@ -47,7 +47,7 @@ class FengSu extends Command
         'Content-Type' => 'application/json',
         // 'platform' => 'dy',
     ];
-
+    protected $platform='dy';
     // 打单平台 1:风速  2:聚水潭
     protected $type_id = 1;
 
@@ -71,7 +71,7 @@ class FengSu extends Command
         $resquet = $this->getOrderList('');
         if ($resquet['code'] == 0) {
             $fengsu = [];
-            $fengsu = Cache::get('fengsu');
+            $fengsu = Cache::get('fengsu_'.$this->platform);
             if ($resquet['data']['list'] != null && !empty($resquet['data']['list'])) {
 
                 $fengsu_pageNum = $fengsu['pageNum'];
@@ -82,7 +82,7 @@ class FengSu extends Command
                     'pageNum' => $fengsu_pageNum,
                     'next_time_space' => $fengsu['next_time_space']
                 ];
-                Cache::set('fengsu', $fengsu);
+                Cache::set('fengsu_'.$this->platform, $fengsu);
 
 
                 $list = $resquet['data']['list'];
@@ -115,7 +115,7 @@ class FengSu extends Command
                 }
 
 
-                Cache::set('fengsu', $fengsu);
+                Cache::set('fengsu_'.$this->platform, $fengsu);
 
 
                 $output->writeln('没有数据');
@@ -165,12 +165,12 @@ class FengSu extends Command
             'next_time_space' => $this->next_time_space
         ];
 
-        $fengsu_cache_data = Cache::get('fengsu');
+        $fengsu_cache_data = Cache::get('fengsu_'.$this->platform);
 
         if (empty($fengsu_cache_data) || $fengsu_cache_data == null) {
-            Cache::set('fengsu', $fengsu);
+            Cache::set('fengsu_'.$this->platform, $fengsu);
         }
-        $fengsu = Cache::get('fengsu');
+        $fengsu = Cache::get('fengsu_'.$this->platform);
 
         // 无数据时,获取数据的开始时间会大于现在的时间,这是一个错误的,会导致一直无法获取数据,开始时间一直往后
         //当开始时间大于现在时间,将开始时间向前调整3分钟
@@ -188,7 +188,7 @@ class FengSu extends Command
                 'next_time_space' => $this->next_time_space
             ];
         }
-        Cache::set('fengsu', $fengsu);
+        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'];
@@ -231,9 +231,7 @@ class FengSu extends Command
         // '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);
+        $request = new Request('POST', $this->url, $headers, $body);
         try {
             $res = $client->sendAsync($request)->wait();
 

+ 191 - 64
app/admin/command/TaskDy.php

@@ -1,4 +1,5 @@
 <?php
+
 /**
  * ----------------------------------------------------------------------------
  * 行到水穷处,坐看云起时
@@ -7,6 +8,7 @@
  * Author: 老成
  * email:85556713@qq.com
  */
+
 declare(strict_types=1);
 
 namespace app\admin\command;
@@ -18,18 +20,24 @@ use think\console\Input;
 use think\console\Output;
 use GuzzleHttp\Client;
 use app\common\model\CrontabLog;
-use app\common\model\FengsuSku;
+use app\common\model\ImportSku;
 use app\common\model\ShopList;
 use app\common\model\ProductConfig;
 use app\common\model\ShopDelivery;
 use app\common\model\CustomerSpec;
 use app\admin\service\FengsuService;
 use GuzzleHttp\Psr7\Request;
+use app\common\model\ImportList;
+use app\admin\service\JuShuiTanService;
+
+use think\facade\Cache;
+use app\common\controller\Http;
 
+use app\admin\command\FengSu;
 //抖音
 class TaskDy extends Command
 {
-    
+
     //抖音请求地址
     protected $url = 'https://fsdy2.fengsutb.com/amount/ship-list-new';
 
@@ -42,82 +50,201 @@ class TaskDy extends Command
         '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:dy')->setDescription('the task command');
+        
+        $this->setName('task_'.$this->platform)->setDescription('the task command');
     }
 
     //根据shop_id
     protected function execute(Input $input, Output $output)
     {
-        dump($this->url);
-        $client = new Client([ 'verify' => false]);
-        $last_time = CrontabLog::getLastRunTime(2);
-        $body = '{
-        "goodType": 2,
-        "goodsFlag": 1,
-        "current": 1,
-        "size": 25,
-        "startTime": "'.$last_time.'",
-        "endTime": "'.date('Y-m-d H:i:s').'",
-        "skuOuterIdExact": false,
-        "skuPropExact": false,
-        "sort": "CONSIGN_TIME",
-        "sortAsc": false,
-        "timeType": 2,
-        "tradeStatus": 2
-        }';
-        //获取Token
-
-        $this->headers['Authorization'] = site_config('addonsd.authorization_token');
-        dump($this->headers['Authorization']);
-        $request = new Request('POST', $this->url, $this->headers, $body);
+        $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'])) {
 
-        dump($request);
+                $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);
 
 
-        $res = $client->sendAsync($request)->wait();
-        if($res->getStatusCode() == 200) {
-            $data = json_decode($res->getBody()->getContents(), true);  
-            $list = $data['data']['list'];
-            if(empty($list)) {
-                $output->writeln('无数据');
-                return;
-            }
-            $queue = [];
-            $shopList = new ShopList();
-            $fengsuSku = new FengsuSku();
-            $productConfig = new ProductConfig();
-            $shopDelivery = new ShopDelivery();
-            $customerSpec = new CustomerSpec();
-            foreach($list as $item) {
-                $status = FengsuService::getAdditionalPrice( $shopList, $fengsuSku, $productConfig, $shopDelivery, $customerSpec, $item);
-                $queue[] = [
-                    'shop_id'       => $item['shopId'],
-                    'trade_from'    => $item['tradeFrom'],
-                    'province'      => $item['receiverProvince'],
-                    'city'          => $item['receiverCity'],
-                    'company_name'  => $item['tradeOrderPrintVos'][0]['companyName'],
-                    'waybill_no'    => $item['waybillNo'],
-                    'consign_time'  => $item['consignTime'],
-                    'goods_id'      => $item['tradeOrderPrintVos'][0]['goodsId'],
-                    'sku_id'        => $item['tradeOrderPrintVos'][0]['skuId'],
-                    'num'           => $item['tradeOrderPrintVos'][0]['total'],
-                    'goods_title'   => $item['tradeOrderPrintVos'][0]['goodsTitle'],
-                    'weigh'         => $item['tradeOrderPrintVos'][0]['weight'],
-                    'price'         => bcdiv((string)$item['payment'], '100', 2),
-                    'status'        => $status,
-                ];
+                $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('没有数据');
             }
-            
-            // 保存到数据库
-            (new FengsuShip())->saveAll($queue);
-            // 更新最后执行时间
-            CrontabLog::create(['type_id' => 2,'last_time' => date('Y-m-d H:i:s')]);
+        } 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;
+        }
+    }
+    
+    
 }

+ 189 - 60
app/admin/command/TaskJd.php

@@ -1,4 +1,5 @@
 <?php
+
 /**
  * ----------------------------------------------------------------------------
  * 行到水穷处,坐看云起时
@@ -7,6 +8,7 @@
  * Author: 老成
  * email:85556713@qq.com
  */
+
 declare(strict_types=1);
 
 namespace app\admin\command;
@@ -18,18 +20,24 @@ use think\console\Input;
 use think\console\Output;
 use GuzzleHttp\Client;
 use app\common\model\CrontabLog;
-use app\common\model\FengsuSku;
+use app\common\model\ImportSku;
 use app\common\model\ShopList;
 use app\common\model\ProductConfig;
 use app\common\model\ShopDelivery;
 use app\common\model\CustomerSpec;
 use app\admin\service\FengsuService;
 use GuzzleHttp\Psr7\Request;
+use app\common\model\ImportList;
+use app\admin\service\JuShuiTanService;
+
+use think\facade\Cache;
+use app\common\controller\Http;
 
+use app\admin\command\FengSu;
 //京东
 class TaskJd extends Command
 {
-    
+
     protected $url = 'https://fsjd.fengsutb.com/amount/ship-list-new';
 
     protected $headers = [
@@ -54,80 +62,201 @@ class TaskJd extends Command
             "User-Agent" => "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/140.0.0.0 Safari/537.36 Edg/140.0.0.0"
     ];
 
+    protected $platform='jd';
+
+    // 打单平台 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:jd')->setDescription('the task command');
+        
+        $this->setName('task_'.$this->platform)->setDescription('the task command');
     }
 
-    //根据
+    //根据shop_id
     protected function execute(Input $input, Output $output)
     {
-        $client = new Client([ 'verify' => false]);
-        $last_time = CrontabLog::getLastRunTime(4);
-        $body = '{
-        "goodType": 2,
-        "goodsFlag": 1,
-        "current": 1,
-        "size": 25,
-        "startTime": "'.$last_time.'",
-        "endTime": "'.date('Y-m-d H:i:s').'",
-        "skuOuterIdExact": false,
-        "skuPropExact": false,
-        "sort": "CONSIGN_TIME",
-        "sortAsc": false,
-        "timeType": 2,
-        "tradeStatus": 2
-        }';
-        //获取Token
-        $this->headers['Authorization'] = site_config('addonsd.authorization_token');
-        $request = new Request('POST', $this->url, $this->headers, $body);
-        $res = $client->sendAsync($request)->wait();
-        if($res->getStatusCode() == 200) {
-            $data = json_decode($res->getBody()->getContents(), true);  
-            $list = $data['data']['list'];
-            if(empty($list)) {
-                $output->writeln('无数据');
-                return;
-            }
-            $queue = [];
-            $shopList = new ShopList();
-            $fengsuSku = new FengsuSku();
-            $productConfig = new ProductConfig();
-            $shopDelivery = new ShopDelivery();
-            $customerSpec = new CustomerSpec();
-            foreach($list as $item) {
-                $status = FengsuService::getAdditionalPrice( $shopList, $fengsuSku, $productConfig, $shopDelivery, $customerSpec, $item);
-                $queue[] = [
-                    'shop_id'       => $item['shopId'],
-                    'trade_from'    => $item['tradeFrom'],
-                    'province'      => $item['receiverProvince'],
-                    'city'          => $item['receiverCity'],
-                    'company_name'  => $item['tradeOrderPrintVos'][0]['companyName'],
-                    'waybill_no'    => $item['waybillNo'],
-                    'consign_time'  => $item['consignTime'],
-                    'goods_id'      => $item['tradeOrderPrintVos'][0]['goodsId'],
-                    'sku_id'        => $item['tradeOrderPrintVos'][0]['skuId'],
-                    'num'           => $item['tradeOrderPrintVos'][0]['total'],
-                    'goods_title'   => $item['tradeOrderPrintVos'][0]['goodsTitle'],
-                    'weigh'         => $item['tradeOrderPrintVos'][0]['weight'],
-                    'price'         => bcdiv((string)$item['payment'], '100', 2),
-                    'status'        => $status,
+        $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('没有数据');
             }
-            
-            // 保存到数据库
-            (new FengsuShip())->saveAll($queue);
-            // 更新最后执行时间
-            CrontabLog::create(['type_id' => 4,'last_time' => date('Y-m-d H:i:s')]);
+        } 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' => 100,
+            '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;
+        }
+    }
+    
+    
 }

+ 190 - 62
app/admin/command/TaskKs.php

@@ -1,4 +1,5 @@
 <?php
+
 /**
  * ----------------------------------------------------------------------------
  * 行到水穷处,坐看云起时
@@ -7,6 +8,7 @@
  * Author: 老成
  * email:85556713@qq.com
  */
+
 declare(strict_types=1);
 
 namespace app\admin\command;
@@ -18,18 +20,24 @@ use think\console\Input;
 use think\console\Output;
 use GuzzleHttp\Client;
 use app\common\model\CrontabLog;
-use app\common\model\FengsuSku;
+use app\common\model\ImportSku;
 use app\common\model\ShopList;
 use app\common\model\ProductConfig;
 use app\common\model\ShopDelivery;
 use app\common\model\CustomerSpec;
 use app\admin\service\FengsuService;
 use GuzzleHttp\Psr7\Request;
+use app\common\model\ImportList;
+use app\admin\service\JuShuiTanService;
+
+use think\facade\Cache;
+use app\common\controller\Http;
 
+use app\admin\command\FengSu;
 //快手
 class TaskKs extends Command
 {
-    
+
     protected $url = 'https://fsks.fengsutb.com/amount/ship-list-new';
 
     protected $headers = [
@@ -53,82 +61,202 @@ class TaskKs extends Command
         "Sec-Fetch-Site" => "same-site",
         "User-Agent" => "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/140.0.0.0 Safari/537.36 Edg/140.0.0.0"
     ];
-    
-    
+
+    protected $platform='ks';
+
+    // 打单平台 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:ks')->setDescription('the task command');
+        
+        $this->setName('task_'.$this->platform)->setDescription('the task command');
     }
 
     //根据shop_id
     protected function execute(Input $input, Output $output)
     {
-        $client = new Client([ 'verify' => false]);
-        $last_time = CrontabLog::getLastRunTime(3);
-        $body = '{
-        "goodType": 2,
-        "goodsFlag": 1,
-        "current": 1,
-        "size": 25,
-        "startTime": "'.$last_time.'",
-        "endTime": "'.date('Y-m-d H:i:s').'",
-        "skuOuterIdExact": false,
-        "skuPropExact": false,
-        "sort": "CONSIGN_TIME",
-        "sortAsc": false,
-        "timeType": 2,
-        "tradeStatus": 2
-        }';
-        //获取Token
-        $this->headers['Authorization'] = site_config('addonsd.authorization_token');
-        $request = new Request('POST', $this->url, $this->headers, $body);
-        $res = $client->sendAsync($request)->wait();
-        if($res->getStatusCode() == 200) {
-            $data = json_decode($res->getBody()->getContents(), true);  
-            $list = $data['data']['list'];
-            if(empty($list)) {
-                $output->writeln('无数据');
-                return;
-            }
-            $queue = [];
-            $shopList = new ShopList();
-            $fengsuSku = new FengsuSku();
-            $productConfig = new ProductConfig();
-            $shopDelivery = new ShopDelivery();
-            $customerSpec = new CustomerSpec();
-            foreach($list as $item) {
-                $status = FengsuService::getAdditionalPrice( $shopList, $fengsuSku, $productConfig, $shopDelivery, $customerSpec, $item);
-                $queue[] = [
-                    'shop_id'       => $item['shopId'],
-                    'trade_from'    => $item['tradeFrom'],
-                    'province'      => $item['receiverProvince'],
-                    'city'          => $item['receiverCity'],
-                    'company_name'  => $item['tradeOrderPrintVos'][0]['companyName'],
-                    'waybill_no'    => $item['waybillNo'],
-                    'consign_time'  => $item['consignTime'],
-                    'goods_id'      => $item['tradeOrderPrintVos'][0]['goodsId'],
-                    'sku_id'        => $item['tradeOrderPrintVos'][0]['skuId'],
-                    'num'           => $item['tradeOrderPrintVos'][0]['total'],
-                    'goods_title'   => $item['tradeOrderPrintVos'][0]['goodsTitle'],
-                    'weigh'         => $item['tradeOrderPrintVos'][0]['weight'],
-                    'price'         => bcdiv((string)$item['payment'], '100', 2),
-                    'status'        => $status,
+        $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('没有数据');
             }
-            
-            // 保存到数据库
-            (new FengsuShip())->saveAll($queue);
-            // 更新最后执行时间
-            CrontabLog::create(['type_id' => 3,'last_time' => date('Y-m-d H:i:s')]);
+        } 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' => 100,
+            '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;
+        }
+    }
+    
+    
 }

+ 186 - 62
app/admin/command/TaskPdd.php

@@ -1,4 +1,5 @@
 <?php
+
 /**
  * ----------------------------------------------------------------------------
  * 行到水穷处,坐看云起时
@@ -7,6 +8,7 @@
  * Author: 老成
  * email:85556713@qq.com
  */
+
 declare(strict_types=1);
 
 namespace app\admin\command;
@@ -18,19 +20,24 @@ use think\console\Input;
 use think\console\Output;
 use GuzzleHttp\Client;
 use app\common\model\CrontabLog;
-use app\common\model\FengsuSku;
+use app\common\model\ImportSku;
 use app\common\model\ShopList;
 use app\common\model\ProductConfig;
 use app\common\model\ShopDelivery;
 use app\common\model\CustomerSpec;
 use app\admin\service\FengsuService;
-
 use GuzzleHttp\Psr7\Request;
+use app\common\model\ImportList;
+use app\admin\service\JuShuiTanService;
 
+use think\facade\Cache;
+use app\common\controller\Http;
+
+use app\admin\command\FengSu;
 //拼多多
 class TaskPdd extends Command
 {
-    
+
     //拼多多请求地址
     protected $url = 'https://fsfxpdd.fengsutb.com/amount/ship-list-new';
 
@@ -57,84 +64,201 @@ class TaskPdd extends Command
         'X-Pdd-Pagecode' => '62f9d7a661b14717564e309aebbb4d47f8988f758f91',
         'X-Pdd-Pati'     => 'D08NxRGxLLD5hYKZU1nqgE2b9IVrGjdv',
     ];
-    
-    
+    protected $platform='pdd';
+
+    // 打单平台 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:pdd')->setDescription('the task command');
+        
+        $this->setName('task_'.$this->platform)->setDescription('the task command');
     }
 
     //根据shop_id
     protected function execute(Input $input, Output $output)
     {
-        $client = new Client([ 'verify' => false]);
-        $last_time = CrontabLog::getLastRunTime(1);
-        $body = '{
-        "goodType": 2,
-        "goodsFlag": 1,
-        "current": 1,
-        "size": 25,
-        "startTime": "'.$last_time.'",
-        "endTime": "'.date('Y-m-d H:i:s').'",
-        "skuOuterIdExact": false,
-        "skuPropExact": false,
-        "sort": "CONSIGN_TIME",
-        "sortAsc": false,
-        "timeType": 2,
-        "tradeStatus": 2
-        }';
-        //获取Token
-        $this->headers['Authorization'] = site_config('addonsd.authorization_token');
-        $request = new Request('POST', $this->url, $this->headers, $body);
-        $res = $client->sendAsync($request)->wait();
-        if($res->getStatusCode() == 200) {
-            $data = json_decode($res->getBody()->getContents(), true);  
-            $list = $data['data']['list'];
-            if(empty($list)) {
-                $output->writeln('无数据');
-                return;
-            }
-            $queue = [];
-            $shopList = new ShopList();
-            $fengsuSku = new FengsuSku();
-            $productConfig = new ProductConfig();
-            $shopDelivery = new ShopDelivery();
-            $customerSpec = new CustomerSpec();
-            foreach($list as $item) {
-                $status = FengsuService::getAdditionalPrice( $shopList, $fengsuSku, $productConfig, $shopDelivery, $customerSpec, $item);
-                $queue[] = [
-                    'shop_id'       => $item['shopId'],
-                    'trade_from'    => $item['tradeFrom'],
-                    'province'      => $item['receiverProvince'],
-                    'city'          => $item['receiverCity'],
-                    'company_name'  => $item['tradeOrderPrintVos'][0]['companyName'],
-                    'waybill_no'    => $item['waybillNo'],
-                    'consign_time'  => $item['consignTime'],
-                    'goods_id'      => $item['tradeOrderPrintVos'][0]['goodsId'],
-                    'sku_id'        => $item['tradeOrderPrintVos'][0]['skuId'],
-                    'num'           => $item['tradeOrderPrintVos'][0]['total'],
-                    'goods_title'   => $item['tradeOrderPrintVos'][0]['goodsTitle'],
-                    'weigh'         => $item['tradeOrderPrintVos'][0]['weight'],
-                    'price'         => bcdiv((string)$item['payment'], '100', 2),
-                    'status'        => $status,
+        $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('没有数据');
             }
-            
-            // 保存到数据库
-            (new FengsuShip())->saveAll($queue);
-            // 更新最后执行时间
-            CrontabLog::create(['type_id' => 1,'last_time' => date('Y-m-d H:i:s')]);
+        } 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' => 100,
+            '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;
+        }
+    }
+    
+    
 }

+ 263 - 0
app/admin/command/TaskSph.php

@@ -0,0 +1,263 @@
+<?php
+
+/**
+ * ----------------------------------------------------------------------------
+ * 行到水穷处,坐看云起时
+ * 开发软件,找贵阳云起信息科技,官网地址:https://www.56q7.com/
+ * ----------------------------------------------------------------------------
+ * Author: 老成
+ * email:85556713@qq.com
+ */
+
+declare(strict_types=1);
+
+namespace app\admin\command;
+
+use app\common\model\FengsuShip;
+
+use think\console\Command;
+use think\console\Input;
+use think\console\Output;
+use GuzzleHttp\Client;
+use app\common\model\CrontabLog;
+use app\common\model\ImportSku;
+use app\common\model\ShopList;
+use app\common\model\ProductConfig;
+use app\common\model\ShopDelivery;
+use app\common\model\CustomerSpec;
+use app\admin\service\FengsuService;
+use GuzzleHttp\Psr7\Request;
+use app\common\model\ImportList;
+use app\admin\service\JuShuiTanService;
+
+use think\facade\Cache;
+use app\common\controller\Http;
+
+use app\admin\command\FengSu;
+//微信小店
+class TaskSph extends Command
+{
+
+    //微信小店请求地址
+    protected $url = 'https://fsxpt.fengsutb.com/amount/ship-list-new';
+
+    //请求头部
+    protected $headers = [
+            'Accept'=> "application/json, text/plain, */*",
+            'Accept-Encoding'=> "gzip, deflate, br, zstd",
+            'Accept-Language'=> "zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6",
+            "Authorization"=> "Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJhZmEiLCJuaWtlIjoi6Zi_5Y-R5rWL6YCfIiwiY3JlYXRlZCI6MTc1ODc5MDI4NDU3OSwiZHBJZCI6MTkxOTQwLCJleHAiOjE3NTkwNDk0ODQsImVuYWJsZWQiOnRydWUsImF1dGhvcml0aWVzIjpbInpodXlvbmdodSJdLCJkcEFjY291bnRJZCI6MTc4MzU3fQ.TuHvPz7Jf0vuYsbrxX9VpyZ2oOrtZ0YzLQJafoX_RV8up1PmtPLfPATBE93_v_1Ig39nODadaTb4aePy3b0hsA",
+            "Cache-Control"=> "no-cache",
+            "Content-Type"=> "application/json",
+            "Origin"=> "https://fx.fengsutb.com",
+            "platform" => "sph",
+            "Pragma"=> "no-cache",
+            "priority" => "u=1, i",
+            "Referer"=> "https://fx.fengsutb.com/",
+            "Sec-ch-ua" => '"Chromium";v="140", "Not=A?Brand";v="24", "Microsoft Edge";v="140"',
+            "Sec-ch-ua-Mobile"=> "?0",
+            "Sec-ch-ua-platform"=> "Windows",
+            "Sec-Fetch-Dest" => "empty",
+            "Sec-Fetch-Mode" => "cors",
+            "Sec-Fetch-Site" => "same-site",
+            "User-Agent" => "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/140.0.0.0 Safari/537.36 Edg/140.0.0.0"
+    ];
+
+    protected $platform='sph';
+
+    // 打单平台 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' => 100,
+            '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;
+        }
+    }
+    
+    
+}

+ 192 - 62
app/admin/command/TaskTb.php

@@ -1,4 +1,5 @@
 <?php
+
 /**
  * ----------------------------------------------------------------------------
  * 行到水穷处,坐看云起时
@@ -7,6 +8,7 @@
  * Author: 老成
  * email:85556713@qq.com
  */
+
 declare(strict_types=1);
 
 namespace app\admin\command;
@@ -18,18 +20,24 @@ use think\console\Input;
 use think\console\Output;
 use GuzzleHttp\Client;
 use app\common\model\CrontabLog;
-use app\common\model\FengsuSku;
+use app\common\model\ImportSku;
 use app\common\model\ShopList;
 use app\common\model\ProductConfig;
 use app\common\model\ShopDelivery;
 use app\common\model\CustomerSpec;
 use app\admin\service\FengsuService;
 use GuzzleHttp\Psr7\Request;
+use app\common\model\ImportList;
+use app\admin\service\JuShuiTanService;
+
+use think\facade\Cache;
+use app\common\controller\Http;
 
+use app\admin\command\FengSu;
 //淘宝
 class TaskTb extends Command
 {
-   
+
     //淘宝请求地址
     protected $url = 'https://fszntb.zhifeiyun.cn/amount/ship-list-new';
 
@@ -54,80 +62,202 @@ class TaskTb extends Command
             "Sec-Fetch-Site" => "same-site",
             "User-Agent" => "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/140.0.0.0 Safari/537.36 Edg/140.0.0.0"
     ];
-    
-   
+
+    protected $platform='tb';
+
+    // 打单平台 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:tb')->setDescription('the task command');
+        
+        $this->setName('task_'.$this->platform)->setDescription('the task command');
     }
 
     //根据shop_id
     protected function execute(Input $input, Output $output)
     {
-        $client = new Client([ 'verify' => false]);
-        $last_time = CrontabLog::getLastRunTime(0);
-        $body = '{
-        "goodType": 2,
-        "goodsFlag": 1,
-        "current": 1,
-        "size": 25,
-        "startTime": "'.$last_time.'",
-        "endTime": "'.date('Y-m-d H:i:s').'",
-        "skuOuterIdExact": false,
-        "skuPropExact": false,
-        "sort": "CONSIGN_TIME",
-        "sortAsc": false,
-        "timeType": 2,
-        "tradeStatus": 2
-        }';
-        //获取Token
-        $this->headers['Authorization'] = site_config('addonsd.authorization_token');
-        $request = new Request('POST', $this->url, $this->headers, $body);
-        $res = $client->sendAsync($request)->wait();
-        if($res->getStatusCode() == 200) {
-            $data = json_decode($res->getBody()->getContents(), true);  
-            $list = $data['data']['list'];
-            if(empty($list)) {
-                $output->writeln('无数据');
-                return;
-            }
-            $queue = [];
-            $shopList = new ShopList();
-            $fengsuSku = new FengsuSku();
-            $productConfig = new ProductConfig();
-            $shopDelivery = new ShopDelivery();
-            $customerSpec = new CustomerSpec();
-            foreach($list as $item) {
-                $status = FengsuService::getAdditionalPrice( $shopList, $fengsuSku, $productConfig, $shopDelivery, $customerSpec, $item);
-                $queue[] = [
-                    'shop_id'       => $item['shopId'],
-                    'trade_from'    => $item['tradeFrom'],
-                    'province'      => $item['receiverProvince'],
-                    'city'          => $item['receiverCity'],
-                    'company_name'  => $item['tradeOrderPrintVos'][0]['companyName'],
-                    'waybill_no'    => $item['waybillNo'],
-                    'consign_time'  => $item['consignTime'],
-                    'goods_id'      => $item['tradeOrderPrintVos'][0]['goodsId'],
-                    'sku_id'        => $item['tradeOrderPrintVos'][0]['skuId'],
-                    'num'           => $item['tradeOrderPrintVos'][0]['total'],
-                    'goods_title'   => $item['tradeOrderPrintVos'][0]['goodsTitle'],
-                    'weigh'         => $item['tradeOrderPrintVos'][0]['weight'],
-                    'price'         => bcdiv((string)$item['payment'], '100', 2),
-                    'status'        => $status,
+        $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('没有数据');
             }
-            
-            // 保存到数据库
-            (new FengsuShip())->saveAll($queue);
-            // 更新最后执行时间
-            CrontabLog::create(['type_id' => 0,'last_time' => date('Y-m-d H:i:s')]);
+        } 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' => 100,
+            '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;
+        }
+    }
+    
+    
 }

+ 192 - 63
app/admin/command/TaskXhs.php

@@ -1,4 +1,5 @@
 <?php
+
 /**
  * ----------------------------------------------------------------------------
  * 行到水穷处,坐看云起时
@@ -7,6 +8,7 @@
  * Author: 老成
  * email:85556713@qq.com
  */
+
 declare(strict_types=1);
 
 namespace app\admin\command;
@@ -18,19 +20,24 @@ use think\console\Input;
 use think\console\Output;
 use GuzzleHttp\Client;
 use app\common\model\CrontabLog;
-use app\common\model\FengsuSku;
+use app\common\model\ImportSku;
 use app\common\model\ShopList;
 use app\common\model\ProductConfig;
 use app\common\model\ShopDelivery;
 use app\common\model\CustomerSpec;
 use app\admin\service\FengsuService;
-
 use GuzzleHttp\Psr7\Request;
+use app\common\model\ImportList;
+use app\admin\service\JuShuiTanService;
 
-// 小红书
+use think\facade\Cache;
+use app\common\controller\Http;
+
+use app\admin\command\FengSu;
+//小红书
 class TaskXhs extends Command
 {
-    
+
     protected $url = 'https://fsxpt.fengsutb.com/amount/ship-list-new';
 
     protected $headers = [
@@ -54,80 +61,202 @@ class TaskXhs extends Command
             "Sec-Fetch-Site" => "same-site",
             "User-Agent" => "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/140.0.0.0 Safari/537.36 Edg/140.0.0.0"
     ];
-    
-    
+
+    protected $platform='xhs';
+
+    // 打单平台 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:xhs')->setDescription('the task command');
+        
+        $this->setName('task_'.$this->platform)->setDescription('the task command');
     }
 
     //根据shop_id
     protected function execute(Input $input, Output $output)
     {
-        $client = new Client([ 'verify' => false]);
-        $last_time = CrontabLog::getLastRunTime(5);
-        $body = '{
-        "goodType": 2,
-        "goodsFlag": 1,
-        "current": 1,
-        "size": 25,
-        "startTime": "'.$last_time.'",
-        "endTime": "'.date('Y-m-d H:i:s').'",
-        "skuOuterIdExact": false,
-        "skuPropExact": false,
-        "sort": "CONSIGN_TIME",
-        "sortAsc": false,
-        "timeType": 2,
-        "tradeStatus": 2
-        }';
-        //获取Token
-        $this->headers['Authorization'] = site_config('addonsd.authorization_token');
-        $request = new Request('POST', $this->url, $this->headers, $body);
-        $res = $client->sendAsync($request)->wait();
-        if($res->getStatusCode() == 200) {
-            $data = json_decode($res->getBody()->getContents(), true);  
-            $list = $data['data']['list'];
-            if(empty($list)) {
-                $output->writeln('无数据');
-                return;
-            }
-            $queue = [];
-            $shopList = new ShopList();
-            $fengsuSku = new FengsuSku();
-            $productConfig = new ProductConfig();
-            $shopDelivery = new ShopDelivery();
-            $customerSpec = new CustomerSpec();
-            foreach($list as $item) {
-                $status = FengsuService::getAdditionalPrice( $shopList, $fengsuSku, $productConfig, $shopDelivery, $customerSpec, $item);
-                $queue[] = [
-                    'shop_id'       => $item['shopId'],
-                    'trade_from'    => $item['tradeFrom'],
-                    'province'      => $item['receiverProvince'],
-                    'city'          => $item['receiverCity'],
-                    'company_name'  => $item['tradeOrderPrintVos'][0]['companyName'],
-                    'waybill_no'    => $item['waybillNo'],
-                    'consign_time'  => $item['consignTime'],
-                    'goods_id'      => $item['tradeOrderPrintVos'][0]['goodsId'],
-                    'sku_id'        => $item['tradeOrderPrintVos'][0]['skuId'],
-                    'num'           => $item['tradeOrderPrintVos'][0]['total'],
-                    'goods_title'   => $item['tradeOrderPrintVos'][0]['goodsTitle'],
-                    'weigh'         => $item['tradeOrderPrintVos'][0]['weight'],
-                    'price'         => bcdiv((string)$item['payment'], '100', 2),
-                    'status'        => $status,
+        $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('没有数据');
             }
-            
-            // 保存到数据库
-            (new FengsuShip())->saveAll($queue);
-            // 更新最后执行时间
-            CrontabLog::create(['type_id' => 5,'last_time' => date('Y-m-d H:i:s')]);
+        } 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' => 100,
+            '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;
+        }
+    }
+    
+    
 }

+ 0 - 3
app/admin/controller/goods/ImportList.php

@@ -92,9 +92,6 @@ class ImportList extends Backend
                 
                 $trade_from_item_list[$item['trade_from']]=$trade_from;
             }
-            $trade_from_list = [
-                'dy' => '抖音'
-            ];
             $this->assign('trade_from_item_list',  $trade_from_item_list);
             return $this->fetch();
         }

+ 7 - 6
config/console.php

@@ -10,11 +10,12 @@ return [
         'feng_su' => 'app\admin\command\FengSu',
         'ju_shui_tan' => 'app\admin\command\JuShuiTan',
 
-        'Tasktb' => 'app\admin\command\TaskTb', // 淘宝
-        'Taskpdd' => 'app\admin\command\TaskPdd', // 拼多多
-        'Taskdy' => 'app\admin\command\TaskDy', // 抖音
-        'Taskks' => 'app\admin\command\TaskKs', // 快手
-        'Taskjd' => 'app\admin\command\TaskJd', // 京东
-        'Taskxhs' => 'app\admin\command\TaskXhs', // 小红书
+        'task_tb' => 'app\admin\command\TaskTb', // 淘宝
+        'task_pdd' => 'app\admin\command\TaskPdd', // 拼多多
+        'task_dy' => 'app\admin\command\TaskDy', // 抖音
+        'task_ks' => 'app\admin\command\TaskKs', // 快手
+        'task_jd' => 'app\admin\command\TaskJd', // 京东
+        'task_xhs' => 'app\admin\command\TaskXhs', // 小红书
+        'task_sph' => 'app\admin\command\TaskSph', // 微信小店
     ],
 ];