Model_hualeixw.php 9.0 KB

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