|
- <?php
- require_once '../st-xm/Common/Mysql.php';
- header("Access-Control-Allow-Origin:*");
- $no_sell_array = array(152739,152740,152741,152691,152697,152715);
- //test
- $_POST['auth_code'] = "mBFpLaTbDVHLN654";
- $_POST['run_code'] = "169141_152602_173942_152608";
- //end of test
- $current_time = time();
- $current_time = date("H:i:s",$current_time);
- $tomorrow_day = date("Y-m-d",strtotime("+1 days"));
-
- $auth_code=isset($_POST['auth_code'])? $_POST['auth_code']:false;
- $run_code=isset($_POST['run_code'])? $_POST['run_code']:false;
- $return_data = array();
- $return_data['code']='201';
-
- if( $auth_code == false || $run_code == false ) {
- $return_data['code']='401';
- echo json_encode($return_data);
- exit();
- }
-
- $pdo=conn1();
- $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();
- }
- $param_run_code = $run_code;
- $run_code_array = explode("_",$run_code);
- $run_code = $run_code_array[0];
- $prod_id = $run_code_array[1];
- if( in_array($prod_id, $no_sell_array) ) {
- $return_data['code']='201';
- $return_data["run_code"] = $param_run_code;
- $return_data["can_book"] = 1;
- $return_data["is_active"] = 1;
- $return_data["bus_no"] = "以实际情况为准";
- $return_data["total_count"] = 0;
- $return_data["saled_count"] = 0;
- $return_data["remain_count"] = 0;
- echo json_encode($return_data);
- exit();
- }
-
- if( count($run_code_array) > 2 ) {
- $back_run_code = $run_code_array[2];
- $back_prod_id = $run_code_array[3];
- if( in_array($back_prod_id, $no_sell_array) ) {
- $return_data['code']='201';
- $return_data["run_code"] = $param_run_code;
- $return_data["can_book"] = 1;
- $return_data["is_active"] = 1;
- $return_data["bus_no"] = "以实际情况为准";
- $return_data["total_count"] = 0;
- $return_data["saled_count"] = 0;
- $return_data["remain_count"] = 0;
- echo json_encode($return_data);
- exit();
- }
- } 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['code']='501';
- echo json_encode($return_data);
- exit();
- }
-
- foreach( $rowset as $run_info_temp ) {
- if( $run_info_temp["RUN_STATUS"] != 138 || ( $run_info_temp["RUN_DATE"] <= $tomorrow_day && $current_time >= "15:00" ) ) {
- $return_data['code']='201';
- $return_data["run_code"] = $param_run_code;
- $return_data["can_book"] = 1;
- $return_data["is_active"] = 1;
- $return_data["bus_no"] = "以实际情况为准";
- $return_data["total_count"] = 0;
- $return_data["saled_count"] = 0;
- $return_data["remain_count"] = 0;
- 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;
- }
-
- $data_array = array();
- $return_data["run_code"] = $param_run_code;
- $return_data["can_book"] = 1;
- $return_data["is_active"] = 1;
- $return_data["pre_days"] = $run_main_info["PRE_SALE_DAY"];
- if( !$run_bus_array[$run_main_info["RUN_ID"]] ) {
- $return_data["bus_no"] = "以实际情况为准";
- $return_data["total_count"] = 0;
- $return_data["saled_count"] = 0;
- $return_data["remain_count"] = 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;
- $return_data["total_count"] = $total_count;
- $return_data["saled_count"] = $saled_count;
- $return_data["remain_count"] = $remain_count;
- }
-
- if( $back_run_code != false ) {
- if( !$run_bus_array[$run_main_info["RUN_ID"]] ) {
- $return_data["bus_no"] = "以实际情况为准";
- $return_data["total_count"] = 0;
- $return_data["saled_count"] = 0;
- $return_data["remain_count"] = 0;
- } else {
- $total_count = 0;
- $saled_count = 0;
- $remain_count = 0;
- foreach( $run_bus_array[$back_run_main_info["RUN_ID"]] as $run_bus_info ) {
- $total_count += $run_bus_info["SEAT_COUNT"];
- $saled_count += $run_bus_info["SALED_COUNT"];
- }
- $return_data["total_count"] = $return_data["total_count"] > $total_count ? $total_count : $return_data["total_count"];
- $return_data["saled_count"] = $return_data["saled_count"] > $saled_count ? $return_data["saled_count"] : $saled_count;
- $return_data["remain_count"] = $return_data["total_count"] - $return_data["saled_count"];
- $return_data["remain_count"] = $return_data["remain_count"] < 0 ? 0 : $return_data["remain_count"];
- }
- }
-
- echo json_encode($return_data);
- exit();
|