Model_hualei.php 9.6 KB

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