Model_hualeixw.php 9.2 KB

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