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