Model_dpdold.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <?php
  2. class Model_Dpdold extends Lin_Model {
  3. function __construct(){
  4. parent::__construct();
  5. }
  6. public function get_data($data)
  7. {
  8. $rs = $this->curlRequest('http://123.207.33.169:8082/selectAuth.htm',"username=XW&password=123456");
  9. $reData = json_decode(str_replace("'", "\"", $rs['result']));
  10. $customer_id = $reData->customer_id;
  11. $customer_userid = $reData->customer_userid;
  12. $product_id = 4461; //产品id 运输方式由APT给出
  13. $format = 'lbl_NL_XIN.frx'; //打印类型
  14. $printType = 1; //打印类型
  15. /**
  16. * 2, 预报订单
  17. */
  18. //预报数据
  19. $count = Array(
  20. 'buyerid' => '',//买家ID
  21. 'consignee_address' => $data['address'],//地址
  22. 'consignee_city' => $data['city'],//城市
  23. 'consignee_mobile' => '',//收货人手机号 选填
  24. 'consignee_name' => $data['name'],//收件人
  25. 'trade_type' => 'ZYXT',//交易类型
  26. 'consignee_postcode' => $data['zipcode'],//邮编
  27. 'consignee_state' => $data['province'],//省/州
  28. 'consignee_telephone' => $data['phone'],//收货人电话 必填
  29. 'country' => $data['lb'],//收货人国家二字码
  30. 'customer_id' => $customer_id,
  31. 'customer_userid' => $customer_userid,
  32. 'orderInvoiceParam' => Array(
  33. '0' => Array
  34. (
  35. 'invoice_amount' => $data['zsbjz'],
  36. 'invoice_pcs' => $data['ts'],
  37. 'invoice_title' => $data['sbpm'],
  38. 'invoice_weight' => sprintf("%.3f",$data['zzl']/$data['ts']),//单条重量
  39. 'item_id' => '',
  40. 'item_transactionid' => '',
  41. 'sku' => $data['zwpm'],
  42. 'sku_code' => $data['zwpm'],
  43. 'hs_code'=> $data['hgbm'],//海关编码
  44. ),
  45. ),
  46. 'order_customerinvoicecode' => $data['number'].'-1',//原单号
  47. 'product_id' => $product_id,
  48. 'weight' => 0,
  49. 'product_imagepath' => '',
  50. 'consignee_email'=>isset($data['email'])?$data['email']:'',
  51. 'consignee_companyname'=>$data['client'],//收件公司
  52. //'order_cargoamount'=>'',//订单实际金额
  53. //'order_insurance'=>'',//保险金额
  54. );
  55. $result = $this->curlRequest('http://123.207.33.169:8082/createOrderApi.htm', "param=" . json_encode($count));
  56. $resultData = json_decode($result['result'], true);
  57. if($resultData['ack'] == 'true')
  58. {
  59. $g = array('x'=>'1','waybill'=>$resultData['tracking_number']);
  60. }
  61. else
  62. {
  63. $resultData['message'] = urldecode($resultData['message']);
  64. $g = array('x'=>'0','Description'=>$resultData['message']);
  65. }
  66. return array($g,$resultData);exit;
  67. }
  68. public function curlRequest($url,$czdata = '')
  69. {
  70. $return = array('state' => 0, 'message' => '', 'result' => '', 'errNo' => 0);
  71. try
  72. {
  73. $ch = curl_init($url);
  74. curl_setopt($ch, CURLOPT_URL, $url);
  75. curl_setopt($ch, CURLOPT_POST, 1);
  76. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  77. curl_setopt($ch, CURLOPT_HTTPHEADER, array(
  78. 'Accept-Language: zh-cn',
  79. 'Connection: Keep-Alive',
  80. 'Cache-Control: no-cache',
  81. 'Content-type: application/x-www-form-urlencoded;charset=UTF-8'));
  82. curl_setopt($ch, CURLOPT_POSTFIELDS, $czdata);
  83. //设置超时时间
  84. curl_setopt($ch, CURLOPT_TIMEOUT, 120);
  85. //API返回数据
  86. $apiResult = curl_exec($ch);
  87. $errNo = curl_errno($ch);
  88. if ($errNo)
  89. {
  90. //返回错误码
  91. $return['errNo'] = $errNo;
  92. $errorStr = curl_error($ch);
  93. switch ((int)$errNo)
  94. {
  95. case 6: //避免一直发邮件 URL报错
  96. break;
  97. case 7: //无法通过 connect() 连接至主机或代理服务器
  98. break;
  99. case 28: //超时
  100. break;
  101. case 56: //接收网络数据失败
  102. break;
  103. default:
  104. break;
  105. }
  106. throw new Exception($errorStr);
  107. }
  108. curl_close($ch);
  109. $return['state'] = 1;
  110. //返回数据
  111. $return['result'] = $apiResult;
  112. }
  113. catch (Exception $e)
  114. {
  115. $return['state'] = 0;
  116. $return['message'] = $e->getMessage();
  117. }
  118. return $return;
  119. }
  120. public function get_manifest($fullorder) //生成发货清单
  121. {
  122. }
  123. public function get_logistics($number)//追踪快递
  124. {
  125. }
  126. } //end class