Kaynağa Gözat

添加tt的cbt运单模式

lvhao 2 gün önce
ebeveyn
işleme
491e4debb7

+ 76 - 1
core/CoreApp/models/Model_apitt.php

@@ -410,7 +410,82 @@ function __construct(){
 		$post['slpx'] = $matching['wcslpx'];
 		return $post;
 	}
-	
+	public function getExpressCompany($shop,$info){
+		$url = 'https://open-api.tiktokglobalshop.com';
+		$link = "/fulfillment/202309/orders/".trim($info['orderinfo'])."/shipping_services/query";
+		$time = time();
+		$extra_text = json_decode($info['extra_text'],true);
+		$order_line_item_ids = [];
+		foreach($extra_text['line_items'] as $v)
+		{
+			$order_line_item_ids[] = $v['id'];
+		}
+		$post = [
+			"order_line_item_ids"=>$order_line_item_ids,
+			"weight"=>[
+				"value"=>"400",
+    			"unit"=>"GRAM"
+			],
+			"dimensions"=>[
+				"length"=> "15",
+				"width"=> "10",
+				"height"=> "5",
+				"unit"=> "CM"
+			]
+		];
+		$queryParams['shop_cipher'] =$shop['shop_cipher'];
+		$queryParams['app_key'] =$shop['app_key'];
+		$queryParams['timestamp'] =$time;
+		$link .= '?'.http_build_query($queryParams);
+		$sign = $this->sign($link,$shop['app_secret'],$post);
+		$url .= $link.'&sign='.$sign;
+		$headers = array('Content-Type: application/json','x-tts-access-token:'.$shop['token']);
+		$res = $this->su_curl($post,$url,$headers);
+		$this->logic_ding->sendToDing($info['number']."获取TT快递服务信息".$res);
+		$res = json_decode($res,true);
+		return $res;
+	}
+	//创建运单
+	public function createLabel($info,$shop){
+		$url = 'https://open-api.tiktokglobalshop.com';
+		$link = "/fulfillment/202309/packages";
+		$time = time();
+		$extra_text = json_decode($info['extra_text'],true);
+		//快递服务商
+		$server_info = $extra_text['server_info'];
+		$post = [
+			'order_id'=>$server_info['order_id'],
+			"order_line_item_ids"=>$server_info['order_line_id'],
+			"dimension"=>$server_info['dimension'],
+			"shipping_service_id"=>$server_info['shipping_services'][0]['shipping_service_id'],
+			"weight"=>$server_info['weight'],
+		];
+		$queryParams['shop_cipher'] =$shop['shop_cipher'];
+		$queryParams['app_key'] =$shop['app_key'];
+		$queryParams['timestamp'] =$time;
+		$link .= '?'.http_build_query($queryParams);
+		$sign = $this->sign($link,$shop['app_secret'],$post);
+		$url .= $link.'&sign='.$sign;
+		$headers = array('Content-Type: application/json','x-tts-access-token:'.$shop['token']);
+		$res = $this->su_curl($post,$url,$headers);
+		$this->logic_ding->sendToDing($info['number']."获取TT快递服务信息".$res);
+		$res = json_decode($res,true);
+		return $res;
+	}
+	//下载快递面单
+	public function downloadLabel($package_id,$shop,$info){
+		$url = 'https://open-api.tiktokglobalshop.com';
+		$link = '/fulfillment/202309/packages/'.$package_id.'/shipping_documents';
+		$time = time();
+		$link .= '?shop_cipher='.$shop['shop_cipher'].'&app_key='.$shop['app_key'].'&timestamp='.$time."&document_type=SHIPPING_LABEL";
+		$sign = $this->sign($link,$shop['app_secret'],'');
+		$url .= $link.'&sign='.$sign;
+		$headers = array('Content-Type: application/json','x-tts-access-token:'.$shop['token']);
+		$res = $this->su_curl('',$url,$headers,$date_type='json',$timeout=300,$httptype="GET");
+		$this->logic_ding->sendToDing($info['number']."获取TT快递服务信息".$res);
+		$res = json_decode($res,true);
+		return $res;
+	}
 	public function sign($url,$appSecret,$body='') 
 	{
 		// 解析URL获取查询参数

+ 82 - 16
core/CoreApp/models/Model_express_tt.php

@@ -14,34 +14,100 @@ class Model_express_tt extends Lin_Model {
         $shop_info = $this->db->from('shop')->where('id', $info['shop'])->get()->result_array();
         
         if(empty($shop_info)){
-            return $g = [
+            return  [
                 'x'=>0,
                 'Description'=>'该商铺不存在',
             ];
         }
-        $order_info = $this->getDetail($info['orderinfo'],$shop_info[0]);
-
-    }
-    //查询信息
-    private function getDetail($orderinfo,$shop){
-        
-        $res = $this->apitt->get_data(['577147809833784067','577147808491737854'],$shop);
-        echo "<pre>";
-        print_r($res);
-        die;
+        //获取快递服务信息
+        $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;
+        }
+        $res2 = $this->downloadExpressLabel($res['data'],$shop_info[0]);
+        if($res2['x'] == 0){
+            return $res2;
+        }
+        return  [
+            'x'=>1,
+            'msg'=>'获取成功',
+            'data'=>$info
+        ];
     }
+   
     //获取订单承运的快递商
-    private function getExpressCompany(){
-
+    private function getExpressCompany($info,$shop_info){
+        $res = $this->apitt->getExpressCompany($info,$shop_info);
+        if($res['code'] != 0){
+            return  [
+                'x'=>0,
+                'Description'=>$res['message'],
+            ];
+        }
+        $extra_info = json_decode($info['extra_info'],true);
+        $extra_info['server_info'] = $res['data'];
+        $info['extra_info'] = json_encode($extra_info,JSON_UNESCAPED_UNICODE);
+        $this->db->update('fullordertt', [
+            'extra_info' => $info['extra_info']
+        ], ['id' => $info['id']]) ;
+        return  [
+            'x'=>1,
+            'msg'=>'获取成功',
+            'data'=>$info
+        ];
     }
 
     //创建发货单和运单标签
-    private function createExpressLabel(){
+    private function createExpressLabel($info,$shop_info){
+        $res = $this->apitt->createExpressLabel($info,$shop_info);
+        if($res['code'] != 0){
+            return  [
+                'x'=>0,
+                'Description'=>$res['message'],
+            ];      
+        }
+        $extra_info = json_decode($info['extra_info'],true);
+        $extra_info['label_info'] = $res['data'];
+        $info['extra_info'] = json_encode($extra_info,JSON_UNESCAPED_UNICODE);
+        $this->db->update('fullordertt', [
+            'extra_info' => $info['extra_info']
+        ], ['id' => $info['id']]) ;
+        return  [
+            'x'=>1,
+            'msg'=>'获取成功',
+            'data'=>$info
+        ];
+        
 
     }
     //下载快递面单
-    private function downloadExpressLabel(){
-
+    private function downloadExpressLabel($info,$shop){
+        $extra_info = json_decode($info['extra_info'],true);
+        $packageid = $extra_info['label_info']['packageid'];
+        $res = $this->apitt->downloadLabel($packageid,$shop,$info);
+        if($res['code'] != 0){
+            return  [
+                'x'=>0,
+                'Description'=>$res['message'],
+            ];      
+        } 
+        $extra_info = json_decode($info['extra_info'],true);
+        $extra_info['express_info'] = $res['data'];
+        $info['extra_info'] = json_encode($extra_info,JSON_UNESCAPED_UNICODE);
+        $this->db->update('fullordertt', [
+            'extra_info' => $info['extra_info']
+        ], ['id' => $info['id']]) ;
+        return  [
+            'x'=>1,
+            'msg'=>'获取成功',
+            'waybill'=>$res['data']['tracking_number'],
+            'label'=>$res['data']['doc_url'],
+        ];
+        
     }