Model_hualeiv1.php 12 KB

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