Model_hualei.php 9.0 KB

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