Model_hualeixw.php 8.8 KB

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