瀏覽代碼

提交tt的快递

lvhao 1 月之前
父節點
當前提交
4959c4b206
共有 1 個文件被更改,包括 67 次插入19 次删除
  1. 67 19
      core/CoreApp/models/Model_express_tt.php

+ 67 - 19
core/CoreApp/models/Model_express_tt.php

@@ -27,24 +27,39 @@ class Model_express_tt extends Lin_Model {
            ];
        }
         if($type == 'CBT'){
-           
-           //获取快递服务信息
-           $res = $this->getExpressCompany($info,$shop_info[0]);
-           if($res['x'] == 0){
-               return $res;
-           }
-           $res1 = $this->createExpressLabel($res['data'],$shop_info[0]);
-           if($res1['x'] == 0){
-               return $res1;
-           }
-           if(is_string($info['extra_text'])){
-               $info['extra_text'] = json_decode($info['extra_text'],true);
-           }
-           if(empty($info['extra_text']['label_info'])){
-                sleep(2);
+           if($info['merge'] == $info['id']){
+                $extra_text = json_decode($info['extra_text'],true);
+                if(is_string($extra_text)){
+                    $extra_text = json_decode($extra_text,true);
+                }
+                if(empty($extra_text['label_info'])){
+                    $res = $this->getDetail([$info['orderinfo']],$shop_info[0]);
+                    if($res['x'] == 0){
+                        return $res;
+                    }
+                    $info = $res['data'];
+                }
+                return $this->downloadCbtConbinLabel($info,$shop_info[0]);
+           }else{
+                //获取快递服务信息
+                $res = $this->getExpressCompany($info,$shop_info[0]);
+                if($res['x'] == 0){
+                    return $res;
+                }
+                $res1 = $this->createExpressLabel($res['data'],$shop_info[0]);
+                if($res1['x'] == 0){
+                    return $res1;
+                }
+                if(is_string($info['extra_text'])){
+                    $info['extra_text'] = json_decode($info['extra_text'],true);
+                }
+                if(empty($info['extra_text']['label_info'])){
+                    sleep(2);
+                }
+                $res2 = $this->downloadExpressLabel($res1['data'],$shop_info[0]);
+                return $res2;
            }
-           $res2 = $this->downloadExpressLabel($res1['data'],$shop_info[0]);
-           return $res2;
+           
           
         }else if($type == 'FBT'){
             $extra_text = json_decode($info['extra_text'],true);
@@ -65,8 +80,6 @@ class Model_express_tt extends Lin_Model {
         }
         
     }
-
-
     private function getFBTOrderDetail($info,$shop_info){
         $res = $this->apitt->get_data([$info['orderinfo']],$shop_info[0]);
         if($res['code'] != 0){
@@ -347,6 +360,41 @@ class Model_express_tt extends Lin_Model {
             'data'=>$info
         ];
     }
+    
+    public function downloadCbtConbinLabel($info,$shop){
+        if(is_string($info['extra_text'])){
+            $extra_text = json_decode($info['extra_text'],true);
+        }else{
+            $extra_text = $info['extra_text'];
+        }
+        $packageid = $extra_text['label_info']['package_id'];
+        $res = $this->apitt->downloadLabel($packageid,$shop,$info);
+        //允许二次请求吧  tiktok接口有时候会返回很奇葩的错误
+        if( empty($res) || $res['code'] != 0){
+            $res = $this->apitt->downloadLabel($packageid,$shop,$info);
+            usleep(100);
+            if(empty($res) || $res['code'] != 0){
+                return  [
+                    'x'=>0,
+                    'Description'=>$res['message'],
+                ]; 
+            }
+                
+        } 
+        $extra_text = json_decode($info['extra_text'],true);
+        $extra_text['express_info'] = $res['data'];
+        $info['extra_text'] = json_encode($extra_text,JSON_UNESCAPED_UNICODE);
+        $this->db->update('fullordertt', [
+            'extra_text' => $info['extra_text']
+        ], ['id' => $info['id']]) ;
+        return  [
+            'x'=>1,
+            'msg'=>'获取成功3',
+            'waybill'=>$res['data']['tracking_number'],
+            'label'=>$res['data']['doc_url'],
+        ];
+        
+    }
     //下载快递面单
     public function downloadExpressLabel($info,$shop){
         if(is_string($info['extra_text'])){