|  | @@ -4,10 +4,10 @@ const c_flight = require('./c_flight');
 | 
	
		
			
				|  |  |  const handle = require('../until/handle')
 | 
	
		
			
				|  |  |  const field = require('../maps/field')
 | 
	
		
			
				|  |  |  const codeMap = require('../maps/rcodeMap')
 | 
	
		
			
				|  |  | -const {userType} = require("../maps/field");
 | 
	
		
			
				|  |  | +const {userType, orderType_all} = require("../maps/field");
 | 
	
		
			
				|  |  |  const {getUnixTimeStamp} = require("../until/time");
 | 
	
		
			
				|  |  |  // 更新订单
 | 
	
		
			
				|  |  | -const {reloadOrder,payOrder} = require("./TimeUpdate");
 | 
	
		
			
				|  |  | +const {reloadOrder, payOrderItem} = require("./TimeUpdate");
 | 
	
		
			
				|  |  |  // 处理账号的注册登录,
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  async function checkAccount(account,userType= field.userType){
 | 
	
	
		
			
				|  | @@ -110,7 +110,7 @@ async function info(type,account){
 | 
	
		
			
				|  |  |      if(result.length < 1){
 | 
	
		
			
				|  |  |          throw {rcode:codeMap.notFound,msg:'无法找到账户'}
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  | -    // 注册成功
 | 
	
		
			
				|  |  | +    // 用户信息
 | 
	
		
			
				|  |  |      return result[0];
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -282,10 +282,33 @@ async function addCar(flightId,account){
 | 
	
		
			
				|  |  |      return result;
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +/**
 | 
	
		
			
				|  |  | + * 获取指定用户的订单
 | 
	
		
			
				|  |  | + * @param account
 | 
	
		
			
				|  |  | + * @param orderType
 | 
	
		
			
				|  |  | + * @returns {Promise<*>}
 | 
	
		
			
				|  |  | + */
 | 
	
		
			
				|  |  | +async function orders(account,orderType){
 | 
	
		
			
				|  |  | +    // 获取订单详情
 | 
	
		
			
				|  |  | +    let err,user,result;
 | 
	
		
			
				|  |  | +    [err,user] = await handle(info(userType,account));
 | 
	
		
			
				|  |  | +    if(err)throw err;
 | 
	
		
			
				|  |  | +    console.log(orderType);
 | 
	
		
			
				|  |  | +    // 获取账户
 | 
	
		
			
				|  |  | +    [err,result] = await handle(db_user.userOrder(user.id,orderType));
 | 
	
		
			
				|  |  | +    if(err)throw err;
 | 
	
		
			
				|  |  | +    return result;
 | 
	
		
			
				|  |  | +}
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -// 创建一个基础订单,未支付
 | 
	
		
			
				|  |  | +/**
 | 
	
		
			
				|  |  | + * 新建订单
 | 
	
		
			
				|  |  | + * @param account
 | 
	
		
			
				|  |  | + * @param flightId
 | 
	
		
			
				|  |  | + * @param travelIds
 | 
	
		
			
				|  |  | + * @returns {Promise<*>}
 | 
	
		
			
				|  |  | + */
 | 
	
		
			
				|  |  |  async function addOrder(account,flightId,travelIds){
 | 
	
		
			
				|  |  | -    let flight;
 | 
	
		
			
				|  |  | +    let flight,err,result;
 | 
	
		
			
				|  |  |      if(travelIds.length < 1){throw {rcode:codeMap.notParam,msg:'缺少乘车人'}}
 | 
	
		
			
				|  |  |      // 检查是否有不知名的乘机人
 | 
	
		
			
				|  |  |      for(let i = 0;i<travelIds.length;i++){
 | 
	
	
		
			
				|  | @@ -295,7 +318,7 @@ async function addOrder(account,flightId,travelIds){
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |      let userId,unixTime = getUnixTimeStamp();
 | 
	
		
			
				|  |  |      // 根据账号查找id
 | 
	
		
			
				|  |  | -    let [err,result] = await handle(db_user.findAccountUser(userType,account));
 | 
	
		
			
				|  |  | +   [err,result] = await handle(db_user.findAccountUser(userType,account));
 | 
	
		
			
				|  |  |      if(err)throw err;
 | 
	
		
			
				|  |  |      if(result.length < 1){
 | 
	
		
			
				|  |  |          throw {rcode:codeMap.notFound,msg:'无法找到账户'}
 | 
	
	
		
			
				|  | @@ -307,12 +330,17 @@ async function addOrder(account,flightId,travelIds){
 | 
	
		
			
				|  |  |      if((parseInt(flight.pay) + travelIds.length) > parseInt(flight.totalVotes)){
 | 
	
		
			
				|  |  |          throw {rcode:codeMap.customError,msg:'航班机票不足'}
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  | +    if(flight.flightState != field.flightState_sail){
 | 
	
		
			
				|  |  | +        throw {rcode:codeMap.customError,msg:'该航班已经结束售卖'}
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  |      // 添加订单
 | 
	
		
			
				|  |  |      [err,result] = await handle(db_user.addOrder(userId,flightId,travelIds,unixTime));
 | 
	
		
			
				|  |  |      if(err)throw err;
 | 
	
		
			
				|  |  |      await reloadOrder();
 | 
	
		
			
				|  |  | -    return result;
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | +    // 添加订单
 | 
	
		
			
				|  |  | +    [err,result] = await handle(db_user.findOrder(userId,flightId,travelIds,unixTime));
 | 
	
		
			
				|  |  | +    if(err)throw err;
 | 
	
		
			
				|  |  | +    return result[0]||{};
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  /**
 | 
	
	
		
			
				|  | @@ -325,10 +353,9 @@ async function payOrder(account,orderId){
 | 
	
		
			
				|  |  |      let userId,order,flight,travels;
 | 
	
		
			
				|  |  |      order.travelIds = undefined;
 | 
	
		
			
				|  |  |      // 根据账号查找id
 | 
	
		
			
				|  |  | -    let [err,result] = await handle(db_user.findAccountUser(userType,account));
 | 
	
		
			
				|  |  | +    let [err,result] = await handle(info(userType,account));
 | 
	
		
			
				|  |  |      if(err)throw err;
 | 
	
		
			
				|  |  | -    if(result.length < 1){ throw {rcode:codeMap.notFound,msg:'无法找到账户'}}
 | 
	
		
			
				|  |  | -    userId = result[0].id;
 | 
	
		
			
				|  |  | +    userId = result.id;
 | 
	
		
			
				|  |  |      [err,result] = await handle(db_user.userOrderInfo(userId,orderId));
 | 
	
		
			
				|  |  |      if(err)throw err;
 | 
	
		
			
				|  |  |      if(result.length < 1){ throw {rcode:codeMap.notFound,msg:'无法找到相关订单'} }
 | 
	
	
		
			
				|  | @@ -347,24 +374,83 @@ async function payOrder(account,orderId){
 | 
	
		
			
				|  |  |              [err,result] = await handle(db_user.clearTick(order.id));
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  | -    await payOrder(orderId);
 | 
	
		
			
				|  |  | -    return true;
 | 
	
		
			
				|  |  | +    [err,result] = await handle(db_user.payOrder(orderId));
 | 
	
		
			
				|  |  | +    if(err){console.log(err);throw err}
 | 
	
		
			
				|  |  | +    payOrderItem();
 | 
	
		
			
				|  |  | +    return result;
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  /**
 | 
	
		
			
				|  |  |   * 选坐
 | 
	
		
			
				|  |  | + * @param account
 | 
	
		
			
				|  |  |   * @param tickId 机票id
 | 
	
		
			
				|  |  |   * @param row 排
 | 
	
		
			
				|  |  |   * @param col 行
 | 
	
		
			
				|  |  |   * @returns {Promise<void>}
 | 
	
		
			
				|  |  |   */
 | 
	
		
			
				|  |  | -async function chooseSit(tickId,row,col){
 | 
	
		
			
				|  |  | -    let tick;
 | 
	
		
			
				|  |  | +async function chooseSit(account,tickId,row,col){
 | 
	
		
			
				|  |  | +    let tick,order,travels;
 | 
	
		
			
				|  |  |      // 获取对应的航班信息
 | 
	
		
			
				|  |  |      let [err,result] = await handle(db_user.tickInfo(tickId))
 | 
	
		
			
				|  |  |      if(err)throw err;
 | 
	
		
			
				|  |  |      if(result.length < 1){throw {rcode:codeMap.notFound,msg:'无法找到机票'}}
 | 
	
		
			
				|  |  | +    tick = result[0];
 | 
	
		
			
				|  |  | +    [err,order] = await handle(orderInfo(account,tick.orderId))
 | 
	
		
			
				|  |  | +    if(err)throw err;
 | 
	
		
			
				|  |  | +    // 查看指定航班指定位置的票是否被选中
 | 
	
		
			
				|  |  | +    [err,result] = await handle(db_user.findTickRowCol(order.flightId,row,col))
 | 
	
		
			
				|  |  | +    if(err)throw err;
 | 
	
		
			
				|  |  | +    if(result.length > 0){throw {rcode:codeMap.dataRepeat,msg:'该位置已经被占用了呢'}}
 | 
	
		
			
				|  |  | +    // 设置座位
 | 
	
		
			
				|  |  | +    [err,result] = await handle(db_user.tickChooseToSel(tickId,row,col))
 | 
	
		
			
				|  |  | +    if(err)throw err;
 | 
	
		
			
				|  |  | +    // 遍历查看订单是否全部选坐完成.全部选坐完成则
 | 
	
		
			
				|  |  | +    travels=order.travelIds.split(',');
 | 
	
		
			
				|  |  | +    [err,result] = await handle(db_user.tickSearch({
 | 
	
		
			
				|  |  | +        orderId: order.id,
 | 
	
		
			
				|  |  | +        tickState: field.tickState_seat
 | 
	
		
			
				|  |  | +    }));
 | 
	
		
			
				|  |  | +    if(err) {throw err}
 | 
	
		
			
				|  |  | +    // 已经全部值机,订单切换为全部值机的状态
 | 
	
		
			
				|  |  | +    if(result.length === travels.length){
 | 
	
		
			
				|  |  | +        [err,result] = await handle(db_user.changeOrder(order.id,{payState:field.payState_choose}));
 | 
	
		
			
				|  |  | +        if(err) {throw  err}
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +    return result;
 | 
	
		
			
				|  |  | +}
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +/**
 | 
	
		
			
				|  |  | + * 退款机票
 | 
	
		
			
				|  |  | + * @param account
 | 
	
		
			
				|  |  | + * @param tickId
 | 
	
		
			
				|  |  | + * @returns {Promise<*>}
 | 
	
		
			
				|  |  | + */
 | 
	
		
			
				|  |  | +async function refundTick(account,tickId){
 | 
	
		
			
				|  |  | +    let tick,order,travels;
 | 
	
		
			
				|  |  | +    // 获取对应的航班信息
 | 
	
		
			
				|  |  | +    let [err,result] = await handle(db_user.tickInfo(tickId))
 | 
	
		
			
				|  |  | +    if(err)throw err;
 | 
	
		
			
				|  |  | +    if(result.length < 1){throw {rcode:codeMap.notFound,msg:'无法找到机票'}}
 | 
	
		
			
				|  |  | +    tick = result[0];
 | 
	
		
			
				|  |  | +    if(tick.tickState != field.tickState_create){throw {rcode:codeMap.customError,msg:'该机票不允许退款'}}
 | 
	
		
			
				|  |  | +    [err,order] = await handle(orderInfo(account,tick.orderId))
 | 
	
		
			
				|  |  | +    if(err)throw err;
 | 
	
		
			
				|  |  | +    // 遍历查看订单是否为部分退款
 | 
	
		
			
				|  |  | +    travels=order.travelIds.split(',');
 | 
	
		
			
				|  |  | +    [err,result] = await handle(db_user.tickSearch({
 | 
	
		
			
				|  |  | +        orderId: order.id,
 | 
	
		
			
				|  |  | +        tickState: field.tickState_refund
 | 
	
		
			
				|  |  | +    }));
 | 
	
		
			
				|  |  | +    if(err) {throw err}
 | 
	
		
			
				|  |  | +    // 是否已经全部退款
 | 
	
		
			
				|  |  | +    if(result.length === travels.length){
 | 
	
		
			
				|  |  | +        [err,result] = await handle(db_user.changeOrder(order.id,{payState:field.payState_refund}));
 | 
	
		
			
				|  |  | +        if(err) {throw  err}
 | 
	
		
			
				|  |  | +    }else{
 | 
	
		
			
				|  |  | +        [err,result] = await handle(db_user.changeOrder(order.id,{payState:field.payState_rebates}));
 | 
	
		
			
				|  |  | +        if(err) {throw  err}
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +    return result;
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  /**
 | 
	
	
		
			
				|  | @@ -390,7 +476,7 @@ async function orderInfo(account,orderId){
 | 
	
		
			
				|  |  |      travels=order.travelIds.split(',');
 | 
	
		
			
				|  |  |      order.travels = travels.map(async travelId=>{
 | 
	
		
			
				|  |  |          [err,result] = await handle(db_user.travelInfo(travelId));
 | 
	
		
			
				|  |  | -        if(err) console.log('获取乘车人信息失败'); throw  err;
 | 
	
		
			
				|  |  | +        if(err) {console.log('获取乘车人信息失败'); throw  err}
 | 
	
		
			
				|  |  |          if(result.length < 1){ throw {rcode:codeMap.notFound,msg:'无法找到乘车人'} }
 | 
	
		
			
				|  |  |          // 查找对应车票信息
 | 
	
		
			
				|  |  |          [err,result] = await handle(db_user.orderTick(order.id,travelId));
 | 
	
	
		
			
				|  | @@ -402,7 +488,13 @@ async function orderInfo(account,orderId){
 | 
	
		
			
				|  |  |      return order;
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | +/**
 | 
	
		
			
				|  |  | + * 修改订单乘机人
 | 
	
		
			
				|  |  | + * @param account
 | 
	
		
			
				|  |  | + * @param orderId
 | 
	
		
			
				|  |  | + * @param travelIds
 | 
	
		
			
				|  |  | + * @returns {Promise<void>}
 | 
	
		
			
				|  |  | + */
 | 
	
		
			
				|  |  |  async function changeOrderTravel(account,orderId,travelIds){
 | 
	
		
			
				|  |  |      let userId,order,travels;
 | 
	
		
			
				|  |  |      // 根据账号查找id
 | 
	
	
		
			
				|  | @@ -438,6 +530,10 @@ module.exports = {
 | 
	
		
			
				|  |  |      travels,
 | 
	
		
			
				|  |  |      travelInfo,
 | 
	
		
			
				|  |  |      updateTravel,
 | 
	
		
			
				|  |  | -    addOrder
 | 
	
		
			
				|  |  | +    orders,
 | 
	
		
			
				|  |  | +    addOrder,
 | 
	
		
			
				|  |  | +    chooseSit,
 | 
	
		
			
				|  |  | +    payOrder,
 | 
	
		
			
				|  |  | +    changeOrderTravel
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  |  
 |