|
- <?php
- require_once '../st-xm/Common/Mysql.php';
- header("Access-Control-Allow-Origin:*");
-
- //test
- //$_POST['auth_code'] = "abcdefg";
- //$_POST['start_date'] = "2016-07-20";
- //$_POST['end_date'] = "2016-07-20";
- //end of test
- $auth_code=isset($_POST['auth_code'])? $_POST['auth_code']:false;
- $start_date=isset($_POST['start_date'])? $_POST['start_date']:date("Y-m-d");
- $end_date=isset($_POST['end_date'])? $_POST['end_date']:date("Y-m-d", strtotime("+1 months"));
- $return_data = array();
- $return_data['code']='201';
-
- if( $auth_code == false ) {
- $return_data['code']='401';
- echo json_encode($return_data);
- exit();
- }
- $pdo=conn();
- //验证函数
- $sql=" SELECT user_name,user_psd,user_auth_code FROM api_auth_code WHERE user_auth_code='".$auth_code."' ";
-
- $result=$pdo->query($sql);
- $rowset=$result->fetchAll();
- $result->closeCursor();
- if( false == $rowset ) {
- $return_data['code']='400';
- echo json_encode($return_data);
- exit();
- }
- //取得所有符合检索条件的班次信息(仅限于上海-乌镇-萧山 和 上海-西塘-乌镇)
- $sql2 = " SELECT * FROM run_main WHERE PROD_ID IN (152690,152703, 152716, 152727) AND RUN_STATUS=138 AND RUN_DATE >= '".$start_date."' AND RUN_DATE <= '".$end_date."' ORDER BY RUN_DATE ";
- $result=$pdo->query($sql2);
- $rowset=$result->fetchAll();
- $result->closeCursor();
-
- $return_data['code']='201';
- if( $rowset == false ) {
- $return_data['all_count'] = 0;
- $return_data['data_array'] = array();
- echo json_encode($return_data);
- }
- //取得所有的站点信息
- $sql3 = " SELECT * FROM base_resource WHERE RES_TYPE_ID=24 ";
- $result=$pdo->query($sql3);
- $result_array=$result->fetchAll();
- $result->closeCursor();
- $res_array = array();
- foreach( $result_array as $res_info ) {
- $res_array[$res_info["RES_ID"]] = $res_info;
- }
- //取得所有地区信息
- $sql4 = " SELECT * FROM base_area WHERE CANCEL_FLAG=0 ";
- $result=$pdo->query($sql4);
- $result_array=$result->fetchAll();
- $result->closeCursor();
- $city_array = array();
- foreach( $result_array as $city_info ) {
- $city_array[$city_info["ID"]] = $city_info;
- }
- //获取所有班次run_id和所有班次对应的产品(线路)prod_id
- $run_id_array = array();
- $prod_id_array = array();
- foreach( $rowset as $row_info ) {
- if( !in_array($row_info["RUN_ID"], $run_id_array ) ) {
- $run_id_array[] = $row_info["RUN_ID"];
- }
- if( !in_array($row_info["PROD_ID"], $prod_id_array ) ) {
- $prod_id_array[] = $row_info["PROD_ID"];
- }
- }
- //获取所有班次的车次信息(显示库存数用)
- $sql5 = " SELECT * FROM run_bus WHERE RUN_ID IN(".implode(",",$run_id_array).")";
- $result=$pdo->query($sql5);
- $result_array=$result->fetchAll();
- $result->closeCursor();
- $run_bus_array = array();
- //将所有班次的车次信息按照班次进行归类 存入$run_bus_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;
- }
- //取得所有线路所对应的票种信息
- $sql6 = " SELECT * FROM opera_product WHERE PROD_TYPE=82 AND PARENT_ID IN(".implode(",",$prod_id_array).") ";
- $result=$pdo->query($sql6);
- $result_array=$result->fetchAll();
- $result->closeCursor();
- $prod_tickets_array = array();
- $prod_tickets_id_array = array();
- //将所有票种信息按照PROD_ID来进行分类存储进$prod_tickets_array
- //并将所有的票种PROD_ID存储进$prod_tickets_id_array
- foreach( $result_array as $prod_tickets_info ) {
- $prod_tickets_array[$prod_tickets_info["PROD_ID"]] = $prod_tickets_info;
- $prod_tickets_id_array[] = $prod_tickets_info["PROD_ID"];
- }
- //获取所有票种价格信息
- $sql7 = " SELECT * FROM opera_product_price WHERE PROD_TYPE_ID=82 AND PROD_ID IN(".implode(",",$prod_tickets_id_array).") ";
- $result=$pdo->query($sql7);
- $result_array=$result->fetchAll();
- $result->closeCursor();
- $prod_price_array = array();
- //把所有票价信息按照父ID(线路)进行分类并存储进$prod_price_array
- foreach( $result_array as $prod_price_info ) {
- $prod_ticket_info = $prod_tickets_array[$prod_price_info["PROD_ID"]];
- $prod_ticket_info["PROD_PRICE"] = $prod_price_info["PROD_PRICE"];
- $prod_ticket_info["CUS_PRICE"] = $prod_price_info["CUS_PRICE"];
- if( !isset($prod_price_array[$prod_ticket_info["PARENT_ID"]]) ) {
- $prod_price_array[$prod_ticket_info["PARENT_ID"]] = array();
- }
- $prod_price_array[$prod_ticket_info["PARENT_ID"]][$prod_price_info["PROD_ID"]] = $prod_ticket_info;
- }
-
- //获取班次的站点信息
- $sql8 = " SELECT * FROM run_station WHERE RUN_ID IN (".implode( ",", $run_id_array).") ";
- $result=$pdo->query($sql8);
- $result_array=$result->fetchAll();
- $result->closeCursor();
- $run_station_array = array();
- $res_start_time_array = array();
- //把班次站点信息按照班次RUN_ID进行归类,并总结出每个班次的起始站点和终了站点
- //根据班次站点对于时间进行归纳,并存储至$res_start_time_array
- foreach( $result_array as $run_station_info ) {
- if( !isset($run_station_array[$run_station_info["RUN_ID"]]) ) {
- $run_station_array[$run_station_info["RUN_ID"]] = array( "start_time" => "","start_res_id" => 0, "start_area_id" => 0, "end_res_id" => 0, "end_area_id" => 0, "end_order_no" => 0 );
- }
- if( !isset($res_start_time_array[$run_station_info["RUN_ID"]])) {
- $res_start_time_array[$run_station_info["RUN_ID"]] = array();
- }
- $res_start_time_array[$run_station_info["RUN_ID"]][$run_station_info["STATION_RES_ID"]] = $run_station_info["START_TIME"];
- if( $run_station_info["STATION_ORDER_ID"] == 1 ) {
- $run_station_array[$run_station_info["RUN_ID"]]["start_time"] = $run_station_info["START_TIME"];
- $run_station_array[$run_station_info["RUN_ID"]]["start_res_id"] = $run_station_info["STATION_RES_ID"];
- $run_station_array[$run_station_info["RUN_ID"]]["start_area_id"] = $run_station_info["AREA_ID"];
- } else {
- if( $run_station_array[$run_station_info["RUN_ID"]]["end_order_no"] < $run_station_info["STATION_ORDER_ID"] ) {
- $run_station_array[$run_station_info["RUN_ID"]]["end_order_no"] = $run_station_info["STATION_ORDER_ID"];
- $run_station_array[$run_station_info["RUN_ID"]]["end_res_id"] = $run_station_info["STATION_RES_ID"];
- $run_station_array[$run_station_info["RUN_ID"]]["end_area_id"] = $run_station_info["AREA_ID"];
- }
- }
- }
-
- //获取票种的所有信息
- $sql9 = " SELECT * FROM opera_product_property WHERE PROD_ID IN(".implode(",",$prod_tickets_id_array).") ";
- $result=$pdo->query($sql9);
- $result_array=$result->fetchAll();
- $result->closeCursor();
- $start_end_array = array();
- //将所有票种的额外信息按照票种PROD_ID进行归类并存储到$start_end_array 主要为了获取每个票种的起始地目的地
- foreach( $result_array as $start_end_info ) {
- if( !isset($start_end_array[$start_end_info["PROD_ID"]]) ) {
- $start_end_array[$start_end_info["PROD_ID"]] = array();
- }
- $start_end_array[$start_end_info["PROD_ID"]][$start_end_info["TYPE_ID"]] = $start_end_info["PROPERTY"];
- }
-
- $data_array = array();
- foreach( $rowset as $row_info ) {
- $base_info = array();
- $base_info["run_code"] = $row_info["RUN_ID"];
- $base_info["supplier"] = "上海南顺";
- $base_info["prod_type"] = "景区直通车";
- $base_info["run_type"] = "普通班次";
- $base_info["bus_type"] = "国产旅游空调车";
- $base_info["can_book"] = 1;
- $base_info["is_active"] = 1;
- $base_info["start_date"] = $row_info["RUN_DATE"];
- $base_info["start_time"] = $row_info["RUN_TIME"];
- $base_info["pre_days"] = $row_info["PRE_SALE_DAY"] > 0 ? $row_info["PRE_SALE_DAY"] : 1;
- $base_info["on_sale"] = $row_info["RUN_STATUS"] == 138 ? 1:0;
- if( !$run_bus_array[$row_info["RUN_ID"]] ) {
- $base_info["bus_no"] = "以实际情况为准";
- $base_info["total_count"] = 0;
- $base_info["saled_count"] = 0;
- $base_info["remain_count"] = 0;
- } else {
- $base_info["bus_no"] = mb_strlen($run_bus_array[$row_info["RUN_ID"]][0]["SEND_BUS_NO"]) > 0 ? $run_bus_array[$row_info["RUN_ID"]][0]["SEND_BUS_NO"] : "以实际情况为准";
- $total_count = 0;
- $saled_count = 0;
- $remain_count = 0;
- foreach( $run_bus_array[$row_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;
- $base_info["total_count"] = $total_count;
- $base_info["saled_count"] = $saled_count;
- $base_info["remain_count"] = $remain_count;
- }
- //need add here
- $tickets_array = $prod_price_array[$row_info["PROD_ID"]];
- foreach( $tickets_array as $tickets_info ) {
- $prod_name = $prod_tickets_array[$tickets_info["PROD_ID"]]["PROD_NAME"];
- if( mb_strpos( $prod_name, "往返") != false ) {
- continue;
- } else {
- echo mb_strpos( $prod_name, "往返");
- }
- $base_info["run_code"] = $row_info["RUN_ID"]."_".$tickets_info["PROD_ID"];
- $start_end_info = $start_end_array[$tickets_info["PROD_ID"]];
- $base_info["start_time"] = $res_start_time_array[$row_info["RUN_ID"]][$start_end_info["112"]];
- $base_info["start_city"] = $city_array[$start_end_info["125"]]["AREA_NAME"];
- $base_info["end_city"] = $city_array[$start_end_info["126"]]["AREA_NAME"];
- $base_info["start_res"] = $res_array[$start_end_info["112"]]["RES_NAME"];
- $base_info["end_res"] = $res_array[$start_end_info["113"]]["RES_NAME"];
- $base_info["half_price"] = $prod_price_array[$row_info["PROD_ID"]][$tickets_info["PROD_ID"]]["PROD_PRICE"];
- $base_info["full_price"] = $prod_price_array[$row_info["PROD_ID"]][$tickets_info["PROD_ID"]]["CUS_PRICE"];
- $base_info["description"] = $prod_name;
- $base_info["description"] = "";
- $data_array[] = $base_info;
- }
- }
- $return_data["all_count"] = count($data_array);
- $return_data["data_array"] = $data_array;
-
- echo json_encode($return_data);
- exit();
|