فهرست منبع

航班查询相关

kindring 3 سال پیش
والد
کامیت
0d8180d19d
5فایلهای تغییر یافته به همراه128 افزوده شده و 15 حذف شده
  1. 3 0
      app.js
  2. 13 3
      controller/c_flight.js
  3. 29 11
      database/d_air.js
  4. 0 1
      routes/citys.js
  5. 83 0
      routes/flight_api.js

+ 3 - 0
app.js

@@ -10,6 +10,8 @@ const usersRouter = require('./routes/users');
 const citysRouter = require('./routes/citys');
 const adminRouter = require('./routes/admin');
 const captcha = require('./routes/captcha');
+const flight = require('./routes/flight_api');
+
 const app = express();
 
 const serverConfig = require('./configs/server.json');
@@ -43,6 +45,7 @@ app.use('/user', usersRouter);
 app.use('/admin', adminRouter);
 app.use('/api/city/',citysRouter);
 app.use('/api/captcha', captcha);
+app.use('/api/flight', flight);
 
 
 

+ 13 - 3
controller/c_flight.js

@@ -6,7 +6,7 @@ const field = require('../maps/field')
 const codeMap = require('../maps/rcodeMap')
 
 /**
- *
+ * 用户查询指定出发时间的航班
  * @param departureCity 出发城市
  * @param targetCity 目标城市
  * @param routeType 航线类型
@@ -21,7 +21,7 @@ async function searchFlight(departureCity,targetCity,routeType,startUnixTime,end
 }
 
 /**
- * 航班列表
+ * 航班列表,所有航班列表
  * @param routeType 航班类型
  * @returns {Promise<*>}
  */
@@ -31,6 +31,16 @@ async function flightList(routeType){
     return result;
 }
 
+/**
+ * 航班具体信息,用来给用户直接查看航班
+ * @param flightId
+ * @returns {Promise<void>}
+ */
+async function flightInfo(flightId){
+    let [err,result] = await handle(db_air.flightInfo(flightId));
+    if(err){throw err}
+    return result;
+}
 
 
 /**
@@ -97,5 +107,5 @@ module.exports = {
     searchFlight,
     flightList,
     addFlight,
-
+    flightInfo
 }

+ 29 - 11
database/d_air.js

@@ -18,10 +18,11 @@ 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
+    sql = `select f.id,f.originalPrice,f.currentPrice,f.sailingTime,f.langdinTime ,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
+            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){
@@ -43,18 +44,34 @@ function flightSearch(departureCity,targetCity,routeType,startUnixTime,endUnixTi
 }
 
 
+
 /**
- * 显示所有航班列表
+ * 显示所有航班列表,管理员级别
  * @param routeType
  * @returns {Promise | Promise<unknown>}
  */
-function flightList(routeType){
+function flightList(){
     let sql=``,values=[];
-    sql=`select * from flight`;
-    if(routeType){
-        sql += ` where routeType = ?`
-        values.push(routeType);
-    }
+    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;`;
+    return mysql.pq(sql,values);
+}
+
+/**
+ * 航班具体信息
+ * @param flightId
+ * @returns {Promise<unknown>}
+ */
+function flightInfo(flightId){
+    let sql=``,values=[];
+    sql+=`select ff.*,count(flightId = ? or null) as pay
+            from 
+            (select * from flight where id = ?) as ff,
+            airTickets;`
+    values.push(flightId,flightId)
     return mysql.pq(sql,values);
 }
 
@@ -218,5 +235,6 @@ module.exports = {
     addFlight,
     flightTicks,
     updateFlight,
-    flightList
+    flightList,
+    flightInfo
 }

+ 0 - 1
routes/citys.js

@@ -68,7 +68,6 @@ router.post('/change',
         }catch (error) {
             if (error.rcode !== code.customError) {
                 console.log(error);
-                console.log.error(`get area map error ${error.message||error.msg}`);
             }
             res.json({
                 rcode: error.rcode || code.serverError,

+ 83 - 0
routes/flight_api.js

@@ -0,0 +1,83 @@
+const router = require('express').Router();
+const c_flight = require('../controller/c_flight')
+const paramsCheck = require('../middleware/paramsCheck');
+const checkLogin = require('../middleware/checkLogin');
+const code = require('../maps/rcodeMap')
+const field = require('../maps/field')
+const c_area = require("../controller/c_area");
+
+router.get('/list',async (req,res)=>{
+    try{
+        let results = await c_flight.flightList();
+        res.json({
+            rcode: code.ok,
+            data: results
+        })
+    }catch (error) {
+        if (error.rcode !== code.customError) {
+            console.log(error);
+        }
+        res.json({
+            rcode: error.rcode || code.serverError,
+            msg: error.msg || error.message
+        });
+    }
+});
+
+router.post('/search',
+    paramsCheck({
+        post:{
+            departure:{required:true},
+            target:{required:true},
+        }
+    }),
+    async (req,res)=>{
+    try{
+        let params = [
+             req.body.departure,
+             req.body.target,
+             req.body.routeType,
+             req.body.startTime,
+             req.body.endTime,
+        ]
+        let results = await c_flight.searchFlight(...params);
+        res.json({
+            rcode: code.ok,
+            data: results
+        })
+    }catch (error) {
+        if (error.rcode !== code.customError) {
+            console.log(error);
+        }
+        res.json({
+            rcode: error.rcode || code.serverError,
+            msg: error.msg || error.message
+        });
+    }
+})
+
+router.get('/detail',
+    paramsCheck({
+        get:{
+            flight:{required:true}
+        }
+    }),
+    async (req,res)=>{
+        try{
+            let results = await c_flight.flightInfo(req.query.flight);
+            res.json({
+                rcode: code.ok,
+                data: results
+            })
+        }catch (error) {
+            if (error.rcode !== code.customError) {
+                console.log(error);
+            }
+            res.json({
+                rcode: error.rcode || code.serverError,
+                msg: error.msg || error.message
+            });
+        }
+    }
+)
+module.exports = router;