123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197 |
- const field = require('../maps/field');
- const mysql = require('./mysql');
- const until_time = require('../until/time');
- const {getUnixTimeStamp} = require("../until/time");
- const code = require("../maps/rcodeMap");
- const checkArgumentsIsEmpty = require("../until/checkArgumentsIsEmpty");
- function flightSearch(departureCity,targetCity,routeType,startUnixTime,endUnixTime){
- let sql=``,values=[];
- sql = `select f.* ,dep.cityname as departureCityName,tar.cityname as targetCityName from
- flight as f
- LEFT JOIN (select id,cityname from area ) as dep on dep.id = f.departureCity
- LEFT JOIN (select id,cityname from area ) as tar on tar.id = f.targetCity
- where f.departureCity = ? and f.targetCity = ?`;
- values.push(departureCity,targetCity);
- if(routeType){
- sql += ` and f.routerType = ?`;
- values.push(routeType);
- }
- if(endUnixTime){
-
- if (!startUnixTime) startUnixTime=getUnixTimeStamp();
- sql += ` and f.sailingTime <= ?`;
- values.push(endUnixTime);
- }
- if(startUnixTime){
- sql += ` and f.sailingTime >= ?`;
- values.push(startUnixTime);
- }
- sql+=`;`
- return mysql.pq(sql,values);
- }
- function flightTicks(flightId){
- let sql=``,values=[];
- sql=`select ff.*,count(t.flightId = ? or null) as pay
- from
- (select totalVotes from flight where id = ?) as ff,
- airTickets as t`;
- values.push(flightId,flightId);
- return mysql.pq(sql,values);
- }
- function addFlight(flightName,
- airplaneCode,
- originalPrice,
- currentPrice,
- sailingTime,
- langdinTime,
- totalVotes,
- routeType,
- departureCity,
- targetCity){
- let sql = ``,values = [];
- sql = `insert into flight
- (
- flightName,airplaneCode,
- originalPrice,currentPrice,
- sailingTime,langdinTime,
- totalVotes,routeType,
- departureCity,targetCity
- ) values(
- ?,?,
- ?,?,
- ?,?,
- ?,?
- )`;
- values.push(...arguments);
- sql += ';'
- return mysql.pq(sql,values);
- }
- function updateFlight(
- flightId,
- flightName,
- airplaneCode,
- originalPrice,
- currentPrice,
- sailingTime,
- langdinTime,
- totalVotes,
- routeType,
- departureCity,
- targetCity){
- let sql=``,values=[];
- let _arguments = Array.from(arguments);
-
- if(checkArgumentsIsEmpty(Array.from(arguments))){
- throw {rcode:code.notParam}
- }
- sql+=`update area set`
-
- if(flightName){
- sql+=' flightName = ?'
- values.push(flightName)
- }
-
- if(airplaneCode){
- sql+=' airplaneCode = ?'
- values.push(airplaneCode)
- }
-
- if(originalPrice){
- sql+=' originalPrice = ?'
- values.push(originalPrice)
- }
-
- if(currentPrice){
- sql+=' currentPrice = ?'
- values.push(currentPrice)
- }
-
- if(sailingTime){
- sql+=' sailingTime = ?'
- values.push(sailingTime)
- }
-
- if(langdinTime){
- sql+=' langdinTime = ?'
- values.push(langdinTime)
- }
-
- if(totalVotes){
- sql+=' totalVotes = ?'
- values.push(totalVotes)
- }
-
- if(routeType){
- sql+=' routeType = ?'
- values.push(routeType)
- }
-
- if(departureCity){
- sql+=' departureCity = ?'
- values.push(departureCity)
- }
-
- if(targetCity){
- sql+=' targetCity = ?'
- values.push(targetCity)
- }
- sql += ` where id = ?;`
- values.push(flightId);
- return mysql.pq(sql,values);
- }
- function recommendFlight(){
- }
|