|
- <?php
- require_once '../st-xm/Common/Mysql.php';
- require_once '../st-xm/Common/config_api.inc';
- header("Access-Control-Allow-Origin:*");
-
- $no_sell_array = array(152739,152740,152741,152691,152697,152715,152709,152715,153133,153135,153137,152569,152570,152571,152572,152573,152575,152577,152579,152581,152582,152695,152696,152706,152707);
-
- $limit_sell_prod = array( 152248, 152251);
- $auth_code=isset($_POST['auth'])? $_POST['auth']:false;
- $run_code=isset($_POST['coachNo'])? $_POST['coachNo']:false;
- $return_data = array();
- $return_data['code']='201';
- $current_time = time();
- $current_hour = date("H:i:s",$current_time);
- $today = date("Y-m-d");
- $limit_time = date("H:i", strtotime("+30 minutes"));
- $tomorrow_day = date("Y-m-d",strtotime("+1 days"));
- if( $auth_code == false || $run_code == false ) {
- $return_data['ret']= false;
- $return_data['errmsg']= '请求信息有误';
- $return_data['errcode']='102';
- $return_data['time']=$current_time;
- $return_data['auth']=get_qunar_auth($return_data);
- echo json_encode($return_data);
- exit();
- }
-
- $pdo=conn1();
- $param_run_code = $run_code;
- $run_code_array = explode("_",$run_code);
- if( !isset($run_code_array[1]) ) {
- require_once '../st-xm/Common/zizai_orderAPI.php';
- $prod_id = $run_code_array[0];
- $sql = " SELECT * FROM outside_run WHERE prod_code='".$prod_id."' AND cancel_flag = 0 ";
- $result=$pdo->query($sql);
- $rowset=$result->fetchAll();
- $result->closeCursor();
- if( $rowset == false ) {
- $return_data['ret']= false;
- $return_data['errmsg']= '线路信息不存在';
- $return_data['errcode']='103';
- $return_data['time']=$current_time;
- $return_data['auth']=get_qunar_auth($return_data);
- echo json_encode($return_data);
- exit();
- }
- $ourside_run_info = $rowset[0];
- $ccode = $ourside_run_info["line_code"];
- $runid = $ourside_run_info["run_code"];
- $ticketId = $prod_id;
- $ticketInfo = new orderService();
- $ticklist = $ticketInfo->ticket(zizaiArgs::$USER, $ccode, $runid);
- $ticket = $ticklist['ticket_list']['ticket'];
- $remain_count =0;
- if ($ticklist['code'] == 0) {
- if (isset($ticket['ticketid']) && $ticketId == $ticket['ticketid']) {
- $remain_count = $ticket['ticketcount'];
- } else {
- foreach ($ticket as $ticketInfo) {
- if (isset($ticketInfo['ticketid']) && strcmp($ticketId, $ticketInfo['ticketid'])) {
- $remain_count = $ticketInfo['ticketcount'];
- break;
- }
- }
- }
- }
- $sql_update = " UPDATE outside_run SET remain_count={$remain_count} WHERE prod_code='".$prod_id."' ";
- $pdo=conn1();
- $pdo->exec($sql_update);
- $data_array = array();
- $data_array["coachNo"] = $param_run_code;
- $data_array["date"] = $ourside_run_info["start_date"];
- $data_array["startTime"] = $ourside_run_info["start_time"];
- $data_array["price"] = $ourside_run_info["cus_price"];
- $data_array["from"] = $ourside_run_info["start_area"];
- $data_array["to"] = $ourside_run_info["end_area"];
- $data_array["fromStation"] = $ourside_run_info["start_res"];
- $data_array["toStation"] = $ourside_run_info["end_res"];
- $data_array["ticketNum"] = $remain_count > 3 ? ($remain_count - 3) : 0;
-
- $return_data = array();
- $return_data["ret"] = true;
- $return_data["agentId"] = QUNAR_AGENT_ID;
- $return_data["time"] = $current_time;
- $return_data["auth"] = get_qunar_auth($return_data);
- $return_data["data"] = $data_array;
-
- echo json_encode($return_data);
- exit();
- }
-
- $run_code = $run_code_array[0];
- $prod_id = $run_code_array[1];
- if( in_array($prod_id, $no_sell_array) ) {
- $return_data['ret']= false;
- $return_data['errmsg']= '线路信息不存在';
- $return_data['errcode']='103';
- $return_data['time']=$current_time;
- $return_data['auth']=get_qunar_auth($return_data);
- echo json_encode($return_data);
- exit();
- }
-
-
- if( count($run_code_array) > 2 ) {
- $back_run_code = $run_code_array[2];
- } else {
- $back_run_code = false;
- }
-
- if( $back_run_code == false ) {
- $sql2 = " SELECT * FROM run_main WHERE RUN_ID = {$run_code} ";
- } else {
- $sql2 = " SELECT * FROM run_main WHERE RUN_ID IN ({$run_code},{$back_run_code}) ";
- }
-
- $result=$pdo->query($sql2);
- $rowset=$result->fetchAll();
- $result->closeCursor();
-
- if( $rowset == false ) {
- $return_data['ret']= false;
- $return_data['errmsg']= '线路信息不存在';
- $return_data['errcode']='103';
- $return_data['time']=$current_time;
- $return_data['auth']=get_qunar_auth($return_data);
- echo json_encode($return_data);
- exit();
- }
-
- foreach( $rowset as $run_info_temp ) {
- if( $run_info_temp["RUN_STATUS"] != 138 ) {
- $return_data['ret']= false;
- $return_data['errmsg']= '线路信息不存在';
- $return_data['errcode']='103';
- $return_data['time']=$current_time;
- $return_data['auth']=get_qunar_auth($return_data);
- echo json_encode($return_data);
- exit();
- }
- }
-
- if( $back_run_code == false ) {
- $run_main_info = $rowset[0];
- $back_run_main_info = false;
- } else {
- $run_main_info = $rowset[0]["RUN_ID"] == $run_code ? $rowset[0] : $rowset[1];
- $back_run_main_info = $rowset[0]["RUN_ID"] == $back_run_code ? $rowset[0] : $rowset[1];
- }
-
- if( $back_run_code == false ) {
- $sql3 = " SELECT * FROM run_bus WHERE RUN_ID = {$run_code} ";
- } else {
- $sql3 = " SELECT * FROM run_bus WHERE RUN_ID IN ({$run_code},{$back_run_code}) ";
- }
-
- $result=$pdo->query($sql3);
- $result_array=$result->fetchAll();
- $result->closeCursor();
- $run_bus_array = array();
- foreach( $result_array as $run_bus_info ) {
- if( !isset($run_bus_array[$run_bus_info["RUN_ID"]]) ) {
- $run_bus_array[$run_bus_info["RUN_ID"]] = array();
- }
- $run_bus_array[$run_bus_info["RUN_ID"]][] = $run_bus_info;
- }
- //取得所有的站点信息
- $sql4 = " SELECT * FROM base_resource WHERE RES_TYPE_ID=24 ";
- $result=$pdo->query($sql4);
- $result_array=$result->fetchAll();
- $result->closeCursor();
- $res_array = array();
- foreach( $result_array as $res_info ) {
- $res_array[$res_info["RES_ID"]] = $res_info;
- }
- //取得所有地区信息
- $sql5 = " SELECT * FROM base_area WHERE CANCEL_FLAG=0 ";
- $result=$pdo->query($sql5);
- $result_array=$result->fetchAll();
- $result->closeCursor();
- $city_array = array();
- foreach( $result_array as $city_info ) {
- $city_array[$city_info["ID"]] = $city_info;
- }
- //取得所有线路所对应的票种信息
- $sql6 = " SELECT * FROM opera_product_property WHERE PROD_ID = {$prod_id} ";
- $result=$pdo->query($sql6);
- $result_array=$result->fetchAll();
- $result->closeCursor();
- if( $result_array == false ) {
- $return_data['ret']= false;
- $return_data['errmsg']= '线路信息不存在';
- $return_data['errcode']='103';
- $return_data['time']=$current_time;
- $return_data['auth']=get_qunar_auth($return_data);
- echo json_encode($return_data);
- exit();
- }
- $product_start_end = array();
- foreach( $result_array as $key => $value ) {
- $product_start_end[$key] = $value;
- }
- //获取所有票种价格信息
- $sql7 = " SELECT * FROM opera_product_price WHERE PROD_ID = {$prod_id} ";
- $result=$pdo->query($sql7);
- $result_array=$result->fetchAll();
- $result->closeCursor();
- if( $result_array == false ) {
- $return_data['ret']= false;
- $return_data['errmsg']= '线路信息不存在';
- $return_data['errcode']='103';
- $return_data['time']=$current_time;
- $return_data['auth']=get_qunar_auth($return_data);
- echo json_encode($return_data);
- exit();
- }
- $opera_price_info = $result_array[0];
- //获取所有站点出发信息
- $sql8 = " SELECT * FROM run_station WHERE RUN_ID = {$run_code} ";
- $result=$pdo->query($sql8);
- $result_array=$result->fetchAll();
- $result->closeCursor();
- if( $result_array == false ) {
- $return_data['ret']= false;
- $return_data['errmsg']= '线路信息不存在';
- $return_data['errcode']='103';
- $return_data['time']=$current_time;
- $return_data['auth']=get_qunar_auth($return_data);
- echo json_encode($return_data);
- exit();
- }
- $station_start_array = array();
- foreach( $result_array as $start_station_info ) {
- $station_start_array[$start_station_info["STATION_RES_ID"]] = $start_station_info["START_TIME"];
- }
-
- $data_array = array();
- $data_array["coachNo"] = $param_run_code;
- $data_array["date"] = $run_main_info["RUN_DATE"];
- $data_array["startTime"] = $station_start_array[$product_start_end["112"]];
- $data_array["price"] = $opera_price_info["CUS_PRICE"];
- $data_array["from"] = getDispAreaNameForCtrip($city_array[$product_start_end["125"]]["AREA_NAME"]);
- $data_array["to"] = getDispAreaNameForCtrip($city_array[$product_start_end["126"]]["AREA_NAME"]);
- $data_array["fromStation"] = $res_array[$product_start_end["112"]]["RES_NAME"];
- $data_array["toStation"] = $res_array[$product_start_end["113"]]["RES_NAME"];
-
- if( !$run_bus_array[$run_main_info["RUN_ID"]] || ( in_array($run_main_info["PROD_ID"], $limit_sell_prod) && (($current_hour >= "10:00" && $data_array["date"] <= $tomorrow_day ) || $data_array["date"] < $tomorrow_day )) ) {
- $data_array["ticketNum"] = 0;
- } else if( $data_array["date"] == $today && $limit_time >= $run_main_info["RUN_TIME"] ) {
- $data_array["ticketNum"] = 0;
- } else {
- $return_data["bus_no"] = mb_strlen($run_bus_array[$run_main_info["RUN_ID"]][0]["SEND_BUS_NO"]) > 0 ? $run_bus_array[$run_main_info["RUN_ID"]][0]["SEND_BUS_NO"] : "以实际情况为准";
- $total_count = 0;
- $saled_count = 0;
- $remain_count = 0;
- foreach( $run_bus_array[$run_main_info["RUN_ID"]] as $run_bus_info ) {
- $total_count += $run_bus_info["SEAT_COUNT"];
- $saled_count += $run_bus_info["SALED_COUNT"];
- }
- $remain_count = $total_count - $saled_count;
- $data_array["ticketNum"] = $remain_count > 3 ? ($remain_count-3) : 0;
- }
-
- $return_data = array();
- $return_data["ret"] = true;
- $return_data["agentId"] = QUNAR_AGENT_ID;
- $return_data["time"] = $current_time;
- $return_data["auth"] = get_qunar_auth($return_data);
- $return_data["data"] = $data_array;
-
- echo json_encode($return_data);
- exit();
|