修改日志的记录条件以及各式,修改缓存余票

hotfix/远程访问多媒体中心
cyc 8 years ago
parent 936794054c
commit 23d2011d6a

@ -13,117 +13,127 @@ class search extends CI_Controller{
public function index($train_date=null,$fromStation=null,$toStation=null){
set_time_limit(0);
if(!$train_date || !$fromStation || !$toStation){
exit('传参错误');
exit('传参不能为空');
}else{
if(strlen($fromStation) != 3){
exit('fromStation:参数错误!');
}
if(strlen($toStation) != 3){
exit('toStation:参数错误!');
}
$this->train_date = $train_date;
//$url = 'http://op.juhe.cn/trainTickets/ticketsAvailable?key='.JUHE_TRAIN_API_KEY.'&train_date='.$train_date.'&from_station='.$fromStation.'&to_station='.$toStation;
$url = 'http://139.129.246.118:12309/trainTickets/ticketsAvailable?key='.JUHE_TRAIN_API_KEY.'&train_date='.$train_date.'&from_station='.$fromStation.'&to_station='.$toStation;
$back_data = $this->get_http($url);
$reason = json_decode($back_data)->reason;
$return_data = new stdClass();
$cache = 'no';
if(empty(json_decode($back_data)->result)){
log_message('error','juhetrain:'.$url.' '.$back_data);
$obj = $this->BIZ_train_model->get_train_info($fromStation,$toStation);
$back_data = $this->get_http($url);
$firstdata = $back_data;
$reason = json_decode($back_data)->reason;
$return_data = new stdClass();
$cache = 'no';
if(empty(json_decode($back_data)->result)){
$obj = $this->BIZ_train_model->get_train_info($fromStation,$toStation);
if($obj){
$back_data = $obj->tpc_content;
$cache = 'yes';
log_message('error','Sn:'.$obj->tpc_sn.'|time:'.$obj->tpc_datetime);
}
}else{
$this->BIZ_train_model->addOrUpdate($fromStation,$toStation,$back_data);
}
$return_data->httpstatus = 200;
$return_data->reason = $reason;
$return_data->cache = $cache;
$return_data->data = new stdClass();
$return_data->data->result = array();
$return_data->data->map = new stdClass();
$obj = array();
$i = 0;
$pricestr = '';
if(!empty(json_decode($back_data)->result->list)){
foreach (json_decode($back_data)->result->list as $value){
$obj[$value->from_station_code] = $value->from_station_name;
$obj[$value->to_station_code] = $value->to_station_name;
$seat_type = '';
if(isset($value->gjrw_price)){
if($value->gjrw_price > 0){
$gjrwPrice = $value->gjrw_price * 10;
$seat_type .= '"6":"'.$gjrwPrice.'","A6":"¥'.$value->gjrw_price.'",';
$this->cache = true;
log_message('error','查询为空的链接:'.$url.'|出错的原因:'.$firstdata.'|调用缓存号:'.$obj->tpc_sn.'|缓存生成的时间:'.$obj->tpc_datetime);
}else{
log_message('error','查询为空的链接:'.$url.'|出错的原因:'.$firstdata.'|缓存为空');
}
}else{
$this->BIZ_train_model->addOrUpdate($fromStation,$toStation,$back_data);
}
$return_data->httpstatus = 200;
$return_data->reason = $reason;
$return_data->cache = $cache;
$return_data->data = new stdClass();
$return_data->data->result = array();
$return_data->data->map = new stdClass();
$obj = array();
$i = 0;
$pricestr = '';
if(!empty(json_decode($back_data)->result->list)){
foreach (json_decode($back_data)->result->list as $value){
$obj[$value->from_station_code] = $value->from_station_name;
$obj[$value->to_station_code] = $value->to_station_name;
$seat_type = '';
if(isset($value->gjrw_price)){
if($value->gjrw_price > 0){
$gjrwPrice = $value->gjrw_price * 10;
$seat_type .= '"6":"'.$gjrwPrice.'","A6":"¥'.$value->gjrw_price.'",';
}
}
}
if(isset($value->qtxb_price)){
if($value->qtxb_price > 0){
$seat_type .= '"H":"¥'.$value->qtxb_price.'",';
if(isset($value->qtxb_price)){
if($value->qtxb_price > 0){
$seat_type .= '"H":"¥'.$value->qtxb_price.'",';
}
}
}
if(isset($value->rw_price)){
if($value->rw_price > 0){
$rwPrice = $value->rw_price * 10;
$seat_type .= '"4":"'.$rwPrice.'","A4":"¥'.$value->rw_price.'",';
if(isset($value->rw_price)){
if($value->rw_price > 0){
$rwPrice = $value->rw_price * 10;
$seat_type .= '"4":"'.$rwPrice.'","A4":"¥'.$value->rw_price.'",';
}
}
}
if(isset($value->rz_price)){
if($value->rz_price > 0){
$rzPrice = $value->rz_price * 10;
$seat_type .= '"2":"'.$rzPrice.'","A2":"¥'.$value->rz_price.'",';
if(isset($value->rz_price)){
if($value->rz_price > 0){
$rzPrice = $value->rz_price * 10;
$seat_type .= '"2":"'.$rzPrice.'","A2":"¥'.$value->rz_price.'",';
}
}
}
if(isset($value->tdz_price)){
if($value->tdz_price > 0){
$seat_type .= '"P":"¥'.$value->tdz_price.'",';
if(isset($value->tdz_price)){
if($value->tdz_price > 0){
$seat_type .= '"P":"¥'.$value->tdz_price.'",';
}
}
}
if(isset($value->wz_price)){
if($value->wz_price > 0){
$wzPrice = $value->wz_price * 10;
$seat_type .= '"WZ":"¥'.$value->wz_price.'",';
if(isset($value->wz_price)){
if($value->wz_price > 0){
$wzPrice = $value->wz_price * 10;
$seat_type .= '"WZ":"¥'.$value->wz_price.'",';
}
}
}
if(isset($value->yw_price)){
if($value->yw_price > 0){
$ywPrice = $value->yw_price * 10;
$seat_type .= '"3":"'.$ywPrice.'","A3":"¥'.$value->yw_price.'",';
if(isset($value->yw_price)){
if($value->yw_price > 0){
$ywPrice = $value->yw_price * 10;
$seat_type .= '"3":"'.$ywPrice.'","A3":"¥'.$value->yw_price.'",';
}
}
}
if(isset($value->yz_price)){
if($value->yz_price > 0){
$yzPrice = $value->yz_price * 10;
$seat_type .= '"1":"'.$yzPrice.'","A1":"¥'.$value->yz_price.'",';
if(isset($value->yz_price)){
if($value->yz_price > 0){
$yzPrice = $value->yz_price * 10;
$seat_type .= '"1":"'.$yzPrice.'","A1":"¥'.$value->yz_price.'",';
}
}
}
if(isset($value->edz_price)){
if($value->edz_price > 0){
$seat_type .= '"O":"¥'.$value->edz_price.'",';
if(isset($value->edz_price)){
if($value->edz_price > 0){
$seat_type .= '"O":"¥'.$value->edz_price.'",';
}
}
}
if(isset($value->ydz_price)){
if($value->ydz_price > 0){
$seat_type .= '"M":"¥'.$value->ydz_price.'",';
if(isset($value->ydz_price)){
if($value->ydz_price > 0){
$seat_type .= '"M":"¥'.$value->ydz_price.'",';
}
}
}
if(isset($value->swz_price)){
if($value->swz_price > 0){
$swzPrice = $value->swz_price * 10;
$seat_type .= '"9":"'.$swzPrice.'","A9":"¥'.$value->swz_price.'",';
if(isset($value->swz_price)){
if($value->swz_price > 0){
$swzPrice = $value->swz_price * 10;
$seat_type .= '"9":"'.$swzPrice.'","A9":"¥'.$value->swz_price.'",';
}
}
}
if(isset($value->dw_price)){
if($value->dw_price > 0){
$seat_type .= '"F":"¥'.$value->dw_price.'",';
if(isset($value->dw_price)){
if($value->dw_price > 0){
$seat_type .= '"F":"¥'.$value->dw_price.'",';
}
}
$pricestr = $seat_type.'"train_no":'.'"'.$value->train_no.'"';
//余票字符串
$return_data->data->result[$i] = '|预定|'.$value->train_no.'|'.$value->train_code.'|'.$value->from_station_name.'|'.$value->to_station_name.'|'.$value->from_station_code.'|'.$value->to_station_code.'|'.$value->start_time.'|'.$value->arrive_time.'|'.$value->run_time.'|'.$value->can_buy_now.'||'.$value->train_start_date.'||||||||'.$this->ticket_exchange($value->gjrw_num).'|'.$this->ticket_exchange($value->qtxb_num).'|'.$this->ticket_exchange($value->rw_num).'|'.$this->ticket_exchange($value->rz_num).'|'.$this->ticket_exchange($value->tdz_num).'|'.$this->ticket_exchange($value->wz_num).'||'.$this->ticket_exchange($value->yw_num).'|'.$this->ticket_exchange($value->yz_num).'|'.$this->ticket_exchange($value->edz_num).'|'.$this->ticket_exchange($value->ydz_num).'|'.$this->ticket_exchange($value->swz_num).'|'.$this->ticket_exchange($value->dw_num).'||';
$data = '{"validateMessagesShowId":"_validatorMessage","status":true,"httpstatus":200,"data":{'.$pricestr.'},"messages":[],"validateMessages":{}}';
$return_data->data->price[$i] = $data;
$i++;
}
$pricestr = $seat_type.'"train_no":'.'"'.$value->train_no.'"';
//余票字符串
$return_data->data->result[$i] = '|预定|'.$value->train_no.'|'.$value->train_code.'|'.$value->from_station_name.'|'.$value->to_station_name.'|'.$value->from_station_code.'|'.$value->to_station_code.'|'.$value->start_time.'|'.$value->arrive_time.'|'.$value->run_time.'|'.$value->can_buy_now.'||'.$value->train_start_date.'||||||||'.$this->ticket_exchange($value->gjrw_num).'|'.$this->ticket_exchange($value->qtxb_num).'|'.$this->ticket_exchange($value->rw_num).'|'.$this->ticket_exchange($value->rz_num).'|'.$this->ticket_exchange($value->tdz_num).'|'.$this->ticket_exchange($value->wz_num).'||'.$this->ticket_exchange($value->yw_num).'|'.$this->ticket_exchange($value->yz_num).'|'.$this->ticket_exchange($value->edz_num).'|'.$this->ticket_exchange($value->ydz_num).'|'.$this->ticket_exchange($value->swz_num).'|'.$this->ticket_exchange($value->dw_num).'||';
$data = '{"validateMessagesShowId":"_validatorMessage","status":true,"httpstatus":200,"data":{'.$pricestr.'},"messages":[],"validateMessages":{}}';
$return_data->data->price[$i] = $data;
$i++;
}
}
$return_data->data->map = (object)$obj;
print_r(json_encode($return_data));
}
$return_data->data->map = (object)$obj;
print_r(json_encode($return_data));
}
}
//获取价格
@ -147,19 +157,29 @@ class search extends CI_Controller{
//余票转换
function ticket_exchange($num){
if(is_numeric($num)){
if($num == 0){
return '无';
}elseif($num >= 99){
if(isset($this->cache)){
$time = strtotime($this->train_date) - time();
$day = $time / 86400;
if($day > 15){
return '有';
}else{
return $num;
}
}else{
if($num == '--'){
return '';
}
}
if(is_numeric($num)){
if($num == 0){
return '无';
}elseif($num >= 99){
return '有';
}else{
return $num;
}
}else{
if($num == '--'){
return '';
}
}
}
}
//发送请求

Loading…
Cancel
Save