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.
 
 
 
 

221 lines
9.9 KiB

  1. <?php
  2. require_once '../st-xm/Common/Mysql.php';
  3. header("Access-Control-Allow-Origin:*");
  4. //test
  5. //$_POST['auth_code'] = "abcdefg";
  6. //$_POST['start_date'] = "2016-07-20";
  7. //$_POST['end_date'] = "2016-07-20";
  8. //end of test
  9. $auth_code=isset($_POST['auth_code'])? $_POST['auth_code']:false;
  10. $start_date=isset($_POST['start_date'])? $_POST['start_date']:date("Y-m-d");
  11. $end_date=isset($_POST['end_date'])? $_POST['end_date']:date("Y-m-d", strtotime("+1 months"));
  12. $return_data = array();
  13. $return_data['code']='201';
  14. if( $auth_code == false ) {
  15. $return_data['code']='401';
  16. echo json_encode($return_data);
  17. exit();
  18. }
  19. $pdo=conn();
  20. //验证函数
  21. $sql=" SELECT user_name,user_psd,user_auth_code FROM api_auth_code WHERE user_auth_code='".$auth_code."' ";
  22. $result=$pdo->query($sql);
  23. $rowset=$result->fetchAll();
  24. $result->closeCursor();
  25. if( false == $rowset ) {
  26. $return_data['code']='400';
  27. echo json_encode($return_data);
  28. exit();
  29. }
  30. //取得所有符合检索条件的班次信息(仅限于上海-乌镇-萧山 和 上海-西塘-乌镇)
  31. $sql2 = " SELECT * FROM run_main WHERE PROD_ID IN (152690,152703, 152716, 152727) AND RUN_STATUS=138 AND RUN_DATE >= '".$start_date."' AND RUN_DATE <= '".$end_date."' ORDER BY RUN_DATE ";
  32. $result=$pdo->query($sql2);
  33. $rowset=$result->fetchAll();
  34. $result->closeCursor();
  35. $return_data['code']='201';
  36. if( $rowset == false ) {
  37. $return_data['all_count'] = 0;
  38. $return_data['data_array'] = array();
  39. echo json_encode($return_data);
  40. }
  41. //取得所有的站点信息
  42. $sql3 = " SELECT * FROM base_resource WHERE RES_TYPE_ID=24 ";
  43. $result=$pdo->query($sql3);
  44. $result_array=$result->fetchAll();
  45. $result->closeCursor();
  46. $res_array = array();
  47. foreach( $result_array as $res_info ) {
  48. $res_array[$res_info["RES_ID"]] = $res_info;
  49. }
  50. //取得所有地区信息
  51. $sql4 = " SELECT * FROM base_area WHERE CANCEL_FLAG=0 ";
  52. $result=$pdo->query($sql4);
  53. $result_array=$result->fetchAll();
  54. $result->closeCursor();
  55. $city_array = array();
  56. foreach( $result_array as $city_info ) {
  57. $city_array[$city_info["ID"]] = $city_info;
  58. }
  59. //获取所有班次run_id和所有班次对应的产品(线路)prod_id
  60. $run_id_array = array();
  61. $prod_id_array = array();
  62. foreach( $rowset as $row_info ) {
  63. if( !in_array($row_info["RUN_ID"], $run_id_array ) ) {
  64. $run_id_array[] = $row_info["RUN_ID"];
  65. }
  66. if( !in_array($row_info["PROD_ID"], $prod_id_array ) ) {
  67. $prod_id_array[] = $row_info["PROD_ID"];
  68. }
  69. }
  70. //获取所有班次的车次信息(显示库存数用)
  71. $sql5 = " SELECT * FROM run_bus WHERE RUN_ID IN(".implode(",",$run_id_array).")";
  72. $result=$pdo->query($sql5);
  73. $result_array=$result->fetchAll();
  74. $result->closeCursor();
  75. $run_bus_array = array();
  76. //将所有班次的车次信息按照班次进行归类 存入$run_bus_array
  77. foreach( $result_array as $run_bus_info ) {
  78. if( !isset($run_bus_array[$run_bus_info["RUN_ID"]]) ) {
  79. $run_bus_array[$run_bus_info["RUN_ID"]] = array();
  80. }
  81. $run_bus_array[$run_bus_info["RUN_ID"]][] = $run_bus_info;
  82. }
  83. //取得所有线路所对应的票种信息
  84. $sql6 = " SELECT * FROM opera_product WHERE PROD_TYPE=82 AND PARENT_ID IN(".implode(",",$prod_id_array).") ";
  85. $result=$pdo->query($sql6);
  86. $result_array=$result->fetchAll();
  87. $result->closeCursor();
  88. $prod_tickets_array = array();
  89. $prod_tickets_id_array = array();
  90. //将所有票种信息按照PROD_ID来进行分类存储进$prod_tickets_array
  91. //并将所有的票种PROD_ID存储进$prod_tickets_id_array
  92. foreach( $result_array as $prod_tickets_info ) {
  93. $prod_tickets_array[$prod_tickets_info["PROD_ID"]] = $prod_tickets_info;
  94. $prod_tickets_id_array[] = $prod_tickets_info["PROD_ID"];
  95. }
  96. //获取所有票种价格信息
  97. $sql7 = " SELECT * FROM opera_product_price WHERE PROD_TYPE_ID=82 AND PROD_ID IN(".implode(",",$prod_tickets_id_array).") ";
  98. $result=$pdo->query($sql7);
  99. $result_array=$result->fetchAll();
  100. $result->closeCursor();
  101. $prod_price_array = array();
  102. //把所有票价信息按照父ID(线路)进行分类并存储进$prod_price_array
  103. foreach( $result_array as $prod_price_info ) {
  104. $prod_ticket_info = $prod_tickets_array[$prod_price_info["PROD_ID"]];
  105. $prod_ticket_info["PROD_PRICE"] = $prod_price_info["PROD_PRICE"];
  106. $prod_ticket_info["CUS_PRICE"] = $prod_price_info["CUS_PRICE"];
  107. if( !isset($prod_price_array[$prod_ticket_info["PARENT_ID"]]) ) {
  108. $prod_price_array[$prod_ticket_info["PARENT_ID"]] = array();
  109. }
  110. $prod_price_array[$prod_ticket_info["PARENT_ID"]][$prod_price_info["PROD_ID"]] = $prod_ticket_info;
  111. }
  112. //获取班次的站点信息
  113. $sql8 = " SELECT * FROM run_station WHERE RUN_ID IN (".implode( ",", $run_id_array).") ";
  114. $result=$pdo->query($sql8);
  115. $result_array=$result->fetchAll();
  116. $result->closeCursor();
  117. $run_station_array = array();
  118. $res_start_time_array = array();
  119. //把班次站点信息按照班次RUN_ID进行归类,并总结出每个班次的起始站点和终了站点
  120. //根据班次站点对于时间进行归纳,并存储至$res_start_time_array
  121. foreach( $result_array as $run_station_info ) {
  122. if( !isset($run_station_array[$run_station_info["RUN_ID"]]) ) {
  123. $run_station_array[$run_station_info["RUN_ID"]] = array( "start_time" => "","start_res_id" => 0, "start_area_id" => 0, "end_res_id" => 0, "end_area_id" => 0, "end_order_no" => 0 );
  124. }
  125. if( !isset($res_start_time_array[$run_station_info["RUN_ID"]])) {
  126. $res_start_time_array[$run_station_info["RUN_ID"]] = array();
  127. }
  128. $res_start_time_array[$run_station_info["RUN_ID"]][$run_station_info["STATION_RES_ID"]] = $run_station_info["START_TIME"];
  129. if( $run_station_info["STATION_ORDER_ID"] == 1 ) {
  130. $run_station_array[$run_station_info["RUN_ID"]]["start_time"] = $run_station_info["START_TIME"];
  131. $run_station_array[$run_station_info["RUN_ID"]]["start_res_id"] = $run_station_info["STATION_RES_ID"];
  132. $run_station_array[$run_station_info["RUN_ID"]]["start_area_id"] = $run_station_info["AREA_ID"];
  133. } else {
  134. if( $run_station_array[$run_station_info["RUN_ID"]]["end_order_no"] < $run_station_info["STATION_ORDER_ID"] ) {
  135. $run_station_array[$run_station_info["RUN_ID"]]["end_order_no"] = $run_station_info["STATION_ORDER_ID"];
  136. $run_station_array[$run_station_info["RUN_ID"]]["end_res_id"] = $run_station_info["STATION_RES_ID"];
  137. $run_station_array[$run_station_info["RUN_ID"]]["end_area_id"] = $run_station_info["AREA_ID"];
  138. }
  139. }
  140. }
  141. //获取票种的所有信息
  142. $sql9 = " SELECT * FROM opera_product_property WHERE PROD_ID IN(".implode(",",$prod_tickets_id_array).") ";
  143. $result=$pdo->query($sql9);
  144. $result_array=$result->fetchAll();
  145. $result->closeCursor();
  146. $start_end_array = array();
  147. //将所有票种的额外信息按照票种PROD_ID进行归类并存储到$start_end_array 主要为了获取每个票种的起始地目的地
  148. foreach( $result_array as $start_end_info ) {
  149. if( !isset($start_end_array[$start_end_info["PROD_ID"]]) ) {
  150. $start_end_array[$start_end_info["PROD_ID"]] = array();
  151. }
  152. $start_end_array[$start_end_info["PROD_ID"]][$start_end_info["TYPE_ID"]] = $start_end_info["PROPERTY"];
  153. }
  154. $data_array = array();
  155. foreach( $rowset as $row_info ) {
  156. $base_info = array();
  157. $base_info["run_code"] = $row_info["RUN_ID"];
  158. $base_info["supplier"] = "上海南顺";
  159. $base_info["prod_type"] = "景区直通车";
  160. $base_info["run_type"] = "普通班次";
  161. $base_info["bus_type"] = "国产旅游空调车";
  162. $base_info["can_book"] = 1;
  163. $base_info["is_active"] = 1;
  164. $base_info["start_date"] = $row_info["RUN_DATE"];
  165. $base_info["start_time"] = $row_info["RUN_TIME"];
  166. $base_info["pre_days"] = $row_info["PRE_SALE_DAY"] > 0 ? $row_info["PRE_SALE_DAY"] : 1;
  167. $base_info["on_sale"] = $row_info["RUN_STATUS"] == 138 ? 1:0;
  168. if( !$run_bus_array[$row_info["RUN_ID"]] ) {
  169. $base_info["bus_no"] = "以实际情况为准";
  170. $base_info["total_count"] = 0;
  171. $base_info["saled_count"] = 0;
  172. $base_info["remain_count"] = 0;
  173. } else {
  174. $base_info["bus_no"] = mb_strlen($run_bus_array[$row_info["RUN_ID"]][0]["SEND_BUS_NO"]) > 0 ? $run_bus_array[$row_info["RUN_ID"]][0]["SEND_BUS_NO"] : "以实际情况为准";
  175. $total_count = 0;
  176. $saled_count = 0;
  177. $remain_count = 0;
  178. foreach( $run_bus_array[$row_info["RUN_ID"]] as $run_bus_info ) {
  179. $total_count += $run_bus_info["SEAT_COUNT"];
  180. $saled_count += $run_bus_info["SALED_COUNT"];
  181. }
  182. $remain_count = $total_count - $saled_count;
  183. $base_info["total_count"] = $total_count;
  184. $base_info["saled_count"] = $saled_count;
  185. $base_info["remain_count"] = $remain_count;
  186. }
  187. //need add here
  188. $tickets_array = $prod_price_array[$row_info["PROD_ID"]];
  189. foreach( $tickets_array as $tickets_info ) {
  190. $prod_name = $prod_tickets_array[$tickets_info["PROD_ID"]]["PROD_NAME"];
  191. if( mb_strpos( $prod_name, "往返") != false ) {
  192. continue;
  193. } else {
  194. echo mb_strpos( $prod_name, "往返");
  195. }
  196. $base_info["run_code"] = $row_info["RUN_ID"]."_".$tickets_info["PROD_ID"];
  197. $start_end_info = $start_end_array[$tickets_info["PROD_ID"]];
  198. $base_info["start_time"] = $res_start_time_array[$row_info["RUN_ID"]][$start_end_info["112"]];
  199. $base_info["start_city"] = $city_array[$start_end_info["125"]]["AREA_NAME"];
  200. $base_info["end_city"] = $city_array[$start_end_info["126"]]["AREA_NAME"];
  201. $base_info["start_res"] = $res_array[$start_end_info["112"]]["RES_NAME"];
  202. $base_info["end_res"] = $res_array[$start_end_info["113"]]["RES_NAME"];
  203. $base_info["half_price"] = $prod_price_array[$row_info["PROD_ID"]][$tickets_info["PROD_ID"]]["PROD_PRICE"];
  204. $base_info["full_price"] = $prod_price_array[$row_info["PROD_ID"]][$tickets_info["PROD_ID"]]["CUS_PRICE"];
  205. $base_info["description"] = $prod_name;
  206. $base_info["description"] = "";
  207. $data_array[] = $base_info;
  208. }
  209. }
  210. $return_data["all_count"] = count($data_array);
  211. $return_data["data_array"] = $data_array;
  212. echo json_encode($return_data);
  213. exit();