Model_hualei.php 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  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发货单回执的报文".$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. return $g;exit;
  199. }
  200. public function curlRequest($url,$czdata = '')
  201. {
  202. $return = array('state' => 0, 'message' => '', 'result' => '', 'errNo' => 0);
  203. try
  204. {
  205. $ch = curl_init($url);
  206. curl_setopt($ch, CURLOPT_URL, $url);
  207. curl_setopt($ch, CURLOPT_POST, 1);
  208. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  209. curl_setopt($ch, CURLOPT_HTTPHEADER, array(
  210. 'Accept-Language: zh-cn',
  211. 'Connection: Keep-Alive',
  212. 'Cache-Control: no-cache',
  213. 'Content-type: application/x-www-form-urlencoded;charset=UTF-8'));
  214. curl_setopt($ch, CURLOPT_POSTFIELDS, $czdata);
  215. //设置超时时间
  216. curl_setopt($ch, CURLOPT_TIMEOUT, 120);
  217. //API返回数据
  218. $apiResult = curl_exec($ch);
  219. $errNo = curl_errno($ch);
  220. if ($errNo)
  221. {
  222. //返回错误码
  223. $return['errNo'] = $errNo;
  224. $errorStr = curl_error($ch);
  225. switch ((int)$errNo)
  226. {
  227. case 6: //避免一直发邮件 URL报错
  228. break;
  229. case 7: //无法通过 connect() 连接至主机或代理服务器
  230. break;
  231. case 28: //超时
  232. break;
  233. case 56: //接收网络数据失败
  234. break;
  235. default:
  236. break;
  237. }
  238. throw new Exception($errorStr);
  239. }
  240. curl_close($ch);
  241. $return['state'] = 1;
  242. //返回数据
  243. $return['result'] = $apiResult;
  244. }
  245. catch (Exception $e)
  246. {
  247. $return['state'] = 0;
  248. $return['message'] = $e->getMessage();
  249. }
  250. return $return;
  251. }
  252. public function get_hqwaybill($number)
  253. {
  254. $ch = curl_init();
  255. curl_setopt($ch, CURLOPT_URL, 'http://123.207.33.169:8082/getOrderTrackingNumber.htm?documentCode='.$number);
  256. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  257. curl_setopt($ch, CURLOPT_HTTPGET, true);
  258. curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
  259. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  260. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  261. $res = curl_exec($ch);
  262. curl_close($ch);
  263. $res = json_decode($res,true);
  264. if(isset($res['childno'][0]))
  265. {
  266. $g = array('x'=>'1','ys'=>0,'waybill'=>$res['order_serveinvoicecode']);
  267. }
  268. else
  269. {
  270. $g = array('x'=>'0','Description'=>$res['msg']);
  271. }
  272. return $g;
  273. }
  274. public function get_pdf($orderid)
  275. {
  276. $ch = curl_init("http://123.207.33.169:8089/order/FastRpt/PDF_NEW.aspx?PrintType=lab10_10&order_id=".$orderid);
  277. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  278. curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
  279. curl_setopt($ch, CURLOPT_NOBODY, 1);
  280. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  281. curl_setopt($ch, CURLOPT_HEADER, 1);
  282. curl_exec($ch);
  283. $res = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
  284. curl_close($ch);
  285. if(stripos($res,'.pdf') !== false)
  286. {
  287. $g = array('x'=>'1','label'=>$res);
  288. }
  289. else
  290. {
  291. $g = array('x'=>'0','Description'=>"获取运单失败,请重试");
  292. }
  293. return $g;
  294. }
  295. public function get_manifest($fullorder) //生成发货清单
  296. {
  297. }
  298. public function get_logistics($number)//追踪快递
  299. {
  300. }
  301. //http://123.207.33.169:8089/order/FastRpt/PDF_NEW.aspx?Format=lbl_NL_XIN.frx&PrintType=lab10_10&order_id=5456516打印
  302. } //end class