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

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){ public function index($train_date=null,$fromStation=null,$toStation=null){
set_time_limit(0); set_time_limit(0);
if(!$train_date || !$fromStation || !$toStation){ if(!$train_date || !$fromStation || !$toStation){
exit('传参错误'); exit('传参不能为空');
}else{ }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://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; $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); $back_data = $this->get_http($url);
$reason = json_decode($back_data)->reason; $firstdata = $back_data;
$return_data = new stdClass(); $reason = json_decode($back_data)->reason;
$cache = 'no'; $return_data = new stdClass();
if(empty(json_decode($back_data)->result)){ $cache = 'no';
log_message('error','juhetrain:'.$url.' '.$back_data); if(empty(json_decode($back_data)->result)){
$obj = $this->BIZ_train_model->get_train_info($fromStation,$toStation); $obj = $this->BIZ_train_model->get_train_info($fromStation,$toStation);
if($obj){ if($obj){
$back_data = $obj->tpc_content; $back_data = $obj->tpc_content;
$cache = 'yes'; $cache = 'yes';
log_message('error','Sn:'.$obj->tpc_sn.'|time:'.$obj->tpc_datetime); $this->cache = true;
} log_message('error','查询为空的链接:'.$url.'|出错的原因:'.$firstdata.'|调用缓存号:'.$obj->tpc_sn.'|缓存生成的时间:'.$obj->tpc_datetime);
}else{ }else{
$this->BIZ_train_model->addOrUpdate($fromStation,$toStation,$back_data); log_message('error','查询为空的链接:'.$url.'|出错的原因:'.$firstdata.'|缓存为空');
} }
$return_data->httpstatus = 200; }else{
$return_data->reason = $reason; $this->BIZ_train_model->addOrUpdate($fromStation,$toStation,$back_data);
$return_data->cache = $cache; }
$return_data->data = new stdClass(); $return_data->httpstatus = 200;
$return_data->data->result = array(); $return_data->reason = $reason;
$return_data->data->map = new stdClass(); $return_data->cache = $cache;
$obj = array(); $return_data->data = new stdClass();
$i = 0; $return_data->data->result = array();
$pricestr = ''; $return_data->data->map = new stdClass();
if(!empty(json_decode($back_data)->result->list)){ $obj = array();
foreach (json_decode($back_data)->result->list as $value){ $i = 0;
$obj[$value->from_station_code] = $value->from_station_name; $pricestr = '';
$obj[$value->to_station_code] = $value->to_station_name; if(!empty(json_decode($back_data)->result->list)){
$seat_type = ''; foreach (json_decode($back_data)->result->list as $value){
if(isset($value->gjrw_price)){ $obj[$value->from_station_code] = $value->from_station_name;
if($value->gjrw_price > 0){ $obj[$value->to_station_code] = $value->to_station_name;
$gjrwPrice = $value->gjrw_price * 10; $seat_type = '';
$seat_type .= '"6":"'.$gjrwPrice.'","A6":"¥'.$value->gjrw_price.'",'; 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(isset($value->qtxb_price)){ if($value->qtxb_price > 0){
if($value->qtxb_price > 0){ $seat_type .= '"H":"¥'.$value->qtxb_price.'",';
$seat_type .= '"H":"¥'.$value->qtxb_price.'",'; }
} }
} if(isset($value->rw_price)){
if(isset($value->rw_price)){ if($value->rw_price > 0){
if($value->rw_price > 0){ $rwPrice = $value->rw_price * 10;
$rwPrice = $value->rw_price * 10; $seat_type .= '"4":"'.$rwPrice.'","A4":"¥'.$value->rw_price.'",';
$seat_type .= '"4":"'.$rwPrice.'","A4":"¥'.$value->rw_price.'",'; }
} }
} if(isset($value->rz_price)){
if(isset($value->rz_price)){ if($value->rz_price > 0){
if($value->rz_price > 0){ $rzPrice = $value->rz_price * 10;
$rzPrice = $value->rz_price * 10; $seat_type .= '"2":"'.$rzPrice.'","A2":"¥'.$value->rz_price.'",';
$seat_type .= '"2":"'.$rzPrice.'","A2":"¥'.$value->rz_price.'",'; }
} }
} if(isset($value->tdz_price)){
if(isset($value->tdz_price)){ if($value->tdz_price > 0){
if($value->tdz_price > 0){ $seat_type .= '"P":"¥'.$value->tdz_price.'",';
$seat_type .= '"P":"¥'.$value->tdz_price.'",'; }
} }
} if(isset($value->wz_price)){
if(isset($value->wz_price)){ if($value->wz_price > 0){
if($value->wz_price > 0){ $wzPrice = $value->wz_price * 10;
$wzPrice = $value->wz_price * 10; $seat_type .= '"WZ":"¥'.$value->wz_price.'",';
$seat_type .= '"WZ":"¥'.$value->wz_price.'",'; }
} }
} if(isset($value->yw_price)){
if(isset($value->yw_price)){ if($value->yw_price > 0){
if($value->yw_price > 0){ $ywPrice = $value->yw_price * 10;
$ywPrice = $value->yw_price * 10; $seat_type .= '"3":"'.$ywPrice.'","A3":"¥'.$value->yw_price.'",';
$seat_type .= '"3":"'.$ywPrice.'","A3":"¥'.$value->yw_price.'",'; }
} }
} if(isset($value->yz_price)){
if(isset($value->yz_price)){ if($value->yz_price > 0){
if($value->yz_price > 0){ $yzPrice = $value->yz_price * 10;
$yzPrice = $value->yz_price * 10; $seat_type .= '"1":"'.$yzPrice.'","A1":"¥'.$value->yz_price.'",';
$seat_type .= '"1":"'.$yzPrice.'","A1":"¥'.$value->yz_price.'",'; }
} }
} if(isset($value->edz_price)){
if(isset($value->edz_price)){ if($value->edz_price > 0){
if($value->edz_price > 0){ $seat_type .= '"O":"¥'.$value->edz_price.'",';
$seat_type .= '"O":"¥'.$value->edz_price.'",'; }
} }
} if(isset($value->ydz_price)){
if(isset($value->ydz_price)){ if($value->ydz_price > 0){
if($value->ydz_price > 0){ $seat_type .= '"M":"¥'.$value->ydz_price.'",';
$seat_type .= '"M":"¥'.$value->ydz_price.'",'; }
} }
} if(isset($value->swz_price)){
if(isset($value->swz_price)){ if($value->swz_price > 0){
if($value->swz_price > 0){ $swzPrice = $value->swz_price * 10;
$swzPrice = $value->swz_price * 10; $seat_type .= '"9":"'.$swzPrice.'","A9":"¥'.$value->swz_price.'",';
$seat_type .= '"9":"'.$swzPrice.'","A9":"¥'.$value->swz_price.'",'; }
} }
} if(isset($value->dw_price)){
if(isset($value->dw_price)){ if($value->dw_price > 0){
if($value->dw_price > 0){ $seat_type .= '"F":"¥'.$value->dw_price.'",';
$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;
$return_data->data->map = (object)$obj; print_r(json_encode($return_data));
print_r(json_encode($return_data)); }
}
} }
//获取价格 //获取价格
@ -147,19 +157,29 @@ class search extends CI_Controller{
//余票转换 //余票转换
function ticket_exchange($num){ function ticket_exchange($num){
if(is_numeric($num)){ if(isset($this->cache)){
if($num == 0){ $time = strtotime($this->train_date) - time();
return '无'; $day = $time / 86400;
}elseif($num >= 99){ if($day > 15){
return '有'; return '有';
}else{ }else{
return $num; return $num;
} }
}else{ }else{
if($num == '--'){ if(is_numeric($num)){
return ''; if($num == 0){
} return '无';
} }elseif($num >= 99){
return '有';
}else{
return $num;
}
}else{
if($num == '--'){
return '';
}
}
}
} }
//发送请求 //发送请求

Loading…
Cancel
Save