From 072d8f583991c7c4b4c5ae9e79e8346f0713cb9e Mon Sep 17 00:00:00 2001 From: QxQ Date: Tue, 18 Jun 2019 16:20:53 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E5=AE=8F=E5=A5=87=E6=82=A0?= =?UTF-8?q?=E9=81=8A=E5=8D=A1=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- controllers/api/Alt_acarps.php | 90 ++++++++++++++++ controllers/api/Altpay_member.php | 213 +++++++++++++++++++++++++++++++++++++ controllers/api/Query_in_fuzzy.php | 123 +++++++++++++++++++++ models/Cars_model.php | 97 +++++++++++++++++ models/api/Altpay_model.php | 20 ++++ models/api/Master_db_model.php | 105 ++++++++++++++++++ 6 files changed, 648 insertions(+) create mode 100644 controllers/api/Alt_acarps.php create mode 100644 controllers/api/Altpay_member.php create mode 100644 controllers/api/Query_in_fuzzy.php create mode 100644 models/api/Altpay_model.php create mode 100644 models/api/Master_db_model.php diff --git a/controllers/api/Alt_acarps.php b/controllers/api/Alt_acarps.php new file mode 100644 index 0000000..bcc6a0e --- /dev/null +++ b/controllers/api/Alt_acarps.php @@ -0,0 +1,90 @@ +input->get(NULL, TRUE); + $lpr="ALT6222";//$post_data["lpr"];LT6222 +//print_r($lpr);exit; + $this->load->model('api/Master_db_model','master_db'); + $sel_cario=$this->master_db->sel_cario($lpr); +//print_r($sel_cario);exit; + if(count($sel_cario)>0){ + + $cario_no=$sel_cario[0]['cario_no']; //入場流水號 + $station_no=$sel_cario[0]['station_no']; //場站代碼 + $member_no=$sel_cario[0]['member_no']; //會員代碼 + $obj_id=$sel_cario[0]['obj_id']; //會員代碼 + $in_out=$sel_cario[0]['in_out']; + + $in_time=$sel_cario[0]['in_time']; //入場時間 + + $Get_billing_fee= "http://altapi.altob.com.tw/fee_api/Get_billing_fee"; //檢查現場入場時間 + + $start_time=$in_time; + $end_time=date('Y-m-d H:i:s'); + $ch0 = curl_init(); + + curl_setopt($ch0, CURLOPT_HEADER, 0); + curl_setopt($ch0, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($ch0, CURLOPT_URL, $Get_billing_fee); + curl_setopt($ch0, CURLOPT_POST, true); + curl_setopt($ch0, CURLOPT_POSTFIELDS, http_build_query(array("station_no"=>$station_no, "start_time"=>$start_time, "end_time"=>$end_time))); + + $totalfee0 = curl_exec($ch0); + curl_close($ch0); + + $totalfee=isset($totalfee0) ? $totalfee0:0 ; + $acarps_ip="192.168.10.82"; + $acarps_port=8081; + $apijson= "http://".$acarps_ip.":".$acarps_port."/lprpayout"; //送宏奇API + + $i=1; + $jsonarray=array("lpr"=>$obj_id, "start_time"=>$start_time, "end_time"=>$end_time, "totalfee"=>$totalfee); + $json=json_encode($jsonarray,true); +//print_r($json); + while(true){ + + $ch = curl_init(); + + curl_setopt($ch, CURLOPT_HEADER, 0); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($ch, CURLOPT_URL, $apijson); + curl_setopt($ch, CURLOPT_POST, true); + curl_setopt($ch, CURLOPT_POSTFIELDS, $json); + curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json; charset=utf-8','Content-Length: ' . strlen($json))); + + $output = curl_exec($ch); + +//print_r($output);exit; + + if($i==10 or $output=="OK"){ + if($output=="OK"){ + $data=date('Y-m-d H:i:s')." Alt_acarps OK ".$obj_id."\n"; + $this->save_setting($data); + } + break; + } + $i++; + } + } + + + } + + + public function save_setting($data){ + $myfile = fopen("/home/data/alt_acarps_log.json", "a+") or die("Unable to open file!"); + fwrite($myfile, $data); + fclose($myfile); + } + +} diff --git a/controllers/api/Altpay_member.php b/controllers/api/Altpay_member.php new file mode 100644 index 0000000..edc4a37 --- /dev/null +++ b/controllers/api/Altpay_member.php @@ -0,0 +1,213 @@ +load->library('session'); + $this->load->model('api/Altpay_model','Altpay'); + + // ----- 回傳訊息 ----- + define('ALLPA_GO_RESULT_CODE_OK', 0); + define('ALLPA_GO_RESULT_MSG_OK', "成功"); + define('ALLPA_GO_RESULT_CODE_CK_ERROR', 10); + define('ALLPA_GO_RESULT_MSG_CK_ERROR', "CK ERROR"); + define('ALLPA_GO_RESULT_CODE_USER_NOT_FOUND', 11); + define('ALLPA_GO_RESULT_MSG_USER_NOT_FOUND', "查無歐Pa卡用戶"); + define('local_ip', 'http://221.120.36.144'); + // ----- 回傳訊息 (END) ----- + } + + public function index() { + $station_info = array(); + $station_info = $this->Altpay->sel_info(); + $result = $station_info; + $key = md5("Alt@b80682490".$station_info[0]['station_no']); + $acarps_ip="altapi.altob.com.tw"; + $this->get_member_data($acarps_ip,$key); + } + + //call總公司API取得歐Pa卡會員資料 + public function get_member_data($acarps_ip,$key){ + $apijson= "http://".$acarps_ip."/alp_pay_api/Altpay_members_api/index/".$key; + $ch = curl_init(); + curl_setopt($ch, CURLOPT_HEADER, 0); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($ch, CURLOPT_URL, $apijson); + $output = curl_exec($ch); + if (curl_errno($ch)) { + print "Error: " . curl_error($ch); + } else { + curl_close($ch); + $this->save_member_json($output); + print_r(json_encode($output)); + } + } + + public function save_member_json($data){ + $myfile = fopen("/home/data/json/altpay_member.json", "w") or die("Unable to open file!"); + fwrite($myfile, $data); + fclose($myfile); + } + + public function read_member_json(){ + $myfile = fopen("/home/data/json/altpay_member.json", "r") or die("Unable to open file!"); + $result = array(); + $result = fread($myfile, filesize("/home/data/json/altpay_member.json")); + fclose($myfile); + return $result; + } + + // 歐Pa卡 - 判斷有效用戶 (限制存取) + public function get_allpa_valid_user($lpr,$check_mac){ + $data = json_decode($this->read_member_json(),true); + $result = array(); + $flag = 0; + for($i=0;$iuri->segment(3); // 進場時間 + $lpr = $this->uri->segment(4); // 車牌號碼 + $station_no = $this->uri->segment(5); // 場站編號 + $check_mac = $this->uri->segment(6); // 驗証欄位 + */ + // 驗証欄位 + /* + if($check_mac != md5($in_time. $lpr . $station_no)){ + echo 'ck_error'; + exit; + } + */ + // 先檢查本地端是否為歐PA會員 + $valid_user_ck = md5($lpr); + $valid_user_result = $this->get_allpa_valid_user($lpr, $valid_user_ck); // check user + if(!isset($valid_user_result['result_code']) || $valid_user_result['result_code'] != 0){ + echo json_encode($valid_user_result, JSON_UNESCAPED_UNICODE); + } else { + $res = $this->get_total_fee($lpr); + $tmp = explode('|',$res); + $total_fee = $tmp[0]; + $station_no = $tmp[1]; + $cario_no = $tmp[2]; + $in_time = $tmp[3]; + $in_lane = $tmp[4]; + $out_lane = $tmp[5]; + $pay_time = strtotime(date('Y-m-d H:i:s')); // 結帳時間 + $data=array( + "station_no"=>$station_no, + "cario_no"=>$cario_no, + "in_time"=>$in_time, + "out_time"=>'', + "in_lane"=>$in_lane, + "out_lane"=>$out_lane, + "pay_time"=>$pay_time, + "fee"=>$total_fee, + "pre_status_code"=>'01', + "pre_balance"=>$valid_user_result['balance'], + "pre_bonus"=>'', + "status_code"=>'01', + "balance"=>$valid_user_result['balance']-$total_fee, + "bonus"=>'', + "in_pic_name"=>'', + "in_pic_down"=>0, + "out_pic_name"=>'', + "out_pic_down"=>0, + "create_time"=>strtotime(date('Y-m-d H:i:s')), + "update_time"=>strtotime(date('Y-m-d H:i:s')) + ); + print_r($data); + } + } + + public function get_total_fee($lpr){ + $this->load->model('api/Master_db_model','master_db'); + $sel_cario=$this->master_db->sel_cario($lpr); + if(count($sel_cario)>0){ + $cario_no=$sel_cario[0]['cario_no']; //入場流水號 + $station_no=$sel_cario[0]['station_no']; //場站代碼 + $member_no=$sel_cario[0]['member_no']; //會員代碼 + $obj_id=$sel_cario[0]['obj_id']; //會員代碼 + $in_out=$sel_cario[0]['in_out']; + $in_time=$sel_cario[0]['in_time']; //入場時間 + + $Get_billing_fee= "http://altapi.altob.com.tw/fee_api/Get_billing_fee"; //檢查現場入場時間 + + $start_time=$in_time; + $end_time=date('Y-m-d H:i:s'); + $ch0 = curl_init(); + + curl_setopt($ch0, CURLOPT_HEADER, 0); + curl_setopt($ch0, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($ch0, CURLOPT_URL, $Get_billing_fee); + curl_setopt($ch0, CURLOPT_POST, true); + curl_setopt($ch0, CURLOPT_POSTFIELDS, http_build_query(array("station_no"=>$station_no, "start_time"=>$start_time, "end_time"=>$end_time))); + + $totalfee0 = curl_exec($ch0); + curl_close($ch0); + + $totalfee=isset($totalfee0) ? $totalfee0:0 ; + return $totalfee.'|'.$sel_cario[0]['station_no'].'|'.$sel_cario[0]['cario_no'].'|'.$sel_cario[0]['in_time'].'|'.$sel_cario[0]['in_lane'].'|'.$sel_cario[0]['out_lane']; + } + } + + public function test(){ + //$lpr = "ABC123"; + $lpr = "AQB2211"; + $ck = md5($lpr); + $this->allpa_go_remote("2018-06-27 21:20:20",$lpr,"40671");exit; + //print_r($lpr."|".$ck."|"); + + ob_end_clean(); + ignore_user_abort(); + ob_start(); + $data = $this->get_allpa_valid_user($lpr, $ck); // check user + echo json_encode($data, JSON_UNESCAPED_UNICODE); + header('Connection: close'); + header('Content-Length: ' . ob_get_length()); + ob_end_flush(); + flush(); + /* + $jdata = file_get_contents("http://localhost/api.html/Altpay_member/get_allpa_valid_user/{$lpr}/{$ck}"); + $results = json_decode($jdata, true); + print_r($results); + */ + } +} +?> + diff --git a/controllers/api/Query_in_fuzzy.php b/controllers/api/Query_in_fuzzy.php new file mode 100644 index 0000000..b954526 --- /dev/null +++ b/controllers/api/Query_in_fuzzy.php @@ -0,0 +1,123 @@ +input->post(NULL, TRUE); + $get_data= $this->input->get(NULL, TRUE);; + + if($post_data){ + $lpr=$post_data['lpr']; + }elseif($get_data){ + $lpr=$get_data['lpr']; + }else{ + $lpr=''; + } + + if($lpr!=''){ + $this->load->model('api/Master_db_model','master_db'); + $sel_cario_like=$this->master_db->sel_cario_like($lpr); + + if(count($sel_cario_like)>0){ + $i=0; + foreach($sel_cario_like as $key0 => $value0){ + $lpr0=$value0['obj_id']; + $chk_carioseat=$this->master_db->chk_carioseat($lpr0); + $sel_carioseat=$this->master_db->sel_carioseat($lpr0); + + $in_date = new DateTime($sel_carioseat[0]['in_time']); + $in_date= $in_date->format('Ymd'); + $in_pic_name = "http://192.168.10.201/carpic/".$in_date."/".$sel_carioseat[0]['in_pic_name']; + + $station_no=$sel_carioseat[0]['station_no']; + + $chk_in_time=isset($chk_carioseat[0]['in_time']) ? $chk_carioseat[0]['in_time']: "0000-00-00 00:00:00" ; //車輛最後出場之入場時間 + + $in_time=$sel_carioseat[0]['in_time']; + + if($in_time>$chk_in_time){ + + $end_time=$sel_carioseat[0]['station_no']; + + $Get_billing_fee= "http://altapi.altob.com.tw/fee_api/Get_billing_fee"; //檢查現場入場時間 + + $start_time=$in_time; + $end_time=date('Y-m-d H:i:s'); + + $ch0 = curl_init(); + + curl_setopt($ch0, CURLOPT_HEADER, 0); + curl_setopt($ch0, CURLOPT_RETURNTRANSFER, true); + curl_setopt($ch0, CURLOPT_URL, $Get_billing_fee); + curl_setopt($ch0, CURLOPT_POST, true); + curl_setopt($ch0, CURLOPT_POSTFIELDS, http_build_query(array("station_no"=>$station_no, "start_time"=>$in_time, "end_time"=>$end_time))); + + $totalfee0 = curl_exec($ch0); + + curl_close($ch0); + + $totalfee=isset($totalfee0) ? $totalfee0:0 ; + + $dataarray[]=array( + "lpr" => $lpr0, + "in_time" => $in_time, + "pay_time" => $end_time, + "fee" => $totalfee0, + "in_pic_name" => $in_pic_name, + "success" => true + ); + $i++; + }else{ + + } + + if($i==0){ + $dataarray[]=array( + "lpr" => $lpr, + "in_time" => "0000-00-00 00:00:00", + "pay_time" => "0000-00-00 00:00:00", + "fee" => 0, + "in_pic_name" => "", + "success" => false + ); + } + + } + + }else{ + $dataarray[]=array( + "lpr" => $lpr, + "in_time" => "0000-00-00 00:00:00", + "pay_time" => "0000-00-00 00:00:00", + "fee" => 0, + "in_pic_name" => "", + "success" => false + ); + } + + }else{ + + $dataarray[]=array( + "lpr" => "", + "in_time" => "0000-00-00 00:00:00", + "pay_time" => "0000-00-00 00:00:00", + "fee" => 0, + "in_pic_name" => "", + "success" => false + ); + } + + print_r(json_encode($dataarray,true));exit; + } + + +} + diff --git a/models/Cars_model.php b/models/Cars_model.php index cdf9ecb..7a229b2 100644 --- a/models/Cars_model.php +++ b/models/Cars_model.php @@ -606,6 +606,13 @@ class Cars_model extends CI_Model // [mitac] 要求 mitac 扣款 START $this->call_mitac_pay($parms['lpr'], $parms['ivsno'], $rows_cario); // [mitac] 要求 mitac 扣款 END + + // [宏奇系統] 離場車辨成功流程 START + if($parms['sno'] == 40671 || $parms['sno'] == 40672 || $parms['sno'] == 40673) + { + $this->acarps($parms['lpr']); + } + // [宏奇系統] 離場車辨成功流程 END } return true; @@ -697,6 +704,13 @@ class Cars_model extends CI_Model // [mitac] 要求 mitac 扣款 START $this->call_mitac_pay($parms['lpr'], $parms['ivsno'], $rows_cario); // [mitac] 要求 mitac 扣款 END + + // [宏奇系統] 離場車辨成功流程 START + if($parms['sno'] == 40671 || $parms['sno'] == 40672 || $parms['sno'] == 40673) + { + $this->acarps($parms['lpr']); + } + // [宏奇系統] 離場車辨成功流程 END } return true; @@ -1676,5 +1690,88 @@ class Cars_model extends CI_Model trigger_error(__FUNCTION__ . 'error:'.$e->getMessage()); } } + + public function acarps($lpr) //出場車辨 送 API 至宏奇 + { + $this->load->model('api/Master_db_model','master_db'); + $sel_cario=$this->master_db->sel_cario($lpr); + + if(count($sel_cario)>0) + { + $cario_no=$sel_cario[0]['cario_no']; //入場流水號 + $station_no=$sel_cario[0]['station_no']; //場站代碼 + $member_no=$sel_cario[0]['member_no']; //會員代碼 + $obj_id=$sel_cario[0]['obj_id']; //會員代碼 + $in_out=$sel_cario[0]['in_out']; + + $in_time=$sel_cario[0]['in_time']; //入場時間 + + $Get_billing_fee= "http://altapi.altob.com.tw/fee_api/Get_billing_fee"; //檢查現場入場時間 + + $start_time=$in_time; + $end_time=date('Y-m-d H:i:s'); + $ch0 = curl_init(); + + curl_setopt($ch0, CURLOPT_HEADER, 0); + curl_setopt($ch0, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($ch0, CURLOPT_URL, $Get_billing_fee); + curl_setopt($ch0, CURLOPT_POST, true); + curl_setopt($ch0, CURLOPT_POSTFIELDS, http_build_query(array("station_no"=>$station_no, "start_time"=>$start_time, "end_time"=>$end_time))); + + $totalfee0 = curl_exec($ch0); + curl_close($ch0); + + $totalfee=isset($totalfee0) ? $totalfee0:0 ; + + //注意ip有轉port需確認SELINUX要=disabled,位於/etc/selinux/config + $acarps_ip="192.168.10.82"; + $acarps_port="8081"; + $apijson= "http://".$acarps_ip.":".$acarps_port."/lprpayout"; //送宏奇API + //print_r($apijson);exit; + $i=1; + $jsonarray=array("lpr"=>$obj_id, "start_time"=>$start_time, "end_time"=>$end_time, "totalfee"=>$totalfee); + $json=json_encode($jsonarray,true); + trigger_error("sendurl:".$apijson); + trigger_error( "sendacarps:".$json); + while(true){ + try{ + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, $apijson); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); + curl_setopt($ch, CURLOPT_POST, TRUE); + curl_setopt($ch, CURLOPT_CONNECTTIMEOUT ,5); + curl_setopt($ch, CURLOPT_TIMEOUT, 5); //timeout in seconds + curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query(array("data"=>$json))); + curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json')); + $result = curl_exec($ch); + trigger_error(curl_error($ch)); + curl_close($ch); + if($result != false) + { + if($result=="OK") + { + trigger_error( "sendacarps:ok"); + break; + } + } + else{trigger_error( "sendacarps_error");} + + if($i==4) + break; + }catch (Exception $e) + { + trigger_error( "sendacarps_try_error".$e); + break; + } + $i++; + } + } + } + + public function save_setting($data){ + $myfile = fopen("/home/data/alt_acarps_log.json", "a+") or die("Unable to open file!"); + fwrite($myfile, $data); + fclose($myfile); + } } diff --git a/models/api/Altpay_model.php b/models/api/Altpay_model.php new file mode 100644 index 0000000..6e968c5 --- /dev/null +++ b/models/api/Altpay_model.php @@ -0,0 +1,20 @@ +db=$this->load->database('local',true); + + } + + public function sel_info() { + $this->db->from('info'); + + $rows = $this->db->get(); + return $rows->result_array(); + } +} diff --git a/models/api/Master_db_model.php b/models/api/Master_db_model.php new file mode 100644 index 0000000..42a231d --- /dev/null +++ b/models/api/Master_db_model.php @@ -0,0 +1,105 @@ +db=$this->load->database('local',true); + + } + + public function sel_cario($lpr) { + $fee_time=date('Y-m-d H:i:s',mktime(0,0,0,date('m'),date('d'),date('Y'))+(date('H')*3600)+((date('i')-30)*60)+date('s')) ; +//print_r($fee_time);exit; + $this->db->select('*') + ->from('cario') + ->where('in_out','CI') + ->where('finished','0') + ->where('payed','0') + ->where('obj_id',$lpr) + ->order_by('in_time desc') + ->limit(1); + + $rows = $this->db->get(); + return $rows->result_array(); + + } + + public function sel_cario_all($lpr) { + + $this->db->from('cario') + ->where('in_out','CI') + ->where('lpr',$lpr) + ->order_by('in_time desc'); + + $rows = $this->db->get(); + return $rows->result_array(); + + } + + public function sel_cario_like($lpr) { + + $this->db->from('cario') + ->where('in_out','CI') + ->where('finished','0') + ->where('payed','0') + ->like('obj_id',$lpr) + ->group_by('obj_id') + ->order_by('in_time desc'); + + $rows = $this->db->get(); + return $rows->result_array(); + + } + + public function sel_carioseat($lpr) { + + $this->db->select('*') + ->from('cario') + ->where('in_out','CI') + ->where('finished','0') + ->where('payed','0') + ->where('obj_id',$lpr) + ->order_by('in_time desc') + ->limit(1); + + $rows = $this->db->get(); + return $rows->result_array(); + + } + + public function chk_carioseat($lpr) { + + $this->db->select('*') + ->from('cario') + ->where('in_out','CO') + ->where('obj_id',$lpr) + ->where('(finished=1 or payed=1)') + ->order_by('in_time desc') + ->limit(1); + + $rows = $this->db->get(); + return $rows->result_array(); + + } + + public function chk_pks_group_member($pksno,$group_id) { + + $this->db->select('group_id') + ->from('pks_group_member') + ->where('pksno',$pksno); + if($group_id!=''){ + $this->db->where('group_id',$group_id); + } + + $rows = $this->db->get(); + return $rows->result_array(); + + } + + + +}