Model_hualeiv1.php 13 KB

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