Model_hualeiv1.php 13 KB

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