Model_hualeiv1.php 12 KB

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