You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

173 lines
6.0 KiB

  1. <?php
  2. require_once '../st-xm/Common/Mysql.php';
  3. header("Access-Control-Allow-Origin:*");
  4. $no_sell_array = array(152739,152740,152741,152691,152697,152715);
  5. //test
  6. $_POST['auth_code'] = "mBFpLaTbDVHLN654";
  7. $_POST['run_code'] = "169141_152602_173942_152608";
  8. //end of test
  9. $current_time = time();
  10. $current_time = date("H:i:s",$current_time);
  11. $tomorrow_day = date("Y-m-d",strtotime("+1 days"));
  12. $auth_code=isset($_POST['auth_code'])? $_POST['auth_code']:false;
  13. $run_code=isset($_POST['run_code'])? $_POST['run_code']:false;
  14. $return_data = array();
  15. $return_data['code']='201';
  16. if( $auth_code == false || $run_code == false ) {
  17. $return_data['code']='401';
  18. echo json_encode($return_data);
  19. exit();
  20. }
  21. $pdo=conn1();
  22. $sql=" SELECT user_name,user_psd,user_auth_code FROM api_auth_code WHERE user_auth_code='".$auth_code."' ";
  23. $result=$pdo->query($sql);
  24. $rowset=$result->fetchAll();
  25. $result->closeCursor();
  26. if( false == $rowset ) {
  27. $return_data['code']='400';
  28. echo json_encode($return_data);
  29. exit();
  30. }
  31. $param_run_code = $run_code;
  32. $run_code_array = explode("_",$run_code);
  33. $run_code = $run_code_array[0];
  34. $prod_id = $run_code_array[1];
  35. if( in_array($prod_id, $no_sell_array) ) {
  36. $return_data['code']='201';
  37. $return_data["run_code"] = $param_run_code;
  38. $return_data["can_book"] = 1;
  39. $return_data["is_active"] = 1;
  40. $return_data["bus_no"] = "以实际情况为准";
  41. $return_data["total_count"] = 0;
  42. $return_data["saled_count"] = 0;
  43. $return_data["remain_count"] = 0;
  44. echo json_encode($return_data);
  45. exit();
  46. }
  47. if( count($run_code_array) > 2 ) {
  48. $back_run_code = $run_code_array[2];
  49. $back_prod_id = $run_code_array[3];
  50. if( in_array($back_prod_id, $no_sell_array) ) {
  51. $return_data['code']='201';
  52. $return_data["run_code"] = $param_run_code;
  53. $return_data["can_book"] = 1;
  54. $return_data["is_active"] = 1;
  55. $return_data["bus_no"] = "以实际情况为准";
  56. $return_data["total_count"] = 0;
  57. $return_data["saled_count"] = 0;
  58. $return_data["remain_count"] = 0;
  59. echo json_encode($return_data);
  60. exit();
  61. }
  62. } else {
  63. $back_run_code = false;
  64. }
  65. if( $back_run_code == false ) {
  66. $sql2 = " SELECT * FROM run_main WHERE RUN_ID = {$run_code} ";
  67. } else {
  68. $sql2 = " SELECT * FROM run_main WHERE RUN_ID IN ({$run_code},{$back_run_code}) ";
  69. }
  70. $result=$pdo->query($sql2);
  71. $rowset=$result->fetchAll();
  72. $result->closeCursor();
  73. if( $rowset == false ) {
  74. $return_data['code']='501';
  75. echo json_encode($return_data);
  76. exit();
  77. }
  78. foreach( $rowset as $run_info_temp ) {
  79. if( $run_info_temp["RUN_STATUS"] != 138 || ( $run_info_temp["RUN_DATE"] <= $tomorrow_day && $current_time >= "15:00" ) ) {
  80. $return_data['code']='201';
  81. $return_data["run_code"] = $param_run_code;
  82. $return_data["can_book"] = 1;
  83. $return_data["is_active"] = 1;
  84. $return_data["bus_no"] = "以实际情况为准";
  85. $return_data["total_count"] = 0;
  86. $return_data["saled_count"] = 0;
  87. $return_data["remain_count"] = 0;
  88. echo json_encode($return_data);
  89. exit();
  90. }
  91. }
  92. if( $back_run_code == false ) {
  93. $run_main_info = $rowset[0];
  94. $back_run_main_info = false;
  95. } else {
  96. $run_main_info = $rowset[0]["RUN_ID"] == $run_code ? $rowset[0] : $rowset[1];
  97. $back_run_main_info = $rowset[0]["RUN_ID"] == $back_run_code ? $rowset[0] : $rowset[1];
  98. }
  99. if( $back_run_code == false ) {
  100. $sql3 = " SELECT * FROM run_bus WHERE RUN_ID = {$run_code} ";
  101. } else {
  102. $sql3 = " SELECT * FROM run_bus WHERE RUN_ID IN ({$run_code},{$back_run_code}) ";
  103. }
  104. $result=$pdo->query($sql3);
  105. $result_array=$result->fetchAll();
  106. $result->closeCursor();
  107. $run_bus_array = array();
  108. foreach( $result_array as $run_bus_info ) {
  109. if( !isset($run_bus_array[$run_bus_info["RUN_ID"]]) ) {
  110. $run_bus_array[$run_bus_info["RUN_ID"]] = array();
  111. }
  112. $run_bus_array[$run_bus_info["RUN_ID"]][] = $run_bus_info;
  113. }
  114. $data_array = array();
  115. $return_data["run_code"] = $param_run_code;
  116. $return_data["can_book"] = 1;
  117. $return_data["is_active"] = 1;
  118. $return_data["pre_days"] = $run_main_info["PRE_SALE_DAY"];
  119. if( !$run_bus_array[$run_main_info["RUN_ID"]] ) {
  120. $return_data["bus_no"] = "以实际情况为准";
  121. $return_data["total_count"] = 0;
  122. $return_data["saled_count"] = 0;
  123. $return_data["remain_count"] = 0;
  124. } else {
  125. $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"] : "以实际情况为准";
  126. $total_count = 0;
  127. $saled_count = 0;
  128. $remain_count = 0;
  129. foreach( $run_bus_array[$run_main_info["RUN_ID"]] as $run_bus_info ) {
  130. $total_count += $run_bus_info["SEAT_COUNT"];
  131. $saled_count += $run_bus_info["SALED_COUNT"];
  132. }
  133. $remain_count = $total_count - $saled_count;
  134. $return_data["total_count"] = $total_count;
  135. $return_data["saled_count"] = $saled_count;
  136. $return_data["remain_count"] = $remain_count;
  137. }
  138. if( $back_run_code != false ) {
  139. if( !$run_bus_array[$run_main_info["RUN_ID"]] ) {
  140. $return_data["bus_no"] = "以实际情况为准";
  141. $return_data["total_count"] = 0;
  142. $return_data["saled_count"] = 0;
  143. $return_data["remain_count"] = 0;
  144. } else {
  145. $total_count = 0;
  146. $saled_count = 0;
  147. $remain_count = 0;
  148. foreach( $run_bus_array[$back_run_main_info["RUN_ID"]] as $run_bus_info ) {
  149. $total_count += $run_bus_info["SEAT_COUNT"];
  150. $saled_count += $run_bus_info["SALED_COUNT"];
  151. }
  152. $return_data["total_count"] = $return_data["total_count"] > $total_count ? $total_count : $return_data["total_count"];
  153. $return_data["saled_count"] = $return_data["saled_count"] > $saled_count ? $return_data["saled_count"] : $saled_count;
  154. $return_data["remain_count"] = $return_data["total_count"] - $return_data["saled_count"];
  155. $return_data["remain_count"] = $return_data["remain_count"] < 0 ? 0 : $return_data["remain_count"];
  156. }
  157. }
  158. echo json_encode($return_data);
  159. exit();