Model_hualeiv1.php 12 KB

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