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.
 
 
 
 

238 lines
12 KiB

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