d_air.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. const field = require('../maps/field');
  2. const mysql = require('./mysql');
  3. const until_time = require('../until/time');
  4. const {getUnixTimeStamp} = require("../until/time");
  5. // 查询指定城市航班
  6. /**
  7. * 查询相关航班信息
  8. * @param departureCity 除非城市id
  9. * @param targetCity 目标城市id
  10. * @param [routeType] 航班类型,国内或者国际
  11. * @param [startUnixTime] 出发时间开始,某个时间点之前
  12. * @param [endUnixTime] 出发时间截止,某个时间段内的
  13. * @returns {Promise | Promise<unknown>}
  14. */
  15. function fightSearch(departureCity,targetCity,routeType,startUnixTime,endUnixTime){
  16. let sql=``,values=[];
  17. sql = `select f.* ,dep.cityname as departureCityName,tar.cityname as targetCityName from
  18. flight as f
  19. LEFT JOIN (select id,cityname from area ) as dep on dep.id = f.departureCity
  20. LEFT JOIN (select id,cityname from area ) as tar on tar.id = f.targetCity
  21. where f.departureCity = ? and f.targetCity = ?`;
  22. values.push(departureCity,targetCity);
  23. if(routeType){
  24. sql += ` and f.routerType = ?`;
  25. values.push(routeType);
  26. }
  27. if(endUnixTime){
  28. // 如果有结束时间,没有开始时间则默认添加
  29. if (!startUnixTime) startUnixTime=getUnixTimeStamp();
  30. sql += ` and f.sailingTime <= ?`;
  31. values.push(endUnixTime);
  32. }
  33. if(startUnixTime){
  34. sql += ` and f.sailingTime >= ?`;
  35. values.push(startUnixTime);
  36. }
  37. sql+=`;`
  38. return mysql.pq(sql,values);
  39. }
  40. /**
  41. * 获取航班票数
  42. * @param fightId
  43. * @returns {Promise<unknown>}
  44. */
  45. function fightTicks(fightId){
  46. let sql=``,values=[];
  47. sql=`select ff.*,count(t.flightId = 1 or null) as pay
  48. from
  49. (select totalVotes from flight where id = 1) as ff,
  50. airTickets as t`
  51. return mysql.pq(sql,values);
  52. }