Model_hualeiv1.php 13 KB

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