|
- <?php
- require_once '../st-xm/Common/Mysql.php';
- 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, 448568, 448569);
- //test
- //$_POST['auth_code'] = "abcdefg";
- //$_POST['run_code'] = "202649_152735";
- //end of test
- $current_time = time();
- $current_time = date("H:i:s",$current_time);
- $tomorrow_day = date("Y-m-d",strtotime("+1 days"));
- $today = date("Y-m-d");
- $limit_time = date("H:i", strtotime("+30 minutes"));
-
- $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);
- if( !isset($run_code_array[1]) ) {
-
- $return_data['code']='201';
- $return_data["run_code"] = $prod_id;
- $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();
-
- 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['code']='201';
- $return_data["run_code"] = $prod_id;
- $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();
- }
- $ourside_run_info = $rowset[0];
- if( $ourside_run_info["prod_name"] == "儿童票" ) {
- $return_data['code']='201';
- $return_data["run_code"] = $prod_id;
- $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();
- }
-
- $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);
- $return_data['code']='201';
- $return_data["run_code"] = $prod_id;
- $return_data["can_book"] = 1;
- $return_data["is_active"] = 1;
- $return_data["bus_no"] = "以实际情况为准";
- $return_data["total_count"] = $remain_count;
- $return_data["saled_count"] = 3;
- $return_data["remain_count"] = $remain_count > 3 ? $remain_count-3 : 0;
-
- 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['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"] == $today && $limit_time >= $run_info_temp["RUN_TIME"] ) ||
- ( in_array($run_info_temp["PROD_ID"], $limit_sell_prod) && $run_info_temp["RUN_DATE"] <= $tomorrow_day && $current_time >= "10: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} AND CANCEL_FLAG = 0 AND RUN_BUS_STATUS = 138 ";
- } else {
- $sql3 = " SELECT * FROM run_bus WHERE RUN_ID IN ({$run_code},{$back_run_code}) AND CANCEL_FLAG = 0 AND RUN_BUS_STATUS = 138 ";
- }
-
- $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["saled_count"] += 3;
- $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();
|