|
- <?php
- date_default_timezone_set('GMT');
- //载入配置文件和连接数据库
- $start_area = trim($_POST['start_area_id']);
- $start_res = trim($_POST['start_res_id']);
- $end_area = trim($_POST['end_area_id']);
- $end_res = trim($_POST['end_res_id']);
- $run_id = trim($_POST['run_id']);
- $price_type = 1;
- //$line_id = 152248;
-
- $line_id = '';//线路ID
- $run_date = '';//出发时间
- $price_name = '';//分销价或零售价
-
- //寻找返程对应线路编码
- $line_code = '';
- $line_str1 = '';
- $line_str2 = '';
- $line_str3 = '';
- $line_str_back = '';
- $back_line = '';
-
- //巴士类型
- $bus_type = '';
-
- //班次站点信息
- $run_station = array();
-
- //顺序站点
- $res_station_seq = array();
-
- //余票信息
- $ticket_over = array();
- $ticket_over_array = array();
- $ticket_over_id = array();
-
- //途经站点
- $res_array = array();
- $cen_station = array();//只有ID
- $center_station = array();
-
- //全程公里数
- $center_distance = 0;
-
- //票种信息
- $ticket_info = array();
- $ticket_go = array();
- $ticket_back = array();
- $ticket = array();
- $back_ticket_go = array();
- $back_ticket_back = array();
-
- //线路可选的票种数组
- $line_ticket_id = array();
- $line_ticket_info = array();
-
-
- //中间时间
- $center_time = '';
-
- //上车站数组
- $start_res_array = array();
-
- //下车站数组
- $end_res_array = array();
-
- //地图
- $map = array();
-
-
- //终极数组
- $final = array();
-
- if($price_type ==1){
- $price_name = "cus_price";
- }else{
- $price_name = "prod_price";
- }
-
- $sql = "SELECT
- a.run_id,
- a.run_status,
- a.run_date,
- a.prod_id,
- b.start_time,
- b.station_order_id,
- b.station_res_id,
- b.station_inout_type,
- b.area_id
- FROM
- run_main AS a,
- run_station AS b
- WHERE
- a.run_id = b.run_id
- AND a.run_id = " . $run_id . "
- AND a.run_status = 138
- ORDER BY
- a.run_id,
- b.station_order_id ";
-
- $result=$pdo->query($sql);
- $run_station = $result->fetchAll(PDO::FETCH_ASSOC);
- writeLog($sql);
-
- $line_id = $run_station[0]['prod_id'];
- $run_date = $run_station[0]['run_date'];
-
- $sql = "SELECT
- run_id,
- res_id,
- seq_id,
- prod_id,
- total_count,
- saled_count
- FROM
- run_stock
- WHERE
- run_id = " . $run_id . "
- AND seat_type = 72
- ORDER BY
- run_id ASC,
- seq_id ASC";
-
- $result=$pdo->query($sql);
- $ticket_over_id = $result->fetchAll(PDO::FETCH_ASSOC);
- writeLog($sql);
-
- foreach($ticket_over_id as $k => $v){
- $ticket_over[$v['res_id']] = $v['total_count'] - $v['saled_count'];
- }
-
- $sql = "select prod_id from run_prod where run_id = " . $run_id;
- $result=$pdo->query($sql);
- $line_ticket_id = $result->fetchAll(PDO::FETCH_ASSOC);
- writeLog($sql);
- foreach($line_ticket_id as $k => $v){
- $line_ticket_info[$v['prod_id']] = $v['prod_id'];
- }
-
-
- foreach($line_array[$line_id]['ticket_info']['go'] as $k => $v){
- if(in_array($k,$line_ticket_info) && $v['start_area'] == $start_area && $v['end_area'] == $end_area){
- $start_res_array[$v['start_res']]['res_id'] = $v['start_res'];
- $start_res_array[$v['start_res']]['res_name'] = $v['start_res_name'];
- $end_res_array[$v['end_res']]['res_id'] = $v['end_res'];
- $end_res_array[$v['end_res']]['res_name'] = $v['end_res_name'];
- }else{
- unset($line_array[$line_id]['ticket_info']['go'][$k]);
- }
- }
- //print_r($start_res_array);print_r($end_res_array);
-
-
- foreach($run_station as $k => $v){
- $res_id_array[$v['station_res_id']] = $v['station_res_id'];
- $res_station_seq[$v['station_res_id']] = $v['station_order_id'];
- if(isset($start_res_array[$v['station_res_id']]) && ($v['station_inout_type'] == 108 || $v['station_inout_type'] == 109)){
- $start_res_array[$v['station_res_id']]['start_time'] = $v['start_time'];
- }elseif(isset($end_res_array[$v['station_res_id']])){
- unset($start_res_array[$v['station_res_id']]);
- }
- if(isset($end_res_array[$v['station_res_id']]) && ($v['station_inout_type'] == 110 || $v['station_inout_type'] == 109)){
- $end_res_array[$v['station_res_id']]['start_time'] = $v['start_time'];
- }elseif(isset($end_res_array[$v['station_res_id']])){
- unset($end_res_array[$v['station_res_id']]);
- }
- }
-
- foreach($start_res_array as $k => $v){
- $res_array1[$v['start_time']] = $v;
- }
- foreach($end_res_array as $k => $v){
- $res_array1[$v['start_time']] = $v;
- }
- ksort($res_array1);
-
-
-
- foreach($line_array[$line_id]['ticket_info']['go'] as $k=>$v){
- if($v['start_area'] == $start_area && $v['start_res'] == $start_res && $v['end_area'] == $end_area && $v['end_res'] == $end_res){
- $ticket_info = $line_array[$line_id]['ticket_info']['go'][$k];
- }
- }
- if(!empty($ticket_info)){
- //将基本数据放入数组中
-
- $final['start_res_id'] = $start_res;
- $final['start_res_name'] = $ticket_info['start_res_name'];
-
- $final['end_res_id'] = $end_res;
- $final['end_res_name'] = $ticket_info['end_res_name'];
-
- if($end_res_array[$final['end_res_id']]['start_time'] < $start_res_array[$final['start_res_id']]['start_time']){
- $center_time = strtotime($end_res_array[$final['end_res_id']]['start_time']) + 24*3600 - strtotime($start_res_array[$final['start_res_id']]['start_time']);
- }else{
- $center_time = strtotime($end_res_array[$final['end_res_id']]['start_time']) - strtotime($start_res_array[$final['start_res_id']]['start_time']);
- }
- $final['start_time'] = $start_res_array[$final['start_res_id']]['start_time'];
- $final['end_time'] = $end_res_array[$final['end_res_id']]['start_time'];
-
- $final['center_time'] = date('用时G小时i分钟',$center_time);
-
- //print_r($final);
-
- //途经站点信息($center_station经度,纬度,里程)
-
- $sta_status = 0;
- foreach($res_array1 as $k => $v){
- if($v['res_id'] == $final['start_res_id']){
- $sta_status++;
- }
- if($sta_status > 0){
- $cen_station[$v['res_id']] = $v['res_id'];
- }
- if($v['res_id'] == $final['end_res_id']){
- $sta_status = 0;
- }
- $res_array[$v['res_id']] = $v;
- }
-
- $sql = "SELECT
- a.res_id,
- a.property AS longitude,
- b.property AS latitude,
- c.distance
- FROM
- base_resource_property AS a,
- base_resource_property AS b,
- opera_product_station AS c
- WHERE
- a.res_id = c.res_id
- AND a.res_id = b.res_id
- AND a.type_id = 212
- AND b.type_id = 213
- AND a.cancel_flag = 0
- AND b.cancel_flag = 0
- AND a.res_id IN (" . implode(",",$cen_station) . ")
- AND c.prod_id = " . $line_id . "
- GROUP BY
- a.res_id";
-
- $result=$pdo->query($sql);
- $cen_station = $result->fetchAll(PDO::FETCH_ASSOC);
- writeLog($sql);
-
- foreach($cen_station as $v){
- $cen_station1[$res_station_seq[$v['res_id']]] = $v;
- }
- ksort($cen_station1);
- foreach($cen_station1 as $v){
- $center_station[$v['res_id']] = $v;
- $center_station[$v['res_id']]['res_name'] = $res_array[$v['res_id']]['res_name'];
- //全程公里数
- //$center_distance += $v['distance'];
- }
-
- $sql = "select order_id,res_id,distance from opera_product_station where prod_id = " . $line_id . " order by order_id";
- $result=$pdo->query($sql);
- $cen_distance_array = $result->fetchAll(PDO::FETCH_ASSOC);
- writeLog($sql);
- $cen_status = 0;
- foreach($cen_distance_array as $k => $v){
- if($v['res_id'] == $start_res){
- $cen_status++;
- }
- if($cen_status > 0){
- $center_distance += $v['distance'];
- }
- if($v['res_id'] == $end_res){
- break;
- }
- }
- //print_r($center_station);
- //全程公里数
- if($center_distance != 0){
- $final['distance'] = (string)$center_distance;
- }else{
- $final['distance'] = '30';
- }
-
- //票种信息
- $ticket_go = $ticket_info;
- $ticket_back = array();
- foreach($line_array[$line_id]['ticket_info']['back'] as $k => $v){
- if($v['start_area'] == $start_area && $v['start_res'] == $start_res && $v['end_area'] == $end_area && $v['end_res'] == $end_res){
- $ticket_back = $v;
- }
- }
-
- $tick_over_status = 0;
- foreach($ticket_over as $k => $v){
- if($k == $final['end_res_id']){
- break;
- }
- if($k == $final['start_res_id'] || $tick_over_status > 0){
- $ticket_over_array[] = $v;
- $tick_over_status++;
- }
- }
- asort($ticket_over_array);
- $ticket_over_array = array_values($ticket_over_array);
-
- if(!empty($ticket_go) && !empty($ticket_back)){
- //根据线路编码找相反线路
- if($bus_type == 255){
- $line_code = $line_array[$line_id]['line_info']['line_no'];
- $line_str1 = substr($line_code,0,2);
- $line_str2 = substr($line_code,2,2);
- $line_str3 = substr($line_code,4,2);
- $line_str_back = $line_str2.$line_str1.$line_str3;
- foreach($line_array as $line_key => $line_vel){
- if(strpos($line_vel['line_info']['line_no'],$line_str_back) !== false){
- $back_line = $line_key;
- break;
- }
- }
- if(!empty($back_line)){
- foreach($line_array[$back_line]['ticket_info']['go'] as $k => $v){
- if($v['start_area'] == $end_area && $v['end_area'] == $start_area){
- $back_ticket_go = $v;
- break;
- }
- }
-
- foreach($line_array[$back_line]['ticket_info']['back'] as $k => $v){
- if($v['start_area'] == $end_area && $v['end_area'] == $start_area){
- $back_ticket_back = $v;
- break;
- }
- }
- }
- }else{
- $line_code = $line_array[$line_id]['line_info']['prod_name'];
- $line_str = explode("-",$line_code);
- $line_str_back = $line_str[1] . "-" . $line_str[0];
- foreach($line_array as $line_key => $line_vel){
- if($line_vel['line_info']['prod_name'] == $line_str_back){
- $back_line = $line_key;
- break;
- }
- }
- if(!empty($back_line)){
- foreach($line_array[$back_line]['ticket_info']['go'] as $k => $v){
- if($v['start_area'] == $end_area && $v['end_area'] == $start_area){
- $back_ticket_go = $v;
- break;
- }
- }
-
- foreach($line_array[$back_line]['ticket_info']['back'] as $k => $v){
- if($v['start_area'] == $end_area && $v['end_area'] == $start_area){
- $back_ticket_back = $v;
- break;
- }
- }
- }
- //print_r($back_line);
- }
- //print_r($back_ticket_go); print_r($back_ticket_back);
- if(!empty($back_ticket_go) && !empty($back_ticket_back)){
- $ticket['ticket_id_go'] = $ticket_go['prod_id'];
- $ticket['go_price'] = (string)((int)$ticket_go[$price_name]);
- $ticket['ticket_id_back'] = $ticket_back['prod_id'];
- $ticket['discount_price'] = (string)(ceil($ticket_go[$price_name] + $back_ticket_go[$price_name] - $ticket_back[$price_name] - $back_ticket_back[$price_name]));
-
- setcookie("go_price_go", $ticket['go_price'], time() + 36000);
- setcookie("go_price_back", $ticket_back[$price_name], time() + 36000);
-
- $ticket['ticket_over'] = (string)$ticket_over_array[0];
- }else{
- $ticket['ticket_id_go'] = $ticket_go['prod_id'];;
- $ticket['go_price'] = (string)((int)$ticket_go[$price_name]);
- $ticket['ticket_id_back'] = "";
- $ticket['back_price'] = "";
- $ticket['discount_price'] = "0";
- $ticket['ticket_over'] = (string)$ticket_over_array[0];
- }
-
- }elseif(!empty($ticket_go) ){
- $ticket['ticket_id_go'] = $ticket_go['prod_id'];;
- $ticket['go_price'] = (string)((int)$ticket_go[$price_name]);
- $ticket['ticket_id_back'] = "";
- $ticket['discount_price'] = "0";
- $ticket['ticket_over'] = (string)$ticket_over_array[0];
- }else{
- $ticket['ticket_id_go'] = "";
- $ticket['go_price'] = "";
- $ticket['ticket_id_back'] = "";
- $ticket['discount_price'] = "0";
- $ticket['ticket_over'] = '0';
- }
-
- $final['ticket'] = $ticket;
- $final['ticket']['site'] = "普通座";
- $final['ticket']['run_type'] = "单程";
-
-
- //地图
- $map = array_merge($center_station);
- $final['map']['start'] = $map[0];
- $final['map']['center'] = array_merge(array_slice($map,1,-1));
- $map_end = array_merge(array_slice($map,-1,1));
- $final['map']['end'] = $map_end[0];
-
- $json = array();
- $json['code'] = '0';
- $json['info'] = "返回数据成功";
- $json['list'] = $final;
- }else{
- $json = array();
- $json['code'] = '1';
- $json['info'] = "无票种";
- $json['list'] = array();
- }
-
-
-
- //print_r($json);
-
- echo json_encode($json);
-
- ?>
|