Model_hualei.php 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. <?php
  2. class Model_hualei extends Lin_Model {
  3. function __construct(){
  4. parent::__construct();
  5. }
  6. //渠道 http://123.207.33.169:8082/getProductList.htm
  7. //$ys = 1;//延时获取运单
  8. public function get_data($data)
  9. {
  10. $duty_type = '';//区分快递承担税费人的选项 DDU或DDP ddp好像是收件人承担税费
  11. if($data['printcode'] == "HUALEI-FEDEX")
  12. {
  13. $product_id = 6021;
  14. $link = 'param=';
  15. $ys = 0;//非延时获取运单
  16. }
  17. else if($data['printcode'] == "HUALEI-ARAMEX-G")
  18. {
  19. $product_id = 3361;
  20. $link = 'param=';
  21. $ys = 0;//非延时获取运单
  22. }
  23. else if($data['printcode'] == "HUALEI-ARAMEX-S")
  24. {
  25. $product_id = 8161;//南非
  26. $link = 'param=';
  27. $ys = 0;//非延时获取运单
  28. }
  29. else if ($data['printcode'] == "HUALEI-GES-EU")
  30. {
  31. $product_id = 4301;
  32. $link = 'param=';
  33. $ys = 0;//非延时获取运单
  34. if($data['printnumber'] > 0)
  35. {
  36. $data['number'] = $data['number'].'-'.($data['printnumber']+1);
  37. }
  38. }
  39. else if ($data['printcode'] == "HUALEI-WMS")//DPEX
  40. {
  41. $product_id = 5781;
  42. $link = 'param=';
  43. $ys = 0;//非延时获取运单
  44. }
  45. else if ($data['printcode'] == "HUALEI-DHL-A1")//TNT
  46. {
  47. $product_id = 7281;
  48. $link = 'param=';
  49. $ys = 0;//非延时获取运单
  50. }
  51. else if ($data['printcode'] == "HUALEI-DHL")//TNT
  52. {
  53. $product_id = 7141;
  54. $link = 'param=';
  55. $ys = 0;//
  56. $duty_type = "DDP";
  57. }
  58. $rs = $this->curlRequest('http://123.207.33.169:8082/selectAuth.htm',"username=LY&password=ly999");
  59. $reData = json_decode(str_replace("'", "\"", $rs['result']));
  60. $customer_id = $reData->customer_id;
  61. $customer_userid = $reData->customer_userid;
  62. //$product_id = 4461; //产品id 运输方式由APT给出
  63. $format = 'lbl_NL_XIN.frx'; //打印类型
  64. $printType = 1; //打印类型
  65. /**
  66. * 2, 预报订单
  67. */
  68. if($data['ioss'] != '')//如果有IOSS
  69. {
  70. //预报数据
  71. $count = Array(
  72. 'buyerid' => '',//买家ID
  73. 'consignee_address' => ($data['address2'] != '')?$data['address'].' '.$data['address2']:$data['address'],//地址
  74. 'consignee_city' => $data['city'],//城市
  75. 'consignee_mobile' => '',//收货人手机号 选填
  76. 'consignee_name' => $data['name'],//收件人
  77. 'trade_type' => 'ZYXT',//交易类型
  78. 'consignee_postcode' => $data['zipcode'],//邮编
  79. 'consignee_state' => $data['province'],//省/州
  80. 'consignee_telephone' => $data['phone'],//收货人电话 必填
  81. 'country' => $data['lb'],//收货人国家二字码
  82. 'shipper_taxno' => $data['ioss'],
  83. 'shipper_taxnotype'=>'IOSS',
  84. 'shipper_taxnocountry' => 'NL',
  85. 'customer_id' => $customer_id,
  86. 'customer_userid' => $customer_userid,
  87. 'orderInvoiceParam' => Array(
  88. '0' => Array
  89. (
  90. 'invoice_amount' => $data['zsbjz'],
  91. 'invoice_pcs' => $data['ts'],
  92. 'invoice_title' => $data['sbpm'],
  93. 'invoice_weight' => sprintf("%.3f",$data['zzl']/$data['ts']),//单条重量
  94. 'item_id' => '',
  95. 'item_transactionid' => '',
  96. 'sku' => $data['zwpm'],
  97. 'sku_code' => $data['zwpm'],
  98. 'hs_code'=> $data['hgbm'],//海关编码
  99. ),
  100. ),
  101. 'order_customerinvoicecode' => $data['number'],//原单号
  102. 'product_id' => $product_id,
  103. 'weight' => 0,
  104. 'product_imagepath' => '',
  105. 'consignee_email'=>isset($data['email'])?$data['email']:'',
  106. 'consignee_companyname'=>$data['client'],//收件公司
  107. //'order_cargoamount'=>'',//订单实际金额
  108. //'order_insurance'=>'',//保险金额
  109. 'duty_type'=>$duty_type,
  110. );
  111. }
  112. else
  113. {
  114. //预报数据
  115. $count = Array(
  116. 'buyerid' => '',//买家ID
  117. 'consignee_address' => ($data['address2'] != '')?$data['address'].' '.$data['address2']:$data['address'],//地址
  118. 'consignee_city' => $data['city'],//城市
  119. 'consignee_mobile' => '',//收货人手机号 选填
  120. 'consignee_name' => $data['name'],//收件人
  121. 'trade_type' => 'ZYXT',//交易类型
  122. 'consignee_postcode' => $data['zipcode'],//邮编
  123. 'consignee_state' => $data['province'],//省/州
  124. 'consignee_telephone' => $data['phone'],//收货人电话 必填
  125. 'country' => $data['lb'],//收货人国家二字码
  126. 'customer_id' => $customer_id,
  127. 'customer_userid' => $customer_userid,
  128. 'orderInvoiceParam' => Array(
  129. '0' => Array
  130. (
  131. 'invoice_amount' => $data['zsbjz'],
  132. 'invoice_pcs' => $data['ts'],
  133. 'invoice_title' => $data['sbpm'],
  134. 'invoice_weight' => sprintf("%.3f",$data['zzl']/$data['ts']),//单条重量
  135. 'item_id' => '',
  136. 'item_transactionid' => '',
  137. 'sku' => $data['zwpm'],
  138. 'sku_code' => $data['zwpm'],
  139. 'hs_code'=> $data['hgbm'],//海关编码
  140. ),
  141. ),
  142. 'order_customerinvoicecode' => $data['number'],//原单号
  143. 'product_id' => $product_id,
  144. 'weight' => 0,
  145. 'product_imagepath' => '',
  146. 'consignee_email'=>isset($data['email'])?$data['email']:'',
  147. 'consignee_companyname'=>$data['client'],//收件公司
  148. //'order_cargoamount'=>'',//订单实际金额
  149. //'order_insurance'=>'',//保险金额
  150. 'duty_type'=>$duty_type,
  151. );
  152. }
  153. $result = $this->curlRequest('http://123.207.33.169:8082/createOrderApi.htm',$link.json_encode($count));
  154. $resultData = json_decode($result['result'], true);
  155. if($resultData['ack'] == 'true')
  156. {
  157. //if($resultData['tracking_number'] == $resultData['reference_number'])
  158. if($ys == 1)
  159. {
  160. $g = array('x'=>'1','ys'=>1,'waybill'=>'');
  161. }
  162. else
  163. {
  164. $pdf = $this->get_pdf($resultData['order_id']);
  165. if($pdf['x'] == 1)
  166. {
  167. if($product_id == 4361)
  168. {
  169. $g = array('x'=>'1','ys'=>0,'waybill'=>$resultData['order_privatecode'],'waybill2'=>$resultData['tracking_number'],'label'=>$pdf['label']);
  170. }
  171. else
  172. {
  173. $g = array('x'=>'1','ys'=>0,'waybill'=>$resultData['tracking_number'],'label'=>$pdf['label']);
  174. }
  175. }
  176. else
  177. {
  178. $g = array('x'=>'0','Description'=>$pdf['Description']);
  179. }
  180. }
  181. }
  182. else
  183. {
  184. $resultData['message'] = urldecode($resultData['message']);
  185. $g = array('x'=>'0','Description'=>$resultData['message']);
  186. }
  187. return $g;exit;
  188. }
  189. public function curlRequest($url,$czdata = '')
  190. {
  191. $return = array('state' => 0, 'message' => '', 'result' => '', 'errNo' => 0);
  192. try
  193. {
  194. $ch = curl_init($url);
  195. curl_setopt($ch, CURLOPT_URL, $url);
  196. curl_setopt($ch, CURLOPT_POST, 1);
  197. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  198. curl_setopt($ch, CURLOPT_HTTPHEADER, array(
  199. 'Accept-Language: zh-cn',
  200. 'Connection: Keep-Alive',
  201. 'Cache-Control: no-cache',
  202. 'Content-type: application/x-www-form-urlencoded;charset=UTF-8'));
  203. curl_setopt($ch, CURLOPT_POSTFIELDS, $czdata);
  204. //设置超时时间
  205. curl_setopt($ch, CURLOPT_TIMEOUT, 120);
  206. //API返回数据
  207. $apiResult = curl_exec($ch);
  208. $errNo = curl_errno($ch);
  209. if ($errNo)
  210. {
  211. //返回错误码
  212. $return['errNo'] = $errNo;
  213. $errorStr = curl_error($ch);
  214. switch ((int)$errNo)
  215. {
  216. case 6: //避免一直发邮件 URL报错
  217. break;
  218. case 7: //无法通过 connect() 连接至主机或代理服务器
  219. break;
  220. case 28: //超时
  221. break;
  222. case 56: //接收网络数据失败
  223. break;
  224. default:
  225. break;
  226. }
  227. throw new Exception($errorStr);
  228. }
  229. curl_close($ch);
  230. $return['state'] = 1;
  231. //返回数据
  232. $return['result'] = $apiResult;
  233. }
  234. catch (Exception $e)
  235. {
  236. $return['state'] = 0;
  237. $return['message'] = $e->getMessage();
  238. }
  239. return $return;
  240. }
  241. public function get_hqwaybill($number)
  242. {
  243. $ch = curl_init();
  244. curl_setopt($ch, CURLOPT_URL, 'http://123.207.33.169:8082/getOrderTrackingNumber.htm?documentCode='.$number);
  245. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  246. curl_setopt($ch, CURLOPT_HTTPGET, true);
  247. curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
  248. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  249. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  250. $res = curl_exec($ch);
  251. curl_close($ch);
  252. $res = json_decode($res,true);
  253. if(isset($res['childno'][0]))
  254. {
  255. $g = array('x'=>'1','ys'=>0,'waybill'=>$res['order_serveinvoicecode']);
  256. }
  257. else
  258. {
  259. $g = array('x'=>'0','Description'=>$res['msg']);
  260. }
  261. return $g;
  262. }
  263. public function get_pdf($orderid)
  264. {
  265. $ch = curl_init("http://123.207.33.169:8089/order/FastRpt/PDF_NEW.aspx?PrintType=lab10_10&order_id=".$orderid);
  266. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  267. curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
  268. curl_setopt($ch, CURLOPT_NOBODY, 1);
  269. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  270. curl_setopt($ch, CURLOPT_HEADER, 1);
  271. curl_exec($ch);
  272. $res = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
  273. curl_close($ch);
  274. if(stripos($res,'.pdf') !== false)
  275. {
  276. $g = array('x'=>'1','label'=>$res);
  277. }
  278. else
  279. {
  280. $g = array('x'=>'0','Description'=>"获取运单失败,请重试");
  281. }
  282. return $g;
  283. }
  284. public function get_manifest($fullorder) //生成发货清单
  285. {
  286. }
  287. public function get_logistics($number)//追踪快递
  288. {
  289. }
  290. //http://123.207.33.169:8089/order/FastRpt/PDF_NEW.aspx?Format=lbl_NL_XIN.frx&PrintType=lab10_10&order_id=5456516打印
  291. } //end class