Model_hualei.php 8.9 KB

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