Parcourir la source

快递订单状态查询

dong025 il y a 2 jours
Parent
commit
d0905b808e

+ 87 - 3
app/admin/command/FengSu.php

@@ -68,7 +68,7 @@ class FengSu extends Command
     {
         $output->writeln('开始同步订单');
 
-        $resquet = $this->getOrderList('');
+        $resquet = $this->getOrderList();
         if ($resquet['code'] == 0) {
             $fengsu = [];
             $fengsu = Cache::get('fengsu_'.$this->platform);
@@ -127,7 +127,7 @@ class FengSu extends Command
         $output->writeln('ok');
     }
 
-    public function getOrderList($platform = '')
+    public function getOrderList()
     {
         $client = new \GuzzleHttp\Client([
             'verify' => false,
@@ -139,7 +139,7 @@ class FengSu extends Command
             'Accept' => ' application/json, text/plain, */*',
             'Authorization' => site_config("addonsd.authorization_token"),
             'Host' => ' fsdy2.fengsutb.com',
-            'platform' => $platform,
+            'platform' => $this->platform,
             'Content-Type' => ' application/json'
         ];
 
@@ -262,6 +262,7 @@ class FengSu extends Command
             return null;
         }
     }
+    
     public function insertOrder($order_list)
     {
         if (!(count($order_list) > 0)) {
@@ -373,6 +374,89 @@ class FengSu extends Command
         
         
     }
+
+
+    public function get_fengsu_order($platform,$waybill_no){
+        $resquet = $this->get_fengsu_order_list($platform,$waybill_no);
+        return $resquet;
+    }
+
+    // 获取指定订单号
+    public function get_fengsu_order_list($platform,$waybill_no){
+        $client = new \GuzzleHttp\Client([
+            'verify' => false,
+            // 或指定证书路径
+            // 'verify' => '/path/to/cacert.pem'
+        ]);
+
+        $headers = [
+            'Accept' => ' application/json, text/plain, */*',
+            'Authorization' => site_config("addonsd.authorization_token"),
+            'Host' => ' fsdy2.fengsutb.com',
+            'platform' => $platform,
+            'Content-Type' => ' application/json'
+        ];
+
+        $todayTime = date("Y-m-d");
+        $startTime_stamp = 0;
+        $endTime_stamp = strtotime($todayTime . '23:59:59');
+        $pageNum = 1;
+
+        $startTime = date('Y-m-d H:i:s', $startTime_stamp);
+        $endTime = date('Y-m-d H:i:s', $endTime_stamp);
+        
+        $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'   => [$waybill_no]
+        ];
+        // 'waybillNos'   => ['73589756512463']
+        $body = json_encode($body);
+
+        $request = new Request('POST', $this->url, $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->set_fengsu_Authorization($client);
+                    }
+                }
+            }
+            var_dump($e->getMessage());
+            return null;
+        }
+    }
 }
 //风速接口返回格式
 //            {

+ 13 - 1
app/admin/command/TaskDy.php

@@ -55,6 +55,7 @@ class TaskDy extends Command
     // 打单平台 1:风速  2:聚水潭
     protected $type_id = 1;
 
+    
     //时间间隔
     protected $start_end_space_time = 10 * 60;
     //下一次时间间隔
@@ -62,6 +63,7 @@ class TaskDy extends Command
 
     protected $fengSu_command=null;
 
+
     // 指令配置
     protected function configure()
     {
@@ -69,6 +71,15 @@ class TaskDy extends Command
         $this->setName('task_'.$this->platform)->setDescription('the task command');
     }
 
+    public function getProtectedVars() {
+        $this->headers['Authorization']=site_config("addonsd.authorization_token");
+        return [
+            'url' => $this->url,
+            'headers' => $this->headers,
+            'platform' => $this->platform
+        ];
+    }
+
     //根据shop_id
     protected function execute(Input $input, Output $output)
     {
@@ -133,7 +144,7 @@ class TaskDy extends Command
         $output->writeln('ok');
     }
 
-    public function getOrderList($platform = 'pdd')
+    public function getOrderList($platform = '')
     {
         $client = new \GuzzleHttp\Client([
             'verify' => false,
@@ -247,4 +258,5 @@ class TaskDy extends Command
     }
     
     
+    
 }

+ 1 - 1
app/admin/command/TaskJd.php

@@ -145,7 +145,7 @@ class TaskJd extends Command
         $output->writeln('ok');
     }
 
-    public function getOrderList($platform = 'pdd')
+    public function getOrderList($platform = '')
     {
         $client = new \GuzzleHttp\Client([
             'verify' => false,

+ 1 - 1
app/admin/command/TaskKs.php

@@ -145,7 +145,7 @@ class TaskKs extends Command
         $output->writeln('ok');
     }
 
-    public function getOrderList($platform = 'pdd')
+    public function getOrderList($platform = '')
     {
         $client = new \GuzzleHttp\Client([
             'verify' => false,

+ 1 - 1
app/admin/command/TaskPdd.php

@@ -147,7 +147,7 @@ class TaskPdd extends Command
         $output->writeln('ok');
     }
 
-    public function getOrderList($platform = 'pdd')
+    public function getOrderList($platform = '')
     {
         $client = new \GuzzleHttp\Client([
             'verify' => false,

+ 1 - 1
app/admin/command/TaskSph.php

@@ -146,7 +146,7 @@ class TaskSph extends Command
         $output->writeln('ok');
     }
 
-    public function getOrderList($platform = 'pdd')
+    public function getOrderList($platform = '')
     {
         $client = new \GuzzleHttp\Client([
             'verify' => false,

+ 1 - 1
app/admin/command/TaskTb.php

@@ -146,7 +146,7 @@ class TaskTb extends Command
         $output->writeln('ok');
     }
 
-    public function getOrderList($platform = 'pdd')
+    public function getOrderList($platform = '')
     {
         $client = new \GuzzleHttp\Client([
             'verify' => false,

+ 1 - 1
app/admin/command/TaskXhs.php

@@ -145,7 +145,7 @@ class TaskXhs extends Command
         $output->writeln('ok');
     }
 
-    public function getOrderList($platform = 'pdd')
+    public function getOrderList($platform = '')
     {
         $client = new \GuzzleHttp\Client([
             'verify' => false,

+ 73 - 43
app/api/controller/Worker.php

@@ -18,7 +18,8 @@ use app\api\controller\GroupUser as GroupUserController;
 use app\common\model\ShopDelivery as ShopDeliveryModel;
 use app\common\model\WorkerOut as WorkerOutModel;
 use app\common\model\PackSpecs as PackSpecsModel;
-
+use app\common\model\ImportList as ImportListModel;
+use app\admin\command\FengSu;
 /**
  * 打包工人相关接口
  */
@@ -128,50 +129,55 @@ class Worker extends Base
             ];
             $sql_data = $this->shopDeliveryModel->where('waybill_no', $data['code'])->find();
             if (!empty($sql_data)) {
-                switch ($sql_data['order_status']) {
-                    case 'TRADE_CLOSED':
-                        $insert_data['order_status']=3;
-                        $insert_data['remark'] = '已退款';
-                        break;
-
-                    default:
-                        if (!empty($sql_data['user_id']) && $sql_data['user_id'] != 0) {
-                            $insert_data['order_status'] = 2;
-                            $insert_data['remark'] = '请勿重复录入';
-                        } else {
-                            $result = $sql_data->save([
-                                'user_id'    =>   $this->userinfo['id'],
-                                'entry_time'    =>    $time,
-                                'updatetime' =>    $time
-                            ]);
-                            if ($result) {
-                                $insert_data['order_status'] = 1;
-                                $insert_data['remark'] = '录入成功';
-                                $insert_data['spec_id'] = $sql_data['spec_id'];
+                $sql_data = $this->get_order_state($sql_data);
+
+                if (false) {
+                    switch ($sql_data['order_status']) {
+                        case 'TRADE_CLOSED':
+                            $insert_data['order_status'] = 3;
+                            $insert_data['remark'] = '已退款';
+                            break;
+
+                        default:
+                            if (!empty($sql_data['user_id']) && $sql_data['user_id'] != 0) {
+                                $insert_data['order_status'] = 2;
+                                $insert_data['remark'] = '请勿重复录入';
                             } else {
-                                $insert_data['remark'] = '录入失败';
+                                $result = $sql_data->save([
+                                    'user_id'    =>   $this->userinfo['id'],
+                                    'entry_time'    =>    $time,
+                                    'updatetime' =>    $time
+                                ]);
+                                if ($result) {
+                                    $insert_data['order_status'] = 1;
+                                    $insert_data['remark'] = '录入成功';
+                                    $insert_data['spec_id'] = $sql_data['spec_id'];
+                                } else {
+                                    $insert_data['remark'] = '录入失败';
+                                }
                             }
-                        }
-
-                        $entry_time = $sql_data['entry_time'];
-                        if (!empty($sql_data['entry_time'])) {
-                            $entry_time = date('Y-m-d H:i:s', $sql_data['entry_time']);
-                        }
-                        switch ($sql_data['incubator']) {
-                            case 1:
-                                $sql_data['incubator_title'] = '单层保温';
-                                break;
-                            case 2:
-                                $sql_data['incubator_title'] = '双层保温';
-                                break;
-                            default:
-                                $sql_data['incubator_title'] = '不是保温箱';
-                                break;
-                        }
-                        $sql_data['entry_time'] = $entry_time;
-                        
-                        break;
+
+                            $entry_time = $sql_data['entry_time'];
+                            if (!empty($sql_data['entry_time'])) {
+                                $entry_time = date('Y-m-d H:i:s', $sql_data['entry_time']);
+                            }
+                            switch ($sql_data['incubator']) {
+                                case 1:
+                                    $sql_data['incubator_title'] = '单层保温';
+                                    break;
+                                case 2:
+                                    $sql_data['incubator_title'] = '双层保温';
+                                    break;
+                                default:
+                                    $sql_data['incubator_title'] = '不是保温箱';
+                                    break;
+                            }
+                            $sql_data['entry_time'] = $entry_time;
+
+                            break;
+                    }
                 }
+
                 $insert_data['order_data'] = $sql_data;
             }
             $result = $scanLog->save($insert_data);
@@ -189,7 +195,31 @@ class Worker extends Base
         }
         $this->success('', $insert_data);
     }
-
+    //接口判断订单状态
+    public function get_order_state($item)
+    {
+        if(!empty($item['waybill_no'])){
+            
+            $importListModel=new ImportListModel();
+            $item=$importListModel->where("waybill_no",$item['waybill_no'])->find();
+            
+
+            switch ($item['type_id']) {
+                // 1:风速  
+                case 1:
+                    $fengSu=new FengSu();
+                    return $fengSu->get_fengsu_order($item['trade_from'],$item['waybill_no']);
+                    // return $item;
+                    break;
+                //2:聚水潭
+                case 2:
+                    
+                    break;
+            }
+            return $item;
+        }
+        
+    }
     //扫描记录
     public function scanlog(ScanLog $scanLog)
     {