Model_hualei.php 12 KB

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