Model_hualei.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401
  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. // }else if($data['printcode'] == 'HUALEI-MGLB'){
  65. // $product_id = 8641;
  66. // $link = 'param=';
  67. // $ys = 0;//
  68. // }else if($data['printcode'] == 'HUALEI-UNI'){
  69. // $product_id = 2;
  70. // $link = 'param=';
  71. // $ys = 0;//
  72. // }
  73. if($data['printcode'] == 'HUALEI-UNI'){
  74. $product_id = 2;
  75. $link = 'param=';
  76. $ys = 0;//
  77. }else{
  78. $g = array('x'=>'0','Description'=>'系统没有开通该渠道');
  79. return $g;
  80. }
  81. $rs = $this->curlRequest('http://123.207.33.169:8082/selectAuth.htm',"username=LY&password=ly999");
  82. $reData = json_decode(str_replace("'", "\"", $rs['result']));
  83. $customer_id = $reData->customer_id;
  84. $customer_userid = $reData->customer_userid;
  85. //$product_id = 4461; //产品id 运输方式由APT给出
  86. $format = 'lbl_NL_XIN.frx'; //打印类型
  87. $printType = 1; //打印类型
  88. /**
  89. * 2, 预报订单
  90. */
  91. if($data['ioss'] != '')//如果有IOSS
  92. {
  93. //预报数据
  94. $count = Array(
  95. 'buyerid' => '',//买家ID
  96. 'consignee_address' => ($data['address2'] != '')?$data['address'].' '.$data['address2']:$data['address'],//地址
  97. 'consignee_city' => $data['city'],//城市
  98. 'consignee_mobile' => '',//收货人手机号 选填
  99. 'consignee_name' => $data['name'],//收件人
  100. 'trade_type' => 'ZYXT',//交易类型
  101. 'consignee_postcode' => $data['zipcode'],//邮编
  102. 'consignee_state' => $data['province'],//省/州
  103. 'consignee_telephone' => $data['phone'],//收货人电话 必填
  104. 'country' => $data['lb'],//收货人国家二字码
  105. 'shipper_taxno' => $data['ioss'],
  106. 'shipper_taxnotype'=>'IOSS',
  107. 'shipper_taxnocountry' => 'NL',
  108. 'customer_id' => $customer_id,
  109. 'customer_userid' => $customer_userid,
  110. 'orderInvoiceParam' => Array(
  111. '0' => Array
  112. (
  113. 'invoice_amount' => $data['zsbjz'],
  114. 'invoice_pcs' => $data['ts'],
  115. 'invoice_title' => $data['sbpm'],
  116. 'invoice_weight' => sprintf("%.3f",$data['zzl']/$data['ts']),//单条重量
  117. 'item_id' => '',
  118. 'item_transactionid' => '',
  119. 'sku' => $data['zwpm'],
  120. 'sku_code' => $data['zwpm'],
  121. 'hs_code'=> $data['hgbm'],//海关编码
  122. ),
  123. ),
  124. 'order_customerinvoicecode' => $data['number'],//原单号
  125. 'product_id' => $product_id,
  126. 'weight' => 0,
  127. 'product_imagepath' => '',
  128. 'consignee_email'=>isset($data['email'])?$data['email']:'',
  129. 'consignee_companyname'=>$data['client'],//收件公司
  130. //'order_cargoamount'=>'',//订单实际金额
  131. //'order_insurance'=>'',//保险金额
  132. 'duty_type'=>$duty_type,
  133. );
  134. }
  135. else
  136. {
  137. //预报数据
  138. $count = Array(
  139. 'buyerid' => '',//买家ID
  140. 'consignee_address' => ($data['address2'] != '')?$data['address'].' '.$data['address2']:$data['address'],//地址
  141. 'consignee_city' => $data['city'],//城市
  142. 'consignee_mobile' => '',//收货人手机号 选填
  143. 'consignee_name' => $data['name'],//收件人
  144. 'trade_type' => 'ZYXT',//交易类型
  145. 'consignee_postcode' => $data['zipcode'],//邮编
  146. 'consignee_state' => $data['province'],//省/州
  147. 'consignee_telephone' => $data['phone'],//收货人电话 必填
  148. 'country' => $data['lb'],//收货人国家二字码
  149. 'customer_id' => $customer_id,
  150. 'customer_userid' => $customer_userid,
  151. 'orderInvoiceParam' => Array(
  152. '0' => Array
  153. (
  154. 'invoice_amount' => $data['zsbjz'],
  155. 'invoice_pcs' => $data['ts'],
  156. 'invoice_title' => $data['sbpm'],
  157. 'invoice_weight' => sprintf("%.3f",$data['zzl']/$data['ts']),//单条重量
  158. 'item_id' => '',
  159. 'item_transactionid' => '',
  160. 'sku' => $data['zwpm'],
  161. 'sku_code' => $data['zwpm'],
  162. 'hs_code'=> $data['hgbm'],//海关编码
  163. ),
  164. ),
  165. 'order_customerinvoicecode' => $data['number'],//原单号
  166. 'product_id' => $product_id,
  167. 'weight' => 0,
  168. 'product_imagepath' => '',
  169. 'consignee_email'=>isset($data['email'])?$data['email']:'',
  170. 'consignee_companyname'=>$data['client'],//收件公司
  171. //'order_cargoamount'=>'',//订单实际金额
  172. //'order_insurance'=>'',//保险金额
  173. 'duty_type'=>$duty_type,
  174. );
  175. }
  176. if($data['printcode'] == 'HUALEI-UNI'){
  177. if($data['printnumber'] > 0){
  178. $count['order_customerinvoicecode'] = $data['number']."-".$data['printnumber'];
  179. }
  180. }
  181. // var_dump($link);
  182. // var_dump(json_encode($count));
  183. $this->logic_ding->sendToDing("hualei发货单请求的报文".$link.json_encode($count));
  184. $start_time = time();
  185. $result = $this->curlRequest('http://123.207.33.169:8082/createOrderApi.htm',$link.json_encode($count));
  186. $this->logic_ding->sendToDing("hualei发货单回执的报文result".json_encode($result,JSON_UNESCAPED_UNICODE));
  187. $resultData = json_decode($result['result'], true);
  188. if(isset($resultData['message'])){
  189. $resultData['message'] = urldecode($resultData['message']);
  190. }
  191. $this->logic_ding->sendToDing("hualei发货单回执的报文resultData".json_encode($resultData,JSON_UNESCAPED_UNICODE));
  192. if($resultData['ack'] == 'true')
  193. {
  194. //if($resultData['tracking_number'] == $resultData['reference_number'])
  195. if($ys == 1)
  196. {
  197. $g = array('x'=>'1','ys'=>1,'waybill'=>'');
  198. }
  199. else
  200. {
  201. $pdf = $this->get_pdf($resultData['order_id']);
  202. if($pdf['x'] == 1)
  203. {
  204. if($product_id == 4361)
  205. {
  206. $g = array('x'=>'1','ys'=>0,'waybill'=>$resultData['order_privatecode'],'waybill2'=>$resultData['tracking_number'],'label'=>$pdf['label']);
  207. }
  208. else
  209. {
  210. $g = array('x'=>'1','ys'=>0,'waybill'=>$resultData['tracking_number'],'label'=>$pdf['label']);
  211. }
  212. }
  213. else
  214. {
  215. $g = array('x'=>'0','Description'=>json_encode($pdf,JSON_UNESCAPED_UNICODE));
  216. }
  217. }
  218. }
  219. else
  220. {
  221. $resultData['message'] = urldecode($resultData['message']);
  222. $g = array('x'=>'0','Description'=>json_encode($resultData ,JSON_UNESCAPED_UNICODE));
  223. }
  224. $end_time = time();
  225. if($g['x'] == 1){
  226. if( $end_time - $start_time > 45){
  227. $this->logic_ding->addJobs('outtime_order',['number'=>$data['number']]);
  228. }
  229. }
  230. $this->logic_ding->sendToDing("hualei发货单回执的pdf报文".json_encode($g,JSON_UNESCAPED_UNICODE));
  231. return $g;exit;
  232. }
  233. public function curlRequest($url,$czdata = '')
  234. {
  235. $return = array('state' => 0, 'message' => '', 'result' => '', 'errNo' => 0);
  236. try
  237. {
  238. $ch = curl_init($url);
  239. curl_setopt($ch, CURLOPT_URL, $url);
  240. curl_setopt($ch, CURLOPT_POST, 1);
  241. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  242. curl_setopt($ch, CURLOPT_HTTPHEADER, array(
  243. 'Accept-Language: zh-cn',
  244. 'Connection: Keep-Alive',
  245. 'Cache-Control: no-cache',
  246. 'Content-type: application/x-www-form-urlencoded;charset=UTF-8'));
  247. curl_setopt($ch, CURLOPT_POSTFIELDS, $czdata);
  248. //设置超时时间
  249. curl_setopt($ch, CURLOPT_TIMEOUT, 120);
  250. //API返回数据
  251. $apiResult = curl_exec($ch);
  252. $errNo = curl_errno($ch);
  253. if ($errNo)
  254. {
  255. //返回错误码
  256. $return['errNo'] = $errNo;
  257. $errorStr = curl_error($ch);
  258. switch ((int)$errNo)
  259. {
  260. case 6: //避免一直发邮件 URL报错
  261. break;
  262. case 7: //无法通过 connect() 连接至主机或代理服务器
  263. break;
  264. case 28: //超时
  265. break;
  266. case 56: //接收网络数据失败
  267. break;
  268. default:
  269. break;
  270. }
  271. throw new Exception($errorStr);
  272. }
  273. curl_close($ch);
  274. $return['state'] = 1;
  275. //返回数据
  276. $return['result'] = $apiResult;
  277. }
  278. catch (Exception $e)
  279. {
  280. $return['state'] = 0;
  281. $return['message'] = $e->getMessage();
  282. }
  283. return $return;
  284. }
  285. public function get_hqwaybill($number)
  286. {
  287. $ch = curl_init();
  288. curl_setopt($ch, CURLOPT_URL, 'http://123.207.33.169:8082/getOrderTrackingNumber.htm?documentCode='.$number);
  289. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  290. curl_setopt($ch, CURLOPT_HTTPGET, true);
  291. curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
  292. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  293. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  294. $res = curl_exec($ch);
  295. curl_close($ch);
  296. $res = json_decode($res,true);
  297. if(isset($res['childno'][0]))
  298. {
  299. $g = array('x'=>'1','ys'=>0,'waybill'=>$res['order_serveinvoicecode']);
  300. }
  301. else
  302. {
  303. $g = array('x'=>'0','Description'=>$res['msg']);
  304. }
  305. return $g;
  306. }
  307. public function get_pdf($orderid)
  308. {
  309. $ch = curl_init("http://123.207.33.169:8089/order/FastRpt/PDF_NEW.aspx?PrintType=lab10_10&order_id=".$orderid);
  310. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  311. curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
  312. curl_setopt($ch, CURLOPT_NOBODY, 1);
  313. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  314. curl_setopt($ch, CURLOPT_HEADER, 1);
  315. curl_exec($ch);
  316. $res = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
  317. curl_close($ch);
  318. if(stripos($res,'.pdf') !== false)
  319. {
  320. $g = array('x'=>'1','label'=>$res);
  321. }
  322. else
  323. {
  324. $g = array('x'=>'0','Description'=>"获取运单失败,请重试");
  325. }
  326. return $g;
  327. }
  328. public function get_manifest($fullorder) //生成发货清单
  329. {
  330. }
  331. public function get_logistics($number)//追踪快递
  332. {
  333. }
  334. //http://123.207.33.169:8089/order/FastRpt/PDF_NEW.aspx?Format=lbl_NL_XIN.frx&PrintType=lab10_10&order_id=5456516打印
  335. /**
  336. * 获取华磊的抓单号
  337. */
  338. public function getDetail($number_str){
  339. $url = "http://123.207.33.169:8082/logistics/api";
  340. $ch = curl_init($url);
  341. $headers = [
  342. 'auth'=>'FACFD061CAEC49D048AD9158084D6669',
  343. 'Content-Type:application/json;charset=UTF-8' ,
  344. ];
  345. $params = [
  346. 'method'=>"order.selectorderandchildbycode",
  347. 'content'=>[
  348. 'order_customerinvoicecode'=>$number_str,
  349. ]
  350. ];
  351. $params = json_encode($params);
  352. $options = [
  353. CURLOPT_RETURNTRANSFER => true,
  354. CURLOPT_POST => true,
  355. CURLOPT_POSTFIELDS => $params,
  356. CURLOPT_HTTPHEADER => $headers,
  357. CURLOPT_TIMEOUT => 30, // 添加超时
  358. CURLOPT_CONNECTTIMEOUT => 10,
  359. // 生产环境应启用SSL验证
  360. // CURLOPT_SSL_VERIFYPEER => true,
  361. // CURLOPT_SSL_VERIFYHOST => 2,
  362. ];
  363. curl_setopt_array($ch, $options);
  364. $response = curl_exec($ch);
  365. // 检查HTTP状态码
  366. // $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  367. // if ($response === false || $httpCode >= 400) {
  368. // $error = curl_error($ch);
  369. // curl_close($ch);
  370. // return [
  371. // "code" => -1,
  372. // "msg" => $error ?: "HTTP $httpCode",
  373. // "http_code" => $httpCode
  374. // ];
  375. // }
  376. curl_close($ch);
  377. return $response;
  378. }
  379. } //end class