Model_hualei.php 9.2 KB

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