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.
 
 
 
 

272 lines
9.9 KiB

  1. <?php
  2. require_once '../st-xm/Common/Mysql.php';
  3. require_once '../st-xm/Common/config_api.inc';
  4. header("Access-Control-Allow-Origin:*");
  5. $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);
  6. $limit_sell_prod = array( 152248, 152251);
  7. $auth_code=isset($_POST['auth'])? $_POST['auth']:false;
  8. $run_code=isset($_POST['coachNo'])? $_POST['coachNo']:false;
  9. $return_data = array();
  10. $return_data['code']='201';
  11. $current_time = time();
  12. $current_hour = date("H:i:s",$current_time);
  13. $today = date("Y-m-d");
  14. $limit_time = date("H:i", strtotime("+30 minutes"));
  15. $tomorrow_day = date("Y-m-d",strtotime("+1 days"));
  16. if( $auth_code == false || $run_code == false ) {
  17. $return_data['ret']= false;
  18. $return_data['errmsg']= '请求信息有误';
  19. $return_data['errcode']='102';
  20. $return_data['time']=$current_time;
  21. $return_data['auth']=get_qunar_auth($return_data);
  22. echo json_encode($return_data);
  23. exit();
  24. }
  25. $pdo=conn1();
  26. $param_run_code = $run_code;
  27. $run_code_array = explode("_",$run_code);
  28. if( !isset($run_code_array[1]) ) {
  29. require_once '../st-xm/Common/zizai_orderAPI.php';
  30. $prod_id = $run_code_array[0];
  31. $sql = " SELECT * FROM outside_run WHERE prod_code='".$prod_id."' AND cancel_flag = 0 ";
  32. $result=$pdo->query($sql);
  33. $rowset=$result->fetchAll();
  34. $result->closeCursor();
  35. if( $rowset == false ) {
  36. $return_data['ret']= false;
  37. $return_data['errmsg']= '线路信息不存在';
  38. $return_data['errcode']='103';
  39. $return_data['time']=$current_time;
  40. $return_data['auth']=get_qunar_auth($return_data);
  41. echo json_encode($return_data);
  42. exit();
  43. }
  44. $ourside_run_info = $rowset[0];
  45. $ccode = $ourside_run_info["line_code"];
  46. $runid = $ourside_run_info["run_code"];
  47. $ticketId = $prod_id;
  48. $ticketInfo = new orderService();
  49. $ticklist = $ticketInfo->ticket(zizaiArgs::$USER, $ccode, $runid);
  50. $ticket = $ticklist['ticket_list']['ticket'];
  51. $remain_count =0;
  52. if ($ticklist['code'] == 0) {
  53. if (isset($ticket['ticketid']) && $ticketId == $ticket['ticketid']) {
  54. $remain_count = $ticket['ticketcount'];
  55. } else {
  56. foreach ($ticket as $ticketInfo) {
  57. if (isset($ticketInfo['ticketid']) && strcmp($ticketId, $ticketInfo['ticketid'])) {
  58. $remain_count = $ticketInfo['ticketcount'];
  59. break;
  60. }
  61. }
  62. }
  63. }
  64. $sql_update = " UPDATE outside_run SET remain_count={$remain_count} WHERE prod_code='".$prod_id."' ";
  65. $pdo=conn1();
  66. $pdo->exec($sql_update);
  67. $data_array = array();
  68. $data_array["coachNo"] = $param_run_code;
  69. $data_array["date"] = $ourside_run_info["start_date"];
  70. $data_array["startTime"] = $ourside_run_info["start_time"];
  71. $data_array["price"] = $ourside_run_info["cus_price"];
  72. $data_array["from"] = $ourside_run_info["start_area"];
  73. $data_array["to"] = $ourside_run_info["end_area"];
  74. $data_array["fromStation"] = $ourside_run_info["start_res"];
  75. $data_array["toStation"] = $ourside_run_info["end_res"];
  76. $data_array["ticketNum"] = $remain_count > 3 ? ($remain_count - 3) : 0;
  77. $return_data = array();
  78. $return_data["ret"] = true;
  79. $return_data["agentId"] = QUNAR_AGENT_ID;
  80. $return_data["time"] = $current_time;
  81. $return_data["auth"] = get_qunar_auth($return_data);
  82. $return_data["data"] = $data_array;
  83. echo json_encode($return_data);
  84. exit();
  85. }
  86. $run_code = $run_code_array[0];
  87. $prod_id = $run_code_array[1];
  88. if( in_array($prod_id, $no_sell_array) ) {
  89. $return_data['ret']= false;
  90. $return_data['errmsg']= '线路信息不存在';
  91. $return_data['errcode']='103';
  92. $return_data['time']=$current_time;
  93. $return_data['auth']=get_qunar_auth($return_data);
  94. echo json_encode($return_data);
  95. exit();
  96. }
  97. if( count($run_code_array) > 2 ) {
  98. $back_run_code = $run_code_array[2];
  99. } else {
  100. $back_run_code = false;
  101. }
  102. if( $back_run_code == false ) {
  103. $sql2 = " SELECT * FROM run_main WHERE RUN_ID = {$run_code} ";
  104. } else {
  105. $sql2 = " SELECT * FROM run_main WHERE RUN_ID IN ({$run_code},{$back_run_code}) ";
  106. }
  107. $result=$pdo->query($sql2);
  108. $rowset=$result->fetchAll();
  109. $result->closeCursor();
  110. if( $rowset == false ) {
  111. $return_data['ret']= false;
  112. $return_data['errmsg']= '线路信息不存在';
  113. $return_data['errcode']='103';
  114. $return_data['time']=$current_time;
  115. $return_data['auth']=get_qunar_auth($return_data);
  116. echo json_encode($return_data);
  117. exit();
  118. }
  119. foreach( $rowset as $run_info_temp ) {
  120. if( $run_info_temp["RUN_STATUS"] != 138 ) {
  121. $return_data['ret']= false;
  122. $return_data['errmsg']= '线路信息不存在';
  123. $return_data['errcode']='103';
  124. $return_data['time']=$current_time;
  125. $return_data['auth']=get_qunar_auth($return_data);
  126. echo json_encode($return_data);
  127. exit();
  128. }
  129. }
  130. if( $back_run_code == false ) {
  131. $run_main_info = $rowset[0];
  132. $back_run_main_info = false;
  133. } else {
  134. $run_main_info = $rowset[0]["RUN_ID"] == $run_code ? $rowset[0] : $rowset[1];
  135. $back_run_main_info = $rowset[0]["RUN_ID"] == $back_run_code ? $rowset[0] : $rowset[1];
  136. }
  137. if( $back_run_code == false ) {
  138. $sql3 = " SELECT * FROM run_bus WHERE RUN_ID = {$run_code} ";
  139. } else {
  140. $sql3 = " SELECT * FROM run_bus WHERE RUN_ID IN ({$run_code},{$back_run_code}) ";
  141. }
  142. $result=$pdo->query($sql3);
  143. $result_array=$result->fetchAll();
  144. $result->closeCursor();
  145. $run_bus_array = array();
  146. foreach( $result_array as $run_bus_info ) {
  147. if( !isset($run_bus_array[$run_bus_info["RUN_ID"]]) ) {
  148. $run_bus_array[$run_bus_info["RUN_ID"]] = array();
  149. }
  150. $run_bus_array[$run_bus_info["RUN_ID"]][] = $run_bus_info;
  151. }
  152. //取得所有的站点信息
  153. $sql4 = " SELECT * FROM base_resource WHERE RES_TYPE_ID=24 ";
  154. $result=$pdo->query($sql4);
  155. $result_array=$result->fetchAll();
  156. $result->closeCursor();
  157. $res_array = array();
  158. foreach( $result_array as $res_info ) {
  159. $res_array[$res_info["RES_ID"]] = $res_info;
  160. }
  161. //取得所有地区信息
  162. $sql5 = " SELECT * FROM base_area WHERE CANCEL_FLAG=0 ";
  163. $result=$pdo->query($sql5);
  164. $result_array=$result->fetchAll();
  165. $result->closeCursor();
  166. $city_array = array();
  167. foreach( $result_array as $city_info ) {
  168. $city_array[$city_info["ID"]] = $city_info;
  169. }
  170. //取得所有线路所对应的票种信息
  171. $sql6 = " SELECT * FROM opera_product_property WHERE PROD_ID = {$prod_id} ";
  172. $result=$pdo->query($sql6);
  173. $result_array=$result->fetchAll();
  174. $result->closeCursor();
  175. if( $result_array == false ) {
  176. $return_data['ret']= false;
  177. $return_data['errmsg']= '线路信息不存在';
  178. $return_data['errcode']='103';
  179. $return_data['time']=$current_time;
  180. $return_data['auth']=get_qunar_auth($return_data);
  181. echo json_encode($return_data);
  182. exit();
  183. }
  184. $product_start_end = array();
  185. foreach( $result_array as $key => $value ) {
  186. $product_start_end[$key] = $value;
  187. }
  188. //获取所有票种价格信息
  189. $sql7 = " SELECT * FROM opera_product_price WHERE PROD_ID = {$prod_id} ";
  190. $result=$pdo->query($sql7);
  191. $result_array=$result->fetchAll();
  192. $result->closeCursor();
  193. if( $result_array == false ) {
  194. $return_data['ret']= false;
  195. $return_data['errmsg']= '线路信息不存在';
  196. $return_data['errcode']='103';
  197. $return_data['time']=$current_time;
  198. $return_data['auth']=get_qunar_auth($return_data);
  199. echo json_encode($return_data);
  200. exit();
  201. }
  202. $opera_price_info = $result_array[0];
  203. //获取所有站点出发信息
  204. $sql8 = " SELECT * FROM run_station WHERE RUN_ID = {$run_code} ";
  205. $result=$pdo->query($sql8);
  206. $result_array=$result->fetchAll();
  207. $result->closeCursor();
  208. if( $result_array == false ) {
  209. $return_data['ret']= false;
  210. $return_data['errmsg']= '线路信息不存在';
  211. $return_data['errcode']='103';
  212. $return_data['time']=$current_time;
  213. $return_data['auth']=get_qunar_auth($return_data);
  214. echo json_encode($return_data);
  215. exit();
  216. }
  217. $station_start_array = array();
  218. foreach( $result_array as $start_station_info ) {
  219. $station_start_array[$start_station_info["STATION_RES_ID"]] = $start_station_info["START_TIME"];
  220. }
  221. $data_array = array();
  222. $data_array["coachNo"] = $param_run_code;
  223. $data_array["date"] = $run_main_info["RUN_DATE"];
  224. $data_array["startTime"] = $station_start_array[$product_start_end["112"]];
  225. $data_array["price"] = $opera_price_info["CUS_PRICE"];
  226. $data_array["from"] = getDispAreaNameForCtrip($city_array[$product_start_end["125"]]["AREA_NAME"]);
  227. $data_array["to"] = getDispAreaNameForCtrip($city_array[$product_start_end["126"]]["AREA_NAME"]);
  228. $data_array["fromStation"] = $res_array[$product_start_end["112"]]["RES_NAME"];
  229. $data_array["toStation"] = $res_array[$product_start_end["113"]]["RES_NAME"];
  230. if( !$run_bus_array[$run_main_info["RUN_ID"]] || ( in_array($run_main_info["PROD_ID"], $limit_sell_prod) && (($current_hour >= "10:00" && $data_array["date"] <= $tomorrow_day ) || $data_array["date"] < $tomorrow_day )) ) {
  231. $data_array["ticketNum"] = 0;
  232. } else if( $data_array["date"] == $today && $limit_time >= $run_main_info["RUN_TIME"] ) {
  233. $data_array["ticketNum"] = 0;
  234. } else {
  235. $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"] : "以实际情况为准";
  236. $total_count = 0;
  237. $saled_count = 0;
  238. $remain_count = 0;
  239. foreach( $run_bus_array[$run_main_info["RUN_ID"]] as $run_bus_info ) {
  240. $total_count += $run_bus_info["SEAT_COUNT"];
  241. $saled_count += $run_bus_info["SALED_COUNT"];
  242. }
  243. $remain_count = $total_count - $saled_count;
  244. $data_array["ticketNum"] = $remain_count > 3 ? ($remain_count-3) : 0;
  245. }
  246. $return_data = array();
  247. $return_data["ret"] = true;
  248. $return_data["agentId"] = QUNAR_AGENT_ID;
  249. $return_data["time"] = $current_time;
  250. $return_data["auth"] = get_qunar_auth($return_data);
  251. $return_data["data"] = $data_array;
  252. echo json_encode($return_data);
  253. exit();