Model_hualeiv1.php 12 KB

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