Ver Fonte

航班查询相关

kindring há 3 anos atrás
pai
commit
9d2e727764
4 ficheiros alterados com 76 adições e 13 exclusões
  1. 56 0
      database/d_air.js
  2. 8 10
      db.md
  3. 5 1
      maps/field.js
  4. 7 2
      until/time.js

+ 56 - 0
database/d_air.js

@@ -0,0 +1,56 @@
+const field = require('../maps/field');
+const mysql = require('./mysql');
+const until_time = require('../until/time');
+const {getUnixTimeStamp} = require("../until/time");
+// 查询指定城市航班
+
+
+/**
+ * 查询相关航班信息
+ * @param departureCity 除非城市id
+ * @param targetCity 目标城市id
+ * @param [routeType] 航班类型,国内或者国际
+ * @param [startUnixTime] 出发时间开始,某个时间点之前
+ * @param [endUnixTime] 出发时间截止,某个时间段内的
+ * @returns {Promise | Promise<unknown>}
+ */
+function fightSearch(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);
+}
+
+
+/**
+ * 获取航班票数
+ * @param fightId
+ * @returns {Promise<unknown>}
+ */
+function fightTicks(fightId){
+    let sql=``,values=[];
+    sql=`select ff.*,count(t.flightId = 1 or null) as pay
+            from 
+            (select totalVotes from flight where id = 1) as ff,
+            airTickets as t`
+    return mysql.pq(sql,values);
+}

+ 8 - 10
db.md

@@ -30,14 +30,6 @@
 | cityType  | char    | 1    | 1国内2国际 | 城市的名称 |
 | cityState | int     | 1    | 1启用2封禁 | 封禁 |
 
-## 航线表route(管理员创建航线)
-| 字段            | 类型   | 默认值 | 可选值         | 备注            |
-|---------------|------|----|-------------|---------------|
-| id            | int  | pk | n           | id            |
-| departureCity | int  | null | n           | 出发城市          |
-| targetCity    | int  | null | n           | 目标城市          |
-| routeType     | char | 1 | 1(国内),2(国际) | 航线类型,是否为跨国航线,程序自动生成 | 
-| routeName | varchar | 00001 | string | 航线名称          |
 
 ## 航班表fight(管理员通过航线创建航班),需要输入价格和指定飞机和起飞时间
 | 字段            | 类型      | 默认值 | 可选值                      | 备注     |
@@ -46,12 +38,16 @@
 | routeId       | int     | pk  | 1                        | n      | 对应的航线id |
 | originalPrice | floor   | 1   | 0-99999                  | 原始机票价格 |
 | currentPrice  | floor   | 1   | 0-99999                  | 当前机票价格 |
-| sailingTime   | date    | now | now                      | 起飞时间   |
-| langdinTime   | date    | now | time                     | 到站时间   |
+| sailingTime   | varcahr    | 0 | 0                      | 起飞时间,unix时间戳   |
+| langdinTime   | varcahr    | 0 | 0                     | 到站时间,unix时间戳   |
 | airplaneCode  | varcahr | 755 | s                        | 飞机代号   |
 | flightState   | char    | 1   | 1(售票),2(值机),3(飞行中),4(结束) | 航班状态   |
 | lateState     | cahr    | 1   | 1(正点),2(晚点)              | 航班晚点状态 |
 | totalVotes    | int | 3   | 1-200                    | 售卖总票数  |
+| routeType     | char | 1 | 1(国内),2(国际) | 航线类型,是否为跨国航线,程序自动生成 | 
+| departureCity | int  | null | n           | 出发城市          |
+| targetCity    | int  | null | n           | 目标城市          |
+| fightName | varchar | '' | '' | 航班名称 | 
 
 ## 机票表 airTickets
 | 字段       | 类型      | 默认值 | 可选值 | 备注                  |
@@ -83,4 +79,6 @@
 |----------|---------|----|-----|------|
 | recommendId | int | pk | n | 推荐id | 
 | flightId | int | pk | n | 航班id |
+| recommendIndex | int | 1 | n | 推荐指数 |
+
 

+ 5 - 1
maps/field.js

@@ -8,4 +8,8 @@ module.exports = {
     userFreezeState:2,
     // 用户注销状态
     userStopState: 3,
-}
+    // 国内航班
+    routeType_domestic:1,
+    // 国际航班
+    routeType_international:2,
+}

+ 7 - 2
until/time.js

@@ -1,5 +1,10 @@
-function getUnixTimeStamp(){
-    return new Date().getTime() / 1000;
+/**
+ * 获取unix时间戳
+ * @param [date] 时间对象
+ * @returns {number}
+ */
+function getUnixTimeStamp(date = new Date()){
+    return date.getTime() / 1000;
 }