kindring 2 tahun lalu
induk
melakukan
7da75bf12d

+ 5 - 1
controller/account.js

@@ -446,7 +446,11 @@ async function chooseSit(account,tickId,row,col){
     if(err) {throw err}
     // 已经全部值机,订单切换为全部值机的状态
     if(result.length === travels.length){
-        [err,result] = await handle(db_user.changeOrder(order.id,{payState:field.payState_choose}));
+        [err,result] = await handle(db_user.changeOrder(order.id,{payState:field.payState_choose,chooseNum:result.length}));
+        if(err) {throw  err}
+    }else{
+        // 添加已经选坐的乘客数量
+        [err,result] = await handle(db_user.changeOrder(order.id,{chooseNum:result.length}));
         if(err) {throw  err}
     }
     return result;

+ 34 - 1
controller/c_flight.js

@@ -286,6 +286,38 @@ async function updateAir(airId,updateParam){
     return result;
 }
 
+/**
+ * 航班进入下一状态
+ * @param flightId 航班id
+ * @param nextState 下一个状态
+ * @returns {Promise<*>}
+ */
+async function setState(flightId,nextState){
+    let err,flight,result;
+    // 获取航班信息
+     [err,flight] = await handle(flightInfo(flightId));
+    if(err){throw err}
+    if(flight.flightState != (nextState -1)){
+        throw {rcode:codeMap.customError,msg:'不允许跳级修改'}
+    }
+    [err,result] = await handle(db_air.updateFlight(flightId,{
+        flightState:nextState
+    }))
+    if(err){throw err}
+    if(nextState == 2){
+        // 切换为检票,无操作
+        console.log(`航班${flightId},开始检票`);
+    }else if(nextState == 3){
+        // 切换为飞行中,查看是否有订单是未值机的
+        console.log(`航班${flightId},开始飞行`);
+    }else if(nextState == 4){
+        // 切换为订单完成
+        // 查看是否有已经值机的用户
+        [err,result] = await handle(db_user.okOrder(flightId))
+        if(err){throw err}
+    }
+    return result;
+}
 
 module.exports = {
     searchFlight,
@@ -298,5 +330,6 @@ module.exports = {
     addAir,
     airs,
     updateAir,
-    seatInfo
+    seatInfo,
+    setState
 }

+ 2 - 0
controller/c_recommend.js

@@ -74,6 +74,8 @@ async function homeRecommends(){
     return recommends;
 }
 
+
+
 module.exports = {
     list,
     addRecommend,

+ 4 - 4
database/d_recommend.js

@@ -14,7 +14,7 @@ const checkArgumentsIsEmpty = require('../until/checkArgumentsIsEmpty')
 function addRecommend(recommendName,discript,zIndex = 1,imgUrl = 'public/upload/bg_weekend.jpg'){
     let sql=``,values=[];
     sql+=`insert into 
-            recommend (recommendName,discript,zIndex,bg) 
+            recommendDir (recommendName,discript,zIndex,bg) 
             values(?,?,?,?);`
     values.push(recommendName,discript,zIndex,imgUrl)
     return mysql.pq(sql,values);
@@ -39,9 +39,9 @@ function recommendList(){
  */
 function find(recommendId){
     let sql=``,values=[];
-    sql+=`select * from recommendDir where id = ?`
-    sql += ';'
-    values.push(recommendId)
+    sql+=`select * from recommendDir where id = ?`;
+    sql += ';';
+    values.push(recommendId);
     return mysql.pq(sql,values);
 }
 

+ 8 - 2
database/d_user.js

@@ -488,8 +488,14 @@ function userOrderInfo(userId,orderId){
     return mysql.pq(sql,values);
 }
 
-function orderTick(){
-
+/**
+ * 指定航班的所有订单完成,部分退款和全部选坐的都
+ * @param flightId
+ */
+function okOrder(flightId){
+    let sql=``,values=[];
+    sql += `update orders set payState = ? where flightId = ? and (payState = ? or chooseNum != 0)`
+    values.push(fields.payState_end,flightId,fields.payState_choose);
 }
 
 module.exports =  {

+ 2 - 2
db.md

@@ -83,6 +83,7 @@
 | refundTick | varchar | | | 退款的机票id | 
 | payPrice | floor(10,2) | n | 0-9999 | 订单价格 |
 | unitPrice | floor(10,2) | n | 0-9999 | 机票单价 | 
+| chooseNum | int | 0 | n | 已经选坐的数量 |
 
 ## 机票表 airTicket (需要选坐,多机票订单不允许)
 | 字段       | 类型      | 默认值 | 可选值 | 备注                  |
@@ -93,7 +94,7 @@
 | ticketState | char(2) | 1 | 1(已经创建) 2(已经值机) 3(等待飞行) 4(退款) | 机票状态 |
 | line | int | n | 1-24 | 座位排数 |
 | row | int | n | 1-6 | 座位列数 |
-| cussTime | int | n | n | 值机时间 |
+| cussTime | int | n | n | 值机时间 | 
 
 ## 购物车 car
 | 字段       | 类型      | 默认值 | 可选值 | 备注                  |
@@ -117,4 +118,3 @@
 | flightId | int | pk | n | 航班id |
 | recommendIndex | int | 1 | n | 推荐指数 |
 
-

+ 1 - 3
routes/flight_api.js

@@ -230,9 +230,7 @@ router.post('/state',
     }),
     async (req,res)=>{
         try{
-            let results = await c_flight.updateFlight(req.body.flightId, {
-                flightState:req.body.nextState
-            });
+            let results = await c_flight.setState(req.body.flightId, req.body.nextState);
             res.json({
                 rcode: code.ok,
                 data: results

+ 46 - 34
routes/recommend_api.js

@@ -1,18 +1,19 @@
 const router = require('express').Router();
 const paramsCheck = require('../middleware/paramsCheck');
 const checkLogin = require('../middleware/checkLogin');
+const apiErrHandle = require('../until/apiErrHandle');
 const c_recommend = require("../controller/c_recommend");
 const field = require('../maps/field');
 const code = require('../maps/rcodeMap');
 const progress = require('../maps/progress')
-router.get('/recommends',async (req,res)=>{
-    try{
+router.get('/recommends', async (req, res) => {
+    try {
         let results = await c_recommend.list();
         res.json({
             rcode: code.ok,
             data: results
         })
-    }catch (error) {
+    } catch (error) {
         if (error.rcode !== code.customError) {
             console.log(error);
         }
@@ -22,14 +23,14 @@ router.get('/recommends',async (req,res)=>{
         });
     }
 });
-router.get('/homer',async (req,res)=>{
-    try{
+router.get('/homer', async (req, res) => {
+    try {
         let results = await c_recommend.homeRecommends();
         res.json({
             rcode: code.ok,
             data: results
         })
-    }catch (error) {
+    } catch (error) {
         if (error.rcode !== code.customError) {
             console.log(error);
         }
@@ -41,48 +42,48 @@ router.get('/homer',async (req,res)=>{
 });
 
 
-router.post('/recommend/add',
+router.post('/add',
     checkLogin(field.adminType),
     paramsCheck({
-        post:{
-            recommendName:{required:true},
-            descript:{required:true},
+        post: {
+            recommendName: {required: true},
+            descript: {required: true},
         }
     }),
-    async (req,res)=>{
-    try{
-        let results = await c_recommend.addRecommend(req.body.recommendName,req.body.descript ,req.body.zIndex,req.body.imgUrl);
-        res.json({
-            rcode: code.ok,
-            data: results
-        })
-    }catch (error) {
-        if (error.rcode !== code.customError) {
-            console.log(error);
+    async (req, res) => {
+        try {
+            let results = await c_recommend.addRecommend(req.body.recommendName, req.body.descript, req.body.zIndex, req.body.imgUrl);
+            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
+            });
         }
-        res.json({
-            rcode: error.rcode || code.serverError,
-            msg: error.msg || error.message
-        });
-    }
-});
+    });
 
-router.post('/recommend/flights',
+router.post('/flights',
     checkLogin(field.adminType),
     paramsCheck({
-        post:{
-            recommendId:{required:true},
-            flights:{required:true},
+        post: {
+            recommendId: {required: true},
+            flights: {required: true},
         }
     }),
-    async (req,res)=>{
-        try{
-            let results = await c_recommend.addFlights(req.body.recommendId,req.body.flights);
+    async (req, res) => {
+        try {
+            let results = await c_recommend.addFlights(req.body.recommendId, req.body.flights);
             res.json({
                 rcode: code.ok,
                 data: results
             })
-        }catch (error) {
+        } catch (error) {
             if (error.rcode !== code.customError) {
                 console.log(error);
             }
@@ -93,5 +94,16 @@ router.post('/recommend/flights',
         }
     });
 
+router.post('/search', async (req, res) => {
+    try {
+        let results = await c_recommend.list();
+        res.json({
+            rcode: code.ok,
+            data: results
+        })
+    } catch (error) {
+        apiErrHandle('搜索航班', res, error);
+    }
+});
 
 module.exports = router;