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.
 
 
 
 

260 lines
9.3 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,152709,152715,153133,153135,153137,152569,152570,152571,152572,152573,152575,152577,152579,152581,152582,152695,152696,152706,152707);
  5. $limit_sell_prod = array( 152248, 152251, 448568, 448569);
  6. //test
  7. //$_POST['auth_code'] = "abcdefg";
  8. //$_POST['run_code'] = "202649_152735";
  9. //end of test
  10. $current_time = time();
  11. $current_time = date("H:i:s",$current_time);
  12. $tomorrow_day = date("Y-m-d",strtotime("+1 days"));
  13. $today = date("Y-m-d");
  14. $limit_time = date("H:i", strtotime("+30 minutes"));
  15. $auth_code=isset($_POST['auth_code'])? $_POST['auth_code']:false;
  16. $run_code=isset($_POST['run_code'])? $_POST['run_code']:false;
  17. $return_data = array();
  18. $return_data['code']='201';
  19. if( $auth_code == false || $run_code == false ) {
  20. $return_data['code']='401';
  21. echo json_encode($return_data);
  22. exit();
  23. }
  24. $pdo=conn1();
  25. $sql=" SELECT user_name,user_psd,user_auth_code FROM api_auth_code WHERE user_auth_code='".$auth_code."' ";
  26. $result=$pdo->query($sql);
  27. $rowset=$result->fetchAll();
  28. $result->closeCursor();
  29. if( false == $rowset ) {
  30. $return_data['code']='400';
  31. echo json_encode($return_data);
  32. exit();
  33. }
  34. $param_run_code = $run_code;
  35. $run_code_array = explode("_",$run_code);
  36. if( !isset($run_code_array[1]) ) {
  37. $return_data['code']='201';
  38. $return_data["run_code"] = $prod_id;
  39. $return_data["can_book"] = 1;
  40. $return_data["is_active"] = 1;
  41. $return_data["bus_no"] = "以实际情况为准";
  42. $return_data["total_count"] = 0;
  43. $return_data["saled_count"] = 0;
  44. $return_data["remain_count"] = 0;
  45. echo json_encode($return_data);
  46. exit();
  47. require_once '../st-xm/Common/zizai_orderAPI.php';
  48. $prod_id = $run_code_array[0];
  49. $sql = " SELECT * FROM outside_run WHERE prod_code='".$prod_id."' AND cancel_flag = 0 ";
  50. $result=$pdo->query($sql);
  51. $rowset=$result->fetchAll();
  52. $result->closeCursor();
  53. if( $rowset == false ) {
  54. $return_data['code']='201';
  55. $return_data["run_code"] = $prod_id;
  56. $return_data["can_book"] = 1;
  57. $return_data["is_active"] = 1;
  58. $return_data["bus_no"] = "以实际情况为准";
  59. $return_data["total_count"] = 0;
  60. $return_data["saled_count"] = 0;
  61. $return_data["remain_count"] = 0;
  62. echo json_encode($return_data);
  63. exit();
  64. }
  65. $ourside_run_info = $rowset[0];
  66. if( $ourside_run_info["prod_name"] == "儿童票" ) {
  67. $return_data['code']='201';
  68. $return_data["run_code"] = $prod_id;
  69. $return_data["can_book"] = 1;
  70. $return_data["is_active"] = 1;
  71. $return_data["bus_no"] = "以实际情况为准";
  72. $return_data["total_count"] = 0;
  73. $return_data["saled_count"] = 0;
  74. $return_data["remain_count"] = 0;
  75. echo json_encode($return_data);
  76. exit();
  77. }
  78. $ccode = $ourside_run_info["line_code"];
  79. $runid = $ourside_run_info["run_code"];
  80. $ticketId = $prod_id;
  81. $ticketInfo = new orderService();
  82. $ticklist = $ticketInfo->ticket(zizaiArgs::$USER, $ccode, $runid);
  83. $ticket = $ticklist['ticket_list']['ticket'];
  84. $remain_count =0;
  85. if ($ticklist['code'] == 0) {
  86. if (isset($ticket['ticketid']) && $ticketId == $ticket['ticketid']) {
  87. $remain_count = $ticket['ticketcount'];
  88. } else {
  89. foreach ($ticket as $ticketInfo) {
  90. if (isset($ticketInfo['ticketid']) && strcmp($ticketId, $ticketInfo['ticketid'])) {
  91. $remain_count = $ticketInfo['ticketcount'];
  92. break;
  93. }
  94. }
  95. }
  96. }
  97. $sql_update = " UPDATE outside_run SET remain_count={$remain_count} WHERE prod_code='".$prod_id."' ";
  98. $pdo=conn1();
  99. $pdo->exec($sql_update);
  100. $return_data['code']='201';
  101. $return_data["run_code"] = $prod_id;
  102. $return_data["can_book"] = 1;
  103. $return_data["is_active"] = 1;
  104. $return_data["bus_no"] = "以实际情况为准";
  105. $return_data["total_count"] = $remain_count;
  106. $return_data["saled_count"] = 3;
  107. $return_data["remain_count"] = $remain_count > 3 ? $remain_count-3 : 0;
  108. echo json_encode($return_data);
  109. exit();
  110. }
  111. $run_code = $run_code_array[0];
  112. $prod_id = $run_code_array[1];
  113. if( in_array($prod_id, $no_sell_array) ) {
  114. $return_data['code']='201';
  115. $return_data["run_code"] = $param_run_code;
  116. $return_data["can_book"] = 1;
  117. $return_data["is_active"] = 1;
  118. $return_data["bus_no"] = "以实际情况为准";
  119. $return_data["total_count"] = 0;
  120. $return_data["saled_count"] = 0;
  121. $return_data["remain_count"] = 0;
  122. echo json_encode($return_data);
  123. exit();
  124. }
  125. if( count($run_code_array) > 2 ) {
  126. $back_run_code = $run_code_array[2];
  127. $back_prod_id = $run_code_array[3];
  128. if( in_array($back_prod_id, $no_sell_array) ) {
  129. $return_data['code']='201';
  130. $return_data["run_code"] = $param_run_code;
  131. $return_data["can_book"] = 1;
  132. $return_data["is_active"] = 1;
  133. $return_data["bus_no"] = "以实际情况为准";
  134. $return_data["total_count"] = 0;
  135. $return_data["saled_count"] = 0;
  136. $return_data["remain_count"] = 0;
  137. echo json_encode($return_data);
  138. exit();
  139. }
  140. } else {
  141. $back_run_code = false;
  142. }
  143. if( $back_run_code == false ) {
  144. $sql2 = " SELECT * FROM run_main WHERE RUN_ID = {$run_code} ";
  145. } else {
  146. $sql2 = " SELECT * FROM run_main WHERE RUN_ID IN ({$run_code},{$back_run_code}) ";
  147. }
  148. $result=$pdo->query($sql2);
  149. $rowset=$result->fetchAll();
  150. $result->closeCursor();
  151. if( $rowset == false ) {
  152. $return_data['code']='501';
  153. echo json_encode($return_data);
  154. exit();
  155. }
  156. foreach( $rowset as $run_info_temp ) {
  157. if( $run_info_temp["RUN_STATUS"] != 138 || ( $run_info_temp["RUN_DATE"] == $today && $limit_time >= $run_info_temp["RUN_TIME"] ) ||
  158. ( in_array($run_info_temp["PROD_ID"], $limit_sell_prod) && $run_info_temp["RUN_DATE"] <= $tomorrow_day && $current_time >= "10:00" ) ) {
  159. $return_data['code']='201';
  160. $return_data["run_code"] = $param_run_code;
  161. $return_data["can_book"] = 1;
  162. $return_data["is_active"] = 1;
  163. $return_data["bus_no"] = "以实际情况为准";
  164. $return_data["total_count"] = 0;
  165. $return_data["saled_count"] = 0;
  166. $return_data["remain_count"] = 0;
  167. echo json_encode($return_data);
  168. exit();
  169. }
  170. }
  171. if( $back_run_code == false ) {
  172. $run_main_info = $rowset[0];
  173. $back_run_main_info = false;
  174. } else {
  175. $run_main_info = $rowset[0]["RUN_ID"] == $run_code ? $rowset[0] : $rowset[1];
  176. $back_run_main_info = $rowset[0]["RUN_ID"] == $back_run_code ? $rowset[0] : $rowset[1];
  177. }
  178. if( $back_run_code == false ) {
  179. $sql3 = " SELECT * FROM run_bus WHERE RUN_ID = {$run_code} AND CANCEL_FLAG = 0 AND RUN_BUS_STATUS = 138 ";
  180. } else {
  181. $sql3 = " SELECT * FROM run_bus WHERE RUN_ID IN ({$run_code},{$back_run_code}) AND CANCEL_FLAG = 0 AND RUN_BUS_STATUS = 138 ";
  182. }
  183. $result=$pdo->query($sql3);
  184. $result_array=$result->fetchAll();
  185. $result->closeCursor();
  186. $run_bus_array = array();
  187. foreach( $result_array as $run_bus_info ) {
  188. if( !isset($run_bus_array[$run_bus_info["RUN_ID"]]) ) {
  189. $run_bus_array[$run_bus_info["RUN_ID"]] = array();
  190. }
  191. $run_bus_array[$run_bus_info["RUN_ID"]][] = $run_bus_info;
  192. }
  193. $data_array = array();
  194. $return_data["run_code"] = $param_run_code;
  195. $return_data["can_book"] = 1;
  196. $return_data["is_active"] = 1;
  197. $return_data["pre_days"] = $run_main_info["PRE_SALE_DAY"];
  198. if( !$run_bus_array[$run_main_info["RUN_ID"]] ) {
  199. $return_data["bus_no"] = "以实际情况为准";
  200. $return_data["total_count"] = 0;
  201. $return_data["saled_count"] = 0;
  202. $return_data["remain_count"] = 0;
  203. } else {
  204. $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"] : "以实际情况为准";
  205. $total_count = 0;
  206. $saled_count = 0;
  207. $remain_count = 0;
  208. foreach( $run_bus_array[$run_main_info["RUN_ID"]] as $run_bus_info ) {
  209. $total_count += $run_bus_info["SEAT_COUNT"];
  210. $saled_count += $run_bus_info["SALED_COUNT"];
  211. }
  212. $remain_count = $total_count - $saled_count;
  213. $return_data["total_count"] = $total_count;
  214. $return_data["saled_count"] = $saled_count;
  215. $return_data["remain_count"] = $remain_count;
  216. }
  217. if( $back_run_code != false ) {
  218. if( !$run_bus_array[$run_main_info["RUN_ID"]] ) {
  219. $return_data["bus_no"] = "以实际情况为准";
  220. $return_data["total_count"] = 0;
  221. $return_data["saled_count"] = 0;
  222. $return_data["remain_count"] = 0;
  223. } else {
  224. $total_count = 0;
  225. $saled_count = 0;
  226. $remain_count = 0;
  227. foreach( $run_bus_array[$back_run_main_info["RUN_ID"]] as $run_bus_info ) {
  228. $total_count += $run_bus_info["SEAT_COUNT"];
  229. $saled_count += $run_bus_info["SALED_COUNT"];
  230. }
  231. $return_data["total_count"] = $return_data["total_count"] > $total_count ? $total_count : $return_data["total_count"];
  232. $return_data["saled_count"] = $return_data["saled_count"] > $saled_count ? $return_data["saled_count"] : $saled_count;
  233. $return_data["saled_count"] += 3;
  234. $return_data["remain_count"] = $return_data["total_count"] - $return_data["saled_count"];
  235. $return_data["remain_count"] = $return_data["remain_count"] < 0 ? 0 : $return_data["remain_count"];
  236. }
  237. }
  238. echo json_encode($return_data);
  239. exit();