|
- <?php
- require_once '../st-xm/Common/Mysql.php';
- header("Access-Control-Allow-Origin:*");
-
- //test
- //$_POST['auth_code'] = "abcdefg";
- //$_POST['run_code'] = "201743_152691";
- //end of test
- $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=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();
- }
- $param_run_code = $run_code;
- $run_code_array = explode("_",$run_code);
- $run_code = $run_code_array[0];
-
- $sql2 = " SELECT * FROM run_main WHERE RUN_ID = {$run_code} AND RUN_STATUS=138 ";
- $result=$pdo->query($sql2);
- $rowset=$result->fetchAll();
- $result->closeCursor();
-
- $return_data['code']='201';
- if( $rowset == false ) {
- $return_data['code']='501';
- echo json_encode($return_data);
- exit();
- }
- $run_main_info = $rowset[0];
-
- $sql3 = " SELECT * FROM run_bus WHERE RUN_ID = {$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;
- }
-
- //print_r($return_data);exit();
-
- echo json_encode($return_data);
- exit();
|