lvhao před 2 měsíci
rodič
revize
9305291d12

+ 34 - 1
core/CoreApp/controllers/Systemprint.php

@@ -51,6 +51,7 @@ class Systemprint extends Start_Controller {
 		$this->load->_model("Model_logic_ding","logic_ding");
 		$this->load->_model("Model_zxyuntu","zxyuntu");
 		$this->load->_model("Model_logic_order","logic_order");
+		$this->load->_model("Model_itsxb","itsxb");
 	}
 	//定义方法的调用规则 获取URI第二段值
     public function _remap($arg,$arg_array)
@@ -1645,8 +1646,40 @@ class Systemprint extends Start_Controller {
 						$failed = $barcode['Description'];//错误提示
 						$this->$fullorder_name->save(array('print'=>1,'failed'=>$failed),$va[$n]);
 					}
+				}elseif(($fullorder['printcode'] == "3PE_XB")){
+					$barcode = $this->itsxb->get_data($fullorder);
+					if($barcode['x'] == 1)
+					{
+						$bctime = date('Ymd',$time);
+						$Hwaybill = $barcode['waybill'];
+						$Hyd = $this->_pdfurl($barcode['label'],'y-'.$Hwaybill,$bctime);
+						//$Hfp = $this->_pdfurl($barcode['fp'],'f-'.$Hwaybill,$bctime);//保留PDF,不需要打印
+						if(isset($barcode['label']) && isset($Hwaybill))
+						{
+						    if($fullorder['waybill'] != "")
+							{
+								$oldwaybill = $fullorder['oldwaybill'].'-'.date('Ymd',$time).'/'.$fullorder['waybill'];
+							}
+							else
+							{
+								$oldwaybill = $fullorder['oldwaybill'];
+							}
+							$oldwaybill .= '-'.$bctime.'/'.$Hwaybill;
+							$fullorder['printnumber'] = $fullorder['printnumber'] +1;//不能删
+							if($this->$fullorder_name->save(array('waybill'=>$Hwaybill,'waybill2'=>$barcode['waybill2'],'libraryconfirm'=>2,'librarynot'=>'','printtime'=>$time,'printnumber'=>$fullorder['printnumber'],'print'=>3,'oldwaybill'=>$oldwaybill,'oldprinttime'=>$oldprinttime),$va[$n]))
+				   		 	{
+								$type = 1;
+								$pdfnum = 1;
+								$text = array('yd'=>base_url().'data/pdf/'.$bctime.'/y-'.$Hwaybill.'.pdf','mode'=>100);
+							}
+						}
+					}
+					else
+					{
+						$failed = $barcode['Description'];//错误提示
+						$this->$fullorder_name->save(array('print'=>1,'failed'=>$failed),$va[$n]);
+					}
 				}
-				/*********云途结束 */
 				else
 				{
 					$this->$fullorder_name->save(array('print'=>1,'failed'=>'未找到此快递运单接口'),$va[$n]);

+ 200 - 0
core/CoreApp/models/Model_itsxb.php

@@ -0,0 +1,200 @@
+<?php
+/**
+ * 对接的是its的小包
+ */
+class Model_itsxb extends Lin_Model {
+    function __construct(){
+        parent::__construct();
+        $this->load->_model("Model_logic_ding",'logic_ding');
+    }
+    private $usertoken = "1ef5f2dee1084467b6e399238fa88233";
+
+    private  $apikey = "47608e3aca7c41d6af9c454cfa29fd60";
+    private  $appSecret ="a10ad09fdbfe4478b111894099d2ef4e";
+    private  $baseUrl = "http://oms.weiku.com.cn";
+    private  $useUrl =  "http://oms.weiku.com.cn/its-api/cs/api/";
+
+    /**
+     * 获取签名
+     */
+    private function getSign($requestBody,$time){
+        
+        $signStr = $this->apikey.$this->appSecret.$this->usertoken.$time.$requestBody;
+    
+        $sign = md5($signStr);
+    
+        return $sign;
+    }
+    /**
+     * 获取打印单数据
+     */
+    public function get_data($data){
+       
+        $url = $this->useUrl."createOrder";
+        $params = $this->set_params($data);
+        $this->logic_ding->sendToDing("3PE发货单请求的报文"."【".$data['number']."】".json_encode($params,JSON_UNESCAPED_SLASHES));
+        $start_time = time();
+        $res = $this->send($url,$params);
+        $this->logic_ding->sendToDing("3PE发货单返回的报文"."【".$data['number']."】".$res);
+        $res = json_decode($res,true);
+        if(!isset($res['code']) || $res['code']!= 0){
+            $g =array('x'=>'0','Description'=>json_encode($res ,JSON_UNESCAPED_UNICODE));
+            return $g;
+        }
+        $rr = $this->getLabel($res['data']['waybillNo']);
+        $this->logic_ding->sendToDing("3PE发货单获取返回label"."【".$data['number']."】".$rr);
+        $rr = json_decode($rr,true);
+        if(!isset($rr['code']) || $rr['code']!= 0){
+            $g =array('x'=>'0','Description'=>json_encode($rr ,JSON_UNESCAPED_UNICODE));
+            return $g;
+        }
+        $g = array('x'=>'1','waybill'=>$res['data']['deliveryNo'],'waybill2'=>$res['data']['waybillNo'],'label'=>$rr['labelUrl']);
+        $end_time = time();
+        if($g['x'] == 1){
+			if( $end_time - $start_time  > 45){
+				$this->logic_ding->addJobs('outtime_order',['number'=>$data['number']]);
+			}
+		}
+        return $g;
+        
+    }
+    /**
+     * 转化数据格式
+     */
+    private function set_params($data){
+        //WK-EUUK-01 欧洲  WK-US-01 中美   WK-JP-01  日本
+        $shipper = [
+            'shipperName'=>"LongYing",//姓名
+            'shipperCountry'=>"CN",//国家二字简码
+            'shipperProvince'=>'HeNan',//省
+            'shipperCity'=>'Xuchang',//市
+          //  'shipperDistrict'=>'',//区
+            'shipperStreet'=>'Shangji Economic Development Zone',
+            'shipperAddress'=>'LongYingShiYe, Yinghao Rd.',//详细地址
+            'shipperPhone'=>'15939964739',//手机号
+            
+        ];
+        $address = $data['address'];
+        if(!empty($data['address2'])){
+            $address = $address." ".$data['address2'];
+        }
+        $consignee = [
+            'consigneeName'=>$data['name'],//姓名
+            'consigneeCountry'=>$data['lb'],
+            'consigneeProvince'=>$data['province'],
+            'consigneeCity'=>$data['city'],
+            'consigneeAddress'=>$address,
+            'consigneePhone'=>$data['phone'],
+            'consigneePostcode'=>$data['zipcode'],
+            'consigneeEmail'=>$data['email'],
+        ];
+        $unit_weight = $data['zzl'] / $data['ts'];
+        $unit_weight = sprintf("%.2f", $unit_weight);
+        $orderDeclareList = [
+            [
+                'englishName'=>$data['sbpm'],//英文名称
+                'chineseName'=>$data['zwpm'],
+                'quantity'=>$data['ts'],
+                'unitNetWeightD'=> $unit_weight,
+                'unitDeclarePriceD'=>$data['dtsbjz'],
+            ]
+        ];
+        $packageList = [
+            [
+                'packageLengthD'=>15,
+                'packageWidthD'=>10,
+                'packageHeightD'=>5,
+                'packageWeightD'=>$data['zzl'],
+            ]
+        ];
+        $params = [
+            'customerOrderNo'=>$data['number'],
+            'logisticsProductCode'=>'WK-US-01',//中美特快专线  输方式代码/物流产品代码
+            'parcelType'=>11,// 10:包裹/11:PAK 袋/12:文件  包裹类型
+            'taxPayMode'=>11,//税金支付方式 10:DDU/11:DDP
+            'shipper'=>$shipper,
+            'consignee'=>$consignee,
+            'orderDeclareList'=>$orderDeclareList,
+            'packageList'=>$packageList,
+        ];
+        return $params;
+    }
+
+
+
+    public function getLabel($waybill){
+        $url = $this->useUrl."label";
+        $params = [
+            'mergePdf'=>1,
+            'nos'=>[$waybill]
+        ];
+       
+        
+        return $this->send($url,$params);
+        
+    }
+    /**
+     * 获取物流方式   这种用curl比较不友好 还是用post直接查吧
+     */
+    public function getWuliuFs(){
+        echo "<pre>";
+        $url = $this->useUrl."getLogistics";
+        $rr = $this->send($url,"");
+       
+       
+        var_dump($rr);
+        die;
+
+    }
+
+
+    public function send($url , $params){
+       
+        $time = time();
+        
+        // 统一处理参数
+        $params = empty($params) ? '' : json_encode($params,JSON_UNESCAPED_SLASHES);
+        $signature = $this->getSign($params, $time);
+        
+        $headers = [
+            'apikey:'.$this->apikey,
+            'signature:'.$signature,  // 修正拼写
+            'timestamp:'.$time,
+            'usertoken:'.$this->usertoken,
+            'Content-Type:application/json;charset=UTF-8'  // 建议添加
+        ];
+        
+        $ch = curl_init($url);
+        $options = [
+            CURLOPT_RETURNTRANSFER => true,
+            CURLOPT_POST => true,
+            CURLOPT_POSTFIELDS => $params,
+            CURLOPT_HTTPHEADER => $headers,
+            CURLOPT_TIMEOUT => 30,  // 添加超时
+            CURLOPT_CONNECTTIMEOUT => 10,
+            // 生产环境应启用SSL验证
+            // CURLOPT_SSL_VERIFYPEER => true,
+            // CURLOPT_SSL_VERIFYHOST => 2,
+        ];
+        
+        curl_setopt_array($ch, $options);
+        $response = curl_exec($ch);
+        
+        // 检查HTTP状态码
+        // $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
+        // if ($response === false || $httpCode >= 400) {
+        //     $error = curl_error($ch);
+        //     curl_close($ch);
+        //     return [
+        //         "code" => -1,
+        //         "msg" => $error ?: "HTTP $httpCode",
+        //         "http_code" => $httpCode
+        //     ];
+        // }
+        
+        curl_close($ch);
+
+        return $response;
+    }
+
+}