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.
 
 
 
 

319 lines
15 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. date_default_timezone_set('PRC');
  6. $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);
  7. $limit_sell_prod = array( 152248, 152251, 448568, 448569);
  8. //$start_date=isset($_POST['start_date'])? $_POST['start_date']:date("Y-m-d");
  9. $start_date=isset($_POST['start_date'])? $_POST['start_date']:date("Y-m-d", strtotime("+1 days"));
  10. $end_date=isset($_POST['end_date'])? $_POST['end_date']:date("Y-m-d", strtotime("+1 months"));
  11. $return_data = array();
  12. $return_data['code']='201';
  13. $pdo=conn1();
  14. //取得所有的线路
  15. $sql = " SELECT * FROM opera_product WHERE PROD_ID IN (152690,152703, 152716, 152727,152251,152248,152745,152738,153146,153144,153122,153123) AND PROD_TYPE=81 AND CANCEL_FLAG = 0 ";
  16. $result=$pdo->query($sql);
  17. $result_array=$result->fetchAll();
  18. $result->closeCursor();
  19. $line_array = array();
  20. $line_id_array = array();
  21. foreach( $result_array as $line_info ) {
  22. $line_id_array[] = $line_info["PROD_ID"];
  23. $line_array[$line_info["PROD_ID"]] = $line_info;
  24. }
  25. //取得所有符合检索条件的班次信息
  26. $sql2 = " SELECT * FROM run_main WHERE PROD_ID IN (".implode(",",$line_id_array).") AND RUN_STATUS=138 AND RUN_DATE >= '".$start_date."' AND RUN_DATE <= '".$end_date."' ORDER BY RUN_DATE ";
  27. $result=$pdo->query($sql2);
  28. $rowset=$result->fetchAll();
  29. $result->closeCursor();
  30. $return_data['code']='201';
  31. if( $rowset == false ) {
  32. $return_data['all_count'] = 0;
  33. $return_data['data_array'] = array();
  34. echo json_encode($return_data);
  35. }
  36. //取得所有的站点信息
  37. $sql3 = " SELECT * FROM base_resource WHERE RES_TYPE_ID=24 ";
  38. $result=$pdo->query($sql3);
  39. $result_array=$result->fetchAll();
  40. $result->closeCursor();
  41. $res_array = array();
  42. foreach( $result_array as $res_info ) {
  43. $res_array[$res_info["RES_ID"]] = $res_info;
  44. }
  45. //取得所有地区信息
  46. $sql4 = " SELECT * FROM base_area WHERE CANCEL_FLAG=0 ";
  47. $result=$pdo->query($sql4);
  48. $result_array=$result->fetchAll();
  49. $result->closeCursor();
  50. $city_array = array();
  51. foreach( $result_array as $city_info ) {
  52. $city_array[$city_info["ID"]] = $city_info;
  53. }
  54. //获取所有班次run_id和所有班次对应的产品(线路)prod_id
  55. $run_id_array = array();
  56. $prod_id_array = array();
  57. foreach( $rowset as $row_info ) {
  58. if( !in_array($row_info["RUN_ID"], $run_id_array ) ) {
  59. $run_id_array[] = $row_info["RUN_ID"];
  60. }
  61. if( !in_array($row_info["PROD_ID"], $prod_id_array ) ) {
  62. $prod_id_array[] = $row_info["PROD_ID"];
  63. }
  64. }
  65. //获取所有班次的车次信息(显示库存数用)
  66. $sql5 = " SELECT * FROM run_bus WHERE RUN_ID IN(".implode(",",$run_id_array).") AND CANCEL_FLAG = 0 AND RUN_BUS_STATUS = 138 ";
  67. $result=$pdo->query($sql5);
  68. $result_array=$result->fetchAll();
  69. $result->closeCursor();
  70. $run_bus_array = array();
  71. //将所有班次的车次信息按照班次进行归类 存入$run_bus_array
  72. foreach( $result_array as $run_bus_info ) {
  73. if( !isset($run_bus_array[$run_bus_info["RUN_ID"]]) ) {
  74. $run_bus_array[$run_bus_info["RUN_ID"]] = array();
  75. }
  76. $run_bus_array[$run_bus_info["RUN_ID"]][] = $run_bus_info;
  77. }
  78. //取得所有线路所对应的票种信息
  79. $sql6 = " SELECT * FROM opera_product WHERE PROD_TYPE=82 AND PARENT_ID IN(".implode(",",$prod_id_array).") AND PROD_ID NOT IN (".implode(",",$no_sell_array).") AND CANCEL_FLAG = 0 ";
  80. $result=$pdo->query($sql6);
  81. $result_array=$result->fetchAll();
  82. $result->closeCursor();
  83. $prod_tickets_array = array();
  84. $prod_tickets_id_array = array();
  85. //将所有票种信息按照PROD_ID来进行分类存储进$prod_tickets_array
  86. //并将所有的票种PROD_ID存储进$prod_tickets_id_array
  87. foreach( $result_array as $prod_tickets_info ) {
  88. $prod_tickets_array[$prod_tickets_info["PROD_ID"]] = $prod_tickets_info;
  89. $prod_tickets_id_array[] = $prod_tickets_info["PROD_ID"];
  90. }
  91. //获取所有票种价格信息
  92. $sql7 = " SELECT * FROM opera_product_price WHERE PROD_TYPE_ID=82 AND PROD_ID IN(".implode(",",$prod_tickets_id_array).") ";
  93. $result=$pdo->query($sql7);
  94. $result_array=$result->fetchAll();
  95. $result->closeCursor();
  96. $prod_price_array = array();
  97. //把所有票价信息按照父ID(线路)进行分类并存储进$prod_price_array
  98. foreach( $result_array as $prod_price_info ) {
  99. $prod_ticket_info = $prod_tickets_array[$prod_price_info["PROD_ID"]];
  100. $prod_ticket_info["PROD_PRICE"] = $prod_price_info["PROD_PRICE"];
  101. $prod_ticket_info["CUS_PRICE"] = $prod_price_info["CUS_PRICE"];
  102. if( !isset($prod_price_array[$prod_ticket_info["PARENT_ID"]]) ) {
  103. $prod_price_array[$prod_ticket_info["PARENT_ID"]] = array();
  104. }
  105. $prod_price_array[$prod_ticket_info["PARENT_ID"]][$prod_price_info["PROD_ID"]] = $prod_ticket_info;
  106. }
  107. //获取班次的站点信息
  108. $sql8 = " SELECT * FROM run_station WHERE RUN_ID IN (".implode( ",", $run_id_array).") ";
  109. $result=$pdo->query($sql8);
  110. $result_array=$result->fetchAll();
  111. $result->closeCursor();
  112. $run_station_array = array();
  113. $res_start_time_array = array();
  114. //把班次站点信息按照班次RUN_ID进行归类,并总结出每个班次的起始站点和终了站点
  115. //根据班次站点对于时间进行归纳,并存储至$res_start_time_array
  116. foreach( $result_array as $run_station_info ) {
  117. if( !isset($run_station_array[$run_station_info["RUN_ID"]]) ) {
  118. $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 );
  119. }
  120. if( !isset($res_start_time_array[$run_station_info["RUN_ID"]])) {
  121. $res_start_time_array[$run_station_info["RUN_ID"]] = array();
  122. }
  123. $res_start_time_array[$run_station_info["RUN_ID"]][$run_station_info["STATION_RES_ID"]] = $run_station_info["START_TIME"];
  124. if( $run_station_info["STATION_ORDER_ID"] == 1 ) {
  125. $run_station_array[$run_station_info["RUN_ID"]]["start_time"] = $run_station_info["START_TIME"];
  126. $run_station_array[$run_station_info["RUN_ID"]]["start_res_id"] = $run_station_info["STATION_RES_ID"];
  127. $run_station_array[$run_station_info["RUN_ID"]]["start_area_id"] = $run_station_info["AREA_ID"];
  128. } else {
  129. if( $run_station_array[$run_station_info["RUN_ID"]]["end_order_no"] < $run_station_info["STATION_ORDER_ID"] ) {
  130. $run_station_array[$run_station_info["RUN_ID"]]["end_order_no"] = $run_station_info["STATION_ORDER_ID"];
  131. $run_station_array[$run_station_info["RUN_ID"]]["end_res_id"] = $run_station_info["STATION_RES_ID"];
  132. $run_station_array[$run_station_info["RUN_ID"]]["end_area_id"] = $run_station_info["AREA_ID"];
  133. }
  134. }
  135. }
  136. //获取票种的所有信息
  137. $sql9 = " SELECT * FROM opera_product_property WHERE PROD_ID IN(".implode(",",$prod_tickets_id_array).") ";
  138. $result=$pdo->query($sql9);
  139. $result_array=$result->fetchAll();
  140. $result->closeCursor();
  141. $start_end_array = array();
  142. //将所有票种的额外信息按照票种PROD_ID进行归类并存储到$start_end_array 主要为了获取每个票种的起始地目的地
  143. foreach( $result_array as $start_end_info ) {
  144. if( !isset($start_end_array[$start_end_info["PROD_ID"]]) ) {
  145. $start_end_array[$start_end_info["PROD_ID"]] = array();
  146. }
  147. $start_end_array[$start_end_info["PROD_ID"]][$start_end_info["TYPE_ID"]] = $start_end_info["PROPERTY"];
  148. }
  149. $disney_disp_array = array(
  150. "上海迪士尼" => "迪士尼"
  151. );
  152. $data_array = array();
  153. foreach( $rowset as $row_info ) {
  154. $base_info = array();
  155. $base_info["run_code"] = $row_info["RUN_ID"];
  156. $base_info["supplier"] = "上海南顺";
  157. $base_info["prod_type"] = "景区直通车";
  158. $base_info["run_type"] = "普通班次";
  159. $base_info["bus_type"] = "国产旅游空调车";
  160. $base_info["can_book"] = 1;
  161. $base_info["is_active"] = 1;
  162. $base_info["start_date"] = $row_info["RUN_DATE"];
  163. $base_info["start_time"] = $row_info["RUN_TIME"];
  164. $base_info["pre_days"] = $row_info["PRE_SALE_DAY"] > 0 ? $row_info["PRE_SALE_DAY"] : 1;
  165. $base_info["on_sale"] = $row_info["RUN_STATUS"] == 138 ? 1:0;
  166. $base_info["is_limit"] = in_array($row_info["PROD_ID"], $limit_sell_prod) ? 1 : 0;
  167. if( !$run_bus_array[$row_info["RUN_ID"]] ) {
  168. $base_info["bus_no"] = "以实际情况为准";
  169. $base_info["total_count"] = 0;
  170. $base_info["saled_count"] = 0;
  171. $base_info["remain_count"] = 0;
  172. } else {
  173. $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"] : "以实际情况为准";
  174. $total_count = 0;
  175. $saled_count = 0;
  176. $remain_count = 0;
  177. foreach( $run_bus_array[$row_info["RUN_ID"]] as $run_bus_info ) {
  178. $total_count += $run_bus_info["SEAT_COUNT"];
  179. $saled_count += $run_bus_info["SALED_COUNT"];
  180. }
  181. $remain_count = $total_count - $saled_count;
  182. $base_info["total_count"] = $total_count;
  183. $base_info["saled_count"] = $saled_count;
  184. $base_info["remain_count"] = $remain_count;
  185. }
  186. //need add here
  187. $tickets_array = $prod_price_array[$row_info["PROD_ID"]];
  188. foreach( $tickets_array as $tickets_info ) {
  189. $prod_name = $prod_tickets_array[$tickets_info["PROD_ID"]]["PROD_NAME"];
  190. if( mb_strpos( $prod_name, "往返") != false ) {
  191. continue;
  192. } else {
  193. echo mb_strpos( $prod_name, "往返");
  194. }
  195. $base_info["run_code"] = $row_info["RUN_ID"]."_".$tickets_info["PROD_ID"];
  196. $start_end_info = $start_end_array[$tickets_info["PROD_ID"]];
  197. $base_info["start_time"] = $res_start_time_array[$row_info["RUN_ID"]][$start_end_info["112"]];
  198. $base_info["end_time"] = $res_start_time_array[$row_info["RUN_ID"]][$start_end_info["113"]];
  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. if( $base_info["start_city"] == "上海迪士尼" ) {
  202. $base_info["start_city"] = "迪士尼";
  203. }
  204. if( $base_info["end_city"] == "上海迪士尼" ) {
  205. $base_info["end_city"] = "迪士尼";
  206. }
  207. $base_info["start_res"] = $res_array[$start_end_info["112"]]["RES_NAME"];
  208. $base_info["end_res"] = $res_array[$start_end_info["113"]]["RES_NAME"];
  209. $start_res = $base_info["start_res"];
  210. $end_res = $base_info["end_res"];
  211. $start_city_length = mb_strlen($base_info["start_city"]);
  212. if( substr($start_res,0,$start_city_length) == $base_info["start_city"] ) {
  213. $base_info["start_res"] = substr($start_res,$start_city_length);
  214. }
  215. $end_city_length = mb_strlen($base_info["end_city"]);
  216. if( substr($end_res,0,$end_city_length) == $base_info["end_city"] ) {
  217. $base_info["end_res"] = substr($end_res,$end_city_length);
  218. }
  219. $base_info["half_price"] = $prod_price_array[$row_info["PROD_ID"]][$tickets_info["PROD_ID"]]["PROD_PRICE"];
  220. $base_info["full_price"] = $prod_price_array[$row_info["PROD_ID"]][$tickets_info["PROD_ID"]]["CUS_PRICE"];
  221. $base_info["description"] = $prod_name;
  222. $base_info["description"] = "";
  223. $data_array[] = $base_info;
  224. }
  225. }
  226. //temp array
  227. $outside_array = array(
  228. "黄浦站" => "黄浦旅游集散站"
  229. );
  230. //zizai
  231. $sql_zizai = " SELECT * FROM outside_run WHERE line_code IN ('shz101') AND cancel_flag = 0 AND prod_name <> '儿童票' AND start_date >= '{$start_date}' AND start_date <= '{$end_date}' ";
  232. $result=$pdo->query($sql_zizai);
  233. $result_array=$result->fetchAll();
  234. $result->closeCursor();
  235. foreach( $result_array as $run_info ) {
  236. $base_info = array();
  237. $base_info["supplier"] = "自在旅行";
  238. $base_info["prod_type"] = "景区直通车";
  239. $base_info["run_type"] = $run_info["prod_name"];
  240. $base_info["bus_type"] = "国产旅游空调车";
  241. $base_info["can_book"] = 1;
  242. $base_info["is_active"] = 1;
  243. $base_info["start_date"] = $run_info["start_date"];
  244. $base_info["start_time"] = $run_info["start_time"];
  245. $base_info["pre_days"] = 1;
  246. $base_info["on_sale"] = 1;
  247. $base_info["run_code"] = $run_info["prod_code"];
  248. $base_info["is_limit"] = 0;
  249. $base_info["description"] = "";
  250. $base_info["bus_no"] = "以实际情况为准";
  251. //留3张容错
  252. $base_info["total_count"] = $run_info["remain_count"];
  253. $base_info["saled_count"] = 3;
  254. $base_info["remain_count"] = $run_info["remain_count"] - 3;
  255. $base_info["remain_count"] = $base_info["remain_count"] > 0 ? $base_info["remain_count"] : 0;
  256. $base_info["start_city"] = $run_info["start_area"];
  257. $base_info["end_city"] = $run_info["end_area"];
  258. $base_info["start_res"] = isset($outside_array[$run_info["start_res"]]) ? $outside_array[$run_info["start_res"]] : $run_info["start_res"];
  259. $base_info["end_res"] = $run_info["end_res"]."站";
  260. $base_info["full_price"] = $run_info["cus_price"];
  261. $data_array[] = $base_info;
  262. }
  263. //生成一个文件
  264. //$txt_file_name = 'coach_zhizhu_data_'.date("Ymd").'_0001';
  265. $txt_file_name = 'coach_zhizhu_data_'.date("Ymd",strtotime("+1 days")).'_0001';
  266. $txt_file = fopen( $txt_file_name.".txt", "w,ccs=UTF-8") or die("Unable to open file!");
  267. foreach( $data_array as $base_info ) {
  268. $pre_minutes = 990;
  269. if( isset($base_info["end_time"]) ) {
  270. $diff_time = strtotime($base_info["end_time"]) - strtotime($base_info["start_time"]);
  271. $disp_diff_time = floor($diff_time / 60);
  272. } else {
  273. $base_info["end_time"] = "";
  274. $disp_diff_time = "";
  275. }
  276. if( $base_info["is_limit"] == 0 ) {
  277. $pre_sec = strtotime($base_info["start_time"]) - strtotime("00:00:00");
  278. } else {
  279. $pre_day = date("Y-m-d", strtotime($base_info["start_date"]." -1 days"));
  280. $pre_sec = strtotime($base_info["start_date"]." ".$base_info["start_time"]) - strtotime($pre_day." 10:00:00");
  281. }
  282. $pre_minutes = floor($pre_sec / 60);
  283. if( $base_info["is_limit"] != 0 ) {
  284. $pre_minutes = 30;
  285. }
  286. $total_count = $base_info["total_count"] > 3 ? ($base_info["total_count"]-3) : 0;
  287. $line = $base_info["start_city"].",".$base_info["end_city"].",".$base_info["start_res"].",".$base_info["end_res"].",".$base_info["run_code"].",旅游空调车,".$base_info["full_price"].",".$base_info["start_time"].",".$base_info["end_time"].",,".$disp_diff_time.",FALSE,0,".QUNAR_CHECK_STOCK_URL.",,,0,".$base_info["start_date"].",10,{$pre_minutes}";
  288. fwrite($txt_file, $line."\n");
  289. }
  290. fclose($txt_file);
  291. create_zip_file( $txt_file_name.".txt", $txt_file_name.".zip");
  292. $destination_file = "/qunar/".$txt_file_name.".zip";
  293. //$destination_file = "/".$txt_file_name.".zip";
  294. echo upload_file_to_ftp( QUNAR_FTP_SERVER, QUNAR_FTP_PORT, QUNAR_FTP_USER, QUNAR_FTP_PSD, $txt_file_name.".zip", $destination_file );
  295. //echo upload_file_to_ftp( QUNAR_UPLOAD_FTP_SERVER, QUNAR_UPLOAD_FTP_PORT, QUNAR_UPLOAD_FTP_USER, QUNAR_UPLOAD_FTP_PSD, $txt_file_name.".zip", $destination_file );
  296. unlink( $txt_file_name.".txt" );
  297. unlink( $txt_file_name.".zip" );
  298. exit();