|
- <?php
-
- date_default_timezone_set('GMT');
-
- $run_id = trim($_POST['run_id']);
- $ticket_id= trim($_POST['ticket_id']);
- $price_type = 1;
- //$line_id = 152248;
-
- $line_id = '';//线路ID
- $run_date = '';//出发时间
- $price_name = '';//分销价或零售价
-
- //巴士类型
- $bus_type = '';
-
- $ticket_type = '';
-
- //班次站点信息
- $run_station = array();
-
- //顺序站点
- $res_station_seq = array();
-
- //余票信息
- $ticket_over = array();
- $ticket_over_array = array();
- $ticket_over_id = array();
-
-
- //线路可选的票种数组
- $line_ticket_id = array();
- $line_ticket_info = array();
-
- //票种信息
- $ticket_info = array();
- $ticket = array();
-
- //上车站数组
- $start_res_array = array();
-
- //下车站数组
- $end_res_array = array();
-
- //站点数组
- $res_array = array();
- $res_id_array = array();
-
-
- //终极数组
- $final = array();
-
- //上车站-下车站信息
- $start_area = '';
- $start_res = '';
- $end_area = '';
- $end_res = '';
-
- if($price_type ==1){
- $price_name = "cus_price";
- }else{
- $price_name = "prod_price";
- }
-
- $sql = "select ticket_mark from opera_product where prod_id = " . $ticket_id;
- $result=$pdo->query($sql);
- $ticket_type = $result->fetchAll(PDO::FETCH_ASSOC);
- writeLog($sql);
-
- if($ticket_type[0]['ticket_mark'] == 0 || $ticket_type[0]['ticket_mark'] == 1){
- $ticket_type = 'go';
- }else{
- $ticket_type = 'back';
- }
-
- $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);
-
- $run_date = $run_station[0]['run_date'];
-
- $line_id = $run_station[0]['prod_id'];
-
-
- $ticket_info = $line_array[$line_id]['ticket_info'][$ticket_type][$ticket_id];
-
- $start_area = $ticket_info['start_area'];
- $start_res = $ticket_info['start_res'];
- $end_area = $ticket_info['end_area'];
- $end_res = $ticket_info['end_res'];
- $bus_type = $line_array[$line_id]['line_info']['bus_type'];
- if($bus_type == 0 || $bus_type == 255 ){
- $bus_type = 255;
- }else{
- $bus_type = 256;
- }
-
-
- if($ticket_type == 'back'){
- 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_go = $v;
- }
- }
- }
-
- $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]);
- }
- }
-
- 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($start_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']]);
- }
- }
-
-
-
- $sql = "SELECT
- res_id,
- res_name
- FROM
- base_resource
- WHERE
- id IN (" . implode(",",$res_id_array) . ")";
-
- $result=$pdo->query($sql);
- $res_id_array = $result->fetchAll(PDO::FETCH_ASSOC);
- writeLog($sql);
- foreach($res_id_array as $k => $v){
- $res_array1[$res_station_seq[$v['res_id']]]['res_id'] = $v['res_id'];
- $res_array1[$res_station_seq[$v['res_id']]]['res_name'] = $v['res_name'];
- }
- ksort($res_array1);
- foreach($res_array1 as $k => $v){
- $res_array[$v['res_id']] = $v['res_name'];
- }
-
-
- //echo $run_date.$line_id;
-
- foreach($start_res_array as $k => $v){
- $start_res_array[$k]['res_name'] = $res_array[$k];
- }
- foreach($end_res_array as $k => $v){
- $end_res_array[$k]['res_name'] = $res_array[$k];
- }
-
- //将基本数据放入数组中
- $final['run_date'] = $run_date;
-
- $final['run_id'] = $run_id;
-
- $final['line_id'] = $line_id;
-
- $final['bus_type'] = $bus_type;
-
- $final['start_area_id'] = $start_area;
-
- $final['start_area_name'] = $ticket_info['start_area_name'];
-
- $final['start_res_id'] = $start_res;
-
- $final['start_res_name'] = $ticket_info['start_res_name'];
-
- $final['end_area_id'] = $end_area;
-
- $final['end_area_name'] = $ticket_info['end_area_name'];
-
-
- $final['end_res_id'] = $end_res;
- $final['end_res_name'] = $ticket_info['end_res_name'];
-
- $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['start_res_array']['area_name'] = $final['start_area_name'];
- $final['start_res_array']['station'] = array_merge($start_res_array);
-
- $final['end_res_array']['area_name'] = $final['end_area_name'];
- $final['end_res_array']['station'] = array_merge($end_res_array);
-
- //print_r($ticket_go);print_r($ticket_back);
- $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);
-
- $ticket['ticket_id'] = $ticket_id;
- $ticket['ticket_type'] = $ticket_type;
- $setcookie_go = $_COOKIE['go_price_go'];
- $setcookie_back = $_COOKIE['go_price_back'];
- $ticket['go_price'] = (string)$ticket_info_go[$price_name];
-
- if($ticket_type == 'back'){
- $ticket['price'] = (string)(ceil($ticket_info[$price_name]+$setcookie_back-$setcookie_go));
- $ticket['discount_price'] = (string)(ceil($setcookie_go-$ticket['price']));
- }else{
- $ticket['discount_price'] = '0';
- $ticket['price'] = $ticket_info[$price_name];
- }
-
- $ticket['ticket_over'] = (string)$ticket_over_array[0];
-
- $final['ticket'] = $ticket;
- $final['ticket']['site'] = "普通座";
- $final['ticket']['run_type'] = "往返";
-
- $json = array();
- $json['code'] = '0';
- $json['info'] = "返回数据成功";
- $json['list'] = $final;
- echo json_encode($json);
-
- ?>
|