/// <summary> /// 获取火车出票推送内容 /// </summary> /// <returns></returns> private void GetTraPrintTicketMessage(SendAppMessageModel sendAppMessageModel) { if (sendAppMessageModel.OrderType == OrderSourceTypeEnum.Tra && sendAppMessageModel.SendType == SendAppMessageTypeEnum.PrintTicketNotice) { TraOrderEntity traOrderEntity = _traOrderDal.Find <TraOrderEntity>(sendAppMessageModel.OrderId); sendAppMessageModel.SendContent = string.Format("您的火车票订单{0}已经出票,请确认", traOrderEntity.OrderId); } }
public TraOrderInfoModel GetTraOrderByOrderId(int orderId) { TraOrderEntity traOrderEntity = _traOrderDal.Find <TraOrderEntity>(orderId); if (traOrderEntity == null) { return(null); } TraOrderModel traOrderModel = Mapper.Map <TraOrderEntity, TraOrderModel>(traOrderEntity); TraOrderStatusEntity traOrderStatusEntity = _traOrderStatusDal.Query <TraOrderStatusEntity>(n => n.OrderId == orderId, true).FirstOrDefault(); TraOrderStatusModel traOrderStatusModel = Mapper.Map <TraOrderStatusEntity, TraOrderStatusModel>(traOrderStatusEntity); List <TraOrderDetailEntity> traOrderDetailEntities = _traOrderDetailDal.Query <TraOrderDetailEntity>(n => n.OrderId == orderId, true).ToList(); List <TraOrderDetailModel> traOrderDetailModels = Mapper.Map <List <TraOrderDetailEntity>, List <TraOrderDetailModel> >(traOrderDetailEntities); List <int> odIdList = new List <int>(); traOrderDetailModels.ForEach(n => odIdList.Add(n.OdId)); List <TraPassengerEntity> traPassengerEntities = _traPassengerDal.Query <TraPassengerEntity>(n => odIdList.Contains(n.OdId), true).ToList(); List <TraPassengerModel> traPassengerModels = Mapper.Map <List <TraPassengerEntity>, List <TraPassengerModel> >(traPassengerEntities); foreach (var detail in traOrderDetailModels) { detail.PassengerList = new List <TraPassengerModel>(); var passengerModel = traPassengerModels.FindAll(n => n.OdId == detail.OdId); detail.PassengerList.AddRange(passengerModel); } TraOrderInfoModel orderInfoModel = new TraOrderInfoModel(); orderInfoModel.Order = traOrderModel; orderInfoModel.OrderStatus = traOrderStatusModel; orderInfoModel.OrderDetailList = traOrderDetailModels; return(orderInfoModel); }
public List <int> SplitOrder(int orderId, string oid) { //获取原始订单 TraOrderEntity copyTraOrderEntity = _traOrderDal.Find <TraOrderEntity>(orderId); if (copyTraOrderEntity == null) { throw new Exception("复制来源订单异常"); } if (string.IsNullOrEmpty(copyTraOrderEntity.OrderFrom) || copyTraOrderEntity.OrderFrom != "Hand") { throw new Exception("该订单不是手动导单不能拆单!"); } //获取原行程信息 List <TraOrderDetailEntity> copyTraOrderDetailEntities = _traOrderDetailDal.Query <TraOrderDetailEntity>(n => n.OrderId == orderId, true) .ToList(); //原始订单乘车人信息 List <int> odIdList = copyTraOrderDetailEntities.Select(n => n.OdId).ToList(); List <TraPassengerEntity> copyTraPassengerEntities = _traPassengerDal.Query <TraPassengerEntity>(n => odIdList.Contains(n.OdId), true).ToList(); List <string> nameList = copyTraPassengerEntities.Select(n => n.Name).Distinct().ToList(); if (nameList.Count <= 1) { throw new Exception("该订单只有一个乘车人不能拆单!"); } List <int> orderIdList = new List <int>(); foreach (string name in nameList) { List <TraPassengerEntity> pList = copyTraPassengerEntities.FindAll(n => n.Name == name); List <int> oList = pList.Select(n => n.OdId).ToList(); List <TraOrderDetailEntity> tList = copyTraOrderDetailEntities.FindAll(n => oList.Contains(n.OdId)).ToList(); int newOrderId = AddOrder(pList, tList, copyTraOrderEntity, oid); orderIdList.Add(newOrderId); } return(orderIdList); #region ////原始订单信息映射复制新实体 //TraOrderEntity traOrderEntity = Mapper.Map<TraOrderEntity, TraOrderEntity>(copyTraOrderEntity); //List<TraOrderDetailEntity> traOrderDetailEntities = // Mapper.Map<List<TraOrderDetailEntity>, List<TraOrderDetailEntity>>(copyTraOrderDetailEntities); //List<TraPassengerEntity> traPassengerEntities = // Mapper.Map<List<TraPassengerEntity>, List<TraPassengerEntity>>(copyTraPassengerEntities); //if (copyPidList == null || copyPidList.Count == 0 ) //{ // throw new Exception("未找到乘车人不能拆单"); //} //if (copyPidList.Count == 1) //{ // throw new Exception("只有一个乘车人不能拆单"); //} ////拆单插入订单 //foreach (var p in traPassengerEntities) //{ // //复制新实体 新增订单 // traOrderEntity.CreateOid = copyTraOrderModel.CreateOid; // traOrderEntity.CopyType = copyTraOrderModel.CopyType; // traOrderEntity.PayAmount = copyTraOrderModel.PayAmount; // traOrderEntity.TotalMoney = copyTraOrderModel.PayAmount; // traOrderEntity.PrintProcurementTime = null; // traOrderEntity.IsNeedPrintTime = null; // //订单表插入 // traOrderEntity = _traOrderDal.Insert(traOrderEntity); // //乘车人插入 // _traPassengerDal.Insert(p); //} ////插入行程 //foreach (var detail in traOrderDetailEntities) //{ // detail.OrderId = traOrderEntity.OrderId; // List<TraPassengerEntity> thisTravelPassengerList = // traPassengerEntities.FindAll(n => n.OdId == detail.OdId); // detail.ServiceFee = thisTravelPassengerList.Sum(n => (n.ServiceFee ?? 0)) / thisTravelPassengerList.Count; // detail.FacePrice = thisTravelPassengerList.Sum(n => (n.FacePrice ?? 0)) / thisTravelPassengerList.Count; // detail.TotalPrice = (detail.ServiceFee + detail.FacePrice) * (detail.TicketNum ?? 0); // //行程表插入 // TraOrderDetailEntity traOrderDetailEntity = _traOrderDetailDal.Insert(detail); //} #endregion }
public GetTraOrderDetailInfoModel GetTraOrderDetailFromAppByOrderId(GetTraOrderDetailInfoQueryModel query) { int orderId = query.OrderId; GetTraOrderDetailInfoModel resultModel = new GetTraOrderDetailInfoModel(); TraOrderEntity traOrderEntity = _traOrderDal.Query <TraOrderEntity>(n => n.OrderId == orderId && n.OrderType == 0, true).FirstOrDefault(); if (traOrderEntity == null) { return(null); } if (!query.IsFromAduitQuery)//不是来自审批人查询 { if (!string.IsNullOrEmpty(query.Customer?.UserID) && query.Customer.UserID.ToLower() != "administrator" && query.Customer.Cid != traOrderEntity.Cid) { return(null); } } if (!string.IsNullOrEmpty(query.Customer?.UserID) && query.Customer.UserID.ToLower() == "administrator") { if ((query.CidList != null && !query.CidList.Contains(traOrderEntity.Cid)) || query.CidList == null) { return(null); } } #region 正单信息 resultModel.OrderId = traOrderEntity.OrderId; resultModel.TraOrder = new GetTraOrderModel() { OrderId = traOrderEntity.OrderId, OrderAmount = traOrderEntity.TotalMoney, TravelList = new List <GetTraOrderTravelModel>(), IsAllowMod = false, IsAllowRet = false, CreateTime = traOrderEntity.CreateTime }; List <TraOrderDetailEntity> traOrderDetailEntities = _traOrderDetailDal.Query <TraOrderDetailEntity>(n => n.OrderId == orderId, true).ToList(); foreach (var traOrderDetailEntity in traOrderDetailEntities) { #region 行程 resultModel.OrderId12306 = traOrderDetailEntity.OrderId12306; GetTraOrderTravelModel travel = new GetTraOrderTravelModel() { OdId = traOrderDetailEntity.OdId, StartName = traOrderDetailEntity.StartName, EndName = traOrderDetailEntity.EndName, StartTime = traOrderDetailEntity.StartTime, EndTime = traOrderDetailEntity.EndTime ?? traOrderDetailEntity.StartTime, TrainNo = traOrderDetailEntity.TrainNo, StartCode = traOrderDetailEntity.StartCode, EndCode = traOrderDetailEntity.EndCode, CorpPolicy = traOrderDetailEntity.CorpPolicy, ChoiceReason = traOrderDetailEntity.ChoiceReason, PassengerList = new List <GetTraOrderPassengerModel>() }; #endregion List <TraPassengerEntity> traPassengerEntities = _traPassengerDal.Query <TraPassengerEntity>(n => n.OdId == traOrderDetailEntity.OdId, true).ToList(); #region 乘客信息 foreach (var traPassengerEntity in traPassengerEntities) { GetTraOrderPassengerModel p = new GetTraOrderPassengerModel() { Pid = traPassengerEntity.Pid, Name = traPassengerEntity.Name, CardNo = traPassengerEntity.CardNo, CardNoType = traPassengerEntity.CardNoType?.ValueToEnum <CardTypeEnum>(), Mobile = traPassengerEntity.Mobile, PlaceCar = traPassengerEntity.PlaceCar, PlaceSeatNo = traPassengerEntity.PlaceSeatNo, PlaceGrade = traPassengerEntity.PlaceGrade, ServiceFee = traPassengerEntity.ServiceFee, FacePrice = traPassengerEntity.FacePrice, AgeType = traPassengerEntity.AgeType.NameToEnum <AgeTypeEnum>() }; //判断当前客户是否已经改签 /* * 正单客户 * 如果已经没有改签就退票了 显示已退票 * 如果有改签,就显示已改签 * **/ List <TraModOrderDetailEntity> traModOrderDetailEntities = (from n in base.Context.Set <TraModOrderDetailEntity>() join mo in base.Context.Set <TraModOrderEntity>().AsNoTracking() on n.CorderId equals mo.CorderId into o from mo in o.DefaultIfEmpty() where n.Pid == p.Pid.ToString() && mo.OrderStatus != "C" && mo.OrderStatus != "N" && mo.OrderId == orderId select n).ToList(); if (traModOrderDetailEntities != null && traModOrderDetailEntities.Count > 0) { #region 判断当前是否是改签中还是已改签 TraModOrderEntity traModOrderEntity = _traModOrderDal.Find <TraModOrderEntity>(traModOrderDetailEntities[0].CorderId ?? 0); if (traModOrderEntity != null && traModOrderEntity.CorderId > 0 && !string.IsNullOrEmpty(traModOrderEntity.OrderStatus) && traModOrderEntity.OrderStatus.ToUpper() != "C") { if (!string.IsNullOrEmpty(traModOrderEntity.ProcessStatus) && traModOrderEntity.ProcessStatus.ToUpper().Contains("H")) { p.PassengerStatus = "已改签"; } else { p.PassengerStatus = "改签中"; } p.TravelRemark = traModOrderEntity.TravelRemark; } #endregion } else { #region 判断是否存在退票,存在的话是已退票还是退票中 //根据订单查询对应的退票单信息(去除改签对应生成的) TraPassengerEntity refundTraPassengerEntity = (from pp in base.Context.Set <TraPassengerEntity>() join detail in base.Context.Set <TraOrderDetailEntity>().AsNoTracking() on pp.OdId equals detail.OdId into d from detail in d.DefaultIfEmpty() join status in base.Context.Set <TraOrderStatusEntity>().AsNoTracking() on detail.OrderId equals status.OrderId into s from status in s.DefaultIfEmpty() join order in base.Context.Set <TraOrderEntity>().AsNoTracking() on detail.OrderId equals order.OrderId into o from order in o.DefaultIfEmpty() where pp.Name == p.Name && pp.CardNo == p.CardNo && pp.Pid != p.Pid && status.IsCancle == 0 && order.OrderRoot == orderId && !order.CorderId.HasValue select pp).FirstOrDefault(); if (refundTraPassengerEntity != null) { //找行程 TraOrderDetailEntity refunTraOrderDetailEntity = _traOrderDetailDal.Find <TraOrderDetailEntity>(refundTraPassengerEntity.OdId); TraOrderStatusEntity traOrderStatusEntity = _traOrderStatusDal.Query <TraOrderStatusEntity>( n => n.OrderId == refunTraOrderDetailEntity.OrderId).FirstOrDefault(); TraOrderEntity traRefundOrderEntity = _traOrderDal.Find <TraOrderEntity>(refunTraOrderDetailEntity.OrderId); if (traOrderStatusEntity != null) { if (traOrderStatusEntity.Status4 == 1) { p.PassengerStatus = "已退票"; } else { p.PassengerStatus = "退票中"; } p.TravelRemark = traRefundOrderEntity.Remark; } } #endregion } travel.PassengerList.Add(p); if (string.IsNullOrEmpty(p.PassengerStatus))//只要有一个状态是空的,就允许退票和改签 { resultModel.TraOrder.IsAllowMod = true; resultModel.TraOrder.IsAllowRet = true; } } #endregion resultModel.TraOrder.TravelList.Add(travel); } #endregion #region 改签信息 List <TraModOrderEntity> traModOrderEntities = _traModOrderDal.Query <TraModOrderEntity>( n => n.OrderId == orderId && !string.IsNullOrEmpty(n.ProcessStatus) && n.ProcessStatus.ToUpper().Contains("H") && !string.IsNullOrEmpty(n.OrderStatus) && n.OrderStatus.ToUpper() != "C" && n.OrderStatus.ToUpper() != "N", true) .ToList(); if (traModOrderEntities != null && traModOrderEntities.Count > 0) { resultModel.TraModOrderList = new List <GetTraModOrderModel>(); foreach (var traModOrderEntity in traModOrderEntities) { #region 改签订单 GetTraModOrderModel traModOrderModel = new GetTraModOrderModel() { CorderId = traModOrderEntity.CorderId, TravelList = new List <GetTraOrderTravelModel>(), IsAllowRet = false }; #endregion List <TraModOrderDetailEntity> traModOrderDetailEntities = _traModOrderDetailDal.Query <TraModOrderDetailEntity>( n => n.CorderId == traModOrderModel.CorderId, true).ToList(); if (traModOrderDetailEntities != null && traModOrderDetailEntities.Count > 0) { #region 改签行程信息 GetTraOrderTravelModel travel = new GetTraOrderTravelModel() { OdId = traModOrderDetailEntities[0].TravelId, StartName = traModOrderDetailEntities[0].AddrName, EndName = traModOrderDetailEntities[0].EndName, StartTime = traModOrderDetailEntities[0].SendTime ?? Convert.ToDateTime("2000-01-01"), EndTime = traModOrderDetailEntities[0].EndTime ?? Convert.ToDateTime("2000-01-01"), TrainNo = traModOrderDetailEntities[0].TrainNo, StartCode = traModOrderDetailEntities[0].StartCode, EndCode = traModOrderDetailEntities[0].EndCode, PassengerList = new List <GetTraOrderPassengerModel>() }; #endregion #region 改签乘客信息 foreach (var traModOrderDetailEntity in traModOrderDetailEntities) { int pid = Convert.ToInt32(traModOrderDetailEntity.Pid); TraPassengerEntity traPassengerEntity = _traPassengerDal.Find <TraPassengerEntity>(pid); GetTraOrderPassengerModel p = new GetTraOrderPassengerModel() { Pid = pid, Name = traPassengerEntity.Name, CardNo = traPassengerEntity.CardNo, CardNoType = traPassengerEntity.CardNoType?.ValueToEnum <CardTypeEnum>(), Mobile = traPassengerEntity.Mobile, PlaceCar = traModOrderDetailEntity.PlaceCar, PlaceSeatNo = traModOrderDetailEntity.PlaceSeatNo, PlaceGrade = traModOrderDetailEntity.PlaceGrade, FacePrice = traModOrderDetailEntity.TrainMoney, AgeType = traPassengerEntity.AgeType.NameToEnum <AgeTypeEnum>(), TravelRemark = traModOrderEntity.TravelRemark }; #region 判断当前乘客是否退票 TraPassengerEntity refundTraPassengerEntity = (from pp in base.Context.Set <TraPassengerEntity>() join detail in base.Context.Set <TraOrderDetailEntity>().AsNoTracking() on pp.OdId equals detail.OdId into d from detail in d.DefaultIfEmpty() join status in base.Context.Set <TraOrderStatusEntity>().AsNoTracking() on detail.OrderId equals status.OrderId into s from status in s.DefaultIfEmpty() join order in base.Context.Set <TraOrderEntity>().AsNoTracking() on detail.OrderId equals order.OrderId into o from order in o.DefaultIfEmpty() where pp.Name == p.Name && pp.CardNo == p.CardNo && pp.Pid != p.Pid && status.IsCancle == 0 && order.OrderRoot == orderId && !order.CorderId.HasValue select pp).FirstOrDefault(); if (refundTraPassengerEntity != null) { //找行程 TraOrderDetailEntity refunTraOrderDetailEntity = _traOrderDetailDal.Find <TraOrderDetailEntity>(refundTraPassengerEntity.OdId); TraOrderStatusEntity traOrderStatusEntity = _traOrderStatusDal.Query <TraOrderStatusEntity>( n => n.OrderId == refunTraOrderDetailEntity.OrderId).FirstOrDefault(); TraOrderEntity traRefundOrderEntity = _traOrderDal.Find <TraOrderEntity>(refunTraOrderDetailEntity.OrderId); if (traOrderStatusEntity != null) { if (traOrderStatusEntity.Status4 == 1) { p.PassengerStatus = "已退票"; } else { p.PassengerStatus = "退票中"; } p.TravelRemark = traRefundOrderEntity.Remark; } } #endregion travel.PassengerList.Add(p); if (string.IsNullOrEmpty(p.PassengerStatus))//只要有一个状态是空的,就允许退票 { traModOrderModel.IsAllowRet = true; } } #endregion traModOrderModel.TravelList.Add(travel); } resultModel.TraModOrderList.Add(traModOrderModel); } } #endregion #region 计算金额 resultModel.TotalOrderAmount = traOrderEntity.TotalMoney; //获取当前订单对应的退票单信息(除去改签生成的对应) List <TraOrderEntity> refundOrderEntities = (from o in base.Context.Set <TraOrderEntity>() join status in base.Context.Set <TraOrderStatusEntity>().AsNoTracking() on o.OrderId equals status.OrderId into s from status in s.DefaultIfEmpty() where o.OrderRoot == orderId && !o.CorderId.HasValue && o.OrderType == 2 && status.Status4 == 1 && status.IsCancle == 0 select o).ToList(); if (refundOrderEntities != null && refundOrderEntities.Count > 0) { resultModel.RefundAmount = resultModel.RefundAmount + refundOrderEntities.Sum(n => n.TotalMoney); } /*判断当前改签是 低改高 还是高改低 * 低改高 算入改签差价 * 高改低 算入退款金额 * **/ if (traModOrderEntities != null && traModOrderEntities.Count > 0) { foreach (var traModOrderEntity in traModOrderEntities) { TraOrderEntity modRefTraOrderEntity = _traOrderDal.Query <TraOrderEntity>( n => n.OrderRoot == orderId && n.CorderId.HasValue && n.OrderType == 2, true).FirstOrDefault();//改签对应的退票信息 if (modRefTraOrderEntity != null) { decimal money = (traModOrderEntity.PayAmount ?? 0) + modRefTraOrderEntity.TotalMoney; // modRefTraOrderEntity.TotalMoney为负数 //低改高 收钱 if (money >= 0) { resultModel.TotalModAmount = resultModel.TotalModAmount + money; } else { //高改低 退钱 resultModel.RefundAmount = resultModel.RefundAmount + money; } } } } #endregion TraOrderStatusEntity orderStatus = _traOrderStatusDal.Query <TraOrderStatusEntity>(n => n.OrderId == orderId, true).FirstOrDefault(); resultModel.ShowOnlineOrderId = (traOrderEntity.CopyType == "X" && traOrderEntity.CopyFromOrderId.HasValue && orderStatus != null && (orderStatus.ProccessStatus & 1) == 1 && orderStatus.IsCancle != 1) ? traOrderEntity.CopyFromOrderId.Value : traOrderEntity.OrderId; return(resultModel); }
public int CopyOrder(CopyTraOrderModel copyTraOrderModel) { //原始订单 TraOrderEntity copyTraOrderEntity = _traOrderDal.Find <TraOrderEntity>(copyTraOrderModel.CopyFromOrderId); if (copyTraOrderEntity == null) { throw new Exception("复制来源订单异常"); } if (copyTraOrderModel.CopyType == "X") { TraOrderEntity copyTraRefundOrderEntity = _traOrderDal.Query <TraOrderEntity>( n => n.OrderRoot == copyTraOrderEntity.OrderId && n.OrderType == 2 && n.RefundType == 1, true).FirstOrDefault(); if (copyTraRefundOrderEntity == null) { throw new Exception("不是虚退订单,不能虚退复制"); } } //原始订单行程信息 List <TraOrderDetailEntity> copyTraOrderDetailEntities = _traOrderDetailDal.Query <TraOrderDetailEntity>(n => n.OrderId == copyTraOrderModel.CopyFromOrderId, true) .ToList(); //原始订单乘车人信息 List <int> copyPidList = copyTraOrderModel.PassengerList.Select(n => n.Pid).ToList(); List <TraPassengerEntity> copyTraPassengerEntities = _traPassengerDal.Query <TraPassengerEntity>(n => copyPidList.Contains(n.Pid)).ToList(); //原始订单信息映射复制新实体 TraOrderEntity traOrderEntity = Mapper.Map <TraOrderEntity, TraOrderEntity>(copyTraOrderEntity); List <TraOrderDetailEntity> traOrderDetailEntities = Mapper.Map <List <TraOrderDetailEntity>, List <TraOrderDetailEntity> >(copyTraOrderDetailEntities); List <TraPassengerEntity> traPassengerEntities = Mapper.Map <List <TraPassengerEntity>, List <TraPassengerEntity> >(copyTraPassengerEntities); //复制新实体 新增订单 traOrderEntity.CreateOid = copyTraOrderModel.CreateOid; traOrderEntity.CopyType = copyTraOrderModel.CopyType; traOrderEntity.PayAmount = copyTraOrderModel.PayAmount; traOrderEntity.TotalMoney = copyTraOrderModel.PayAmount; traOrderEntity.PrintProcurementTime = null; traOrderEntity.IsNeedPrintTime = null; if (traOrderEntity.CopyType != "X")//不是虚退复制 { traOrderEntity.CreateTime = DateTime.Now; traOrderEntity.CopyFromOrderId = copyTraOrderModel.CopyFromOrderId; } else { if (string.IsNullOrEmpty(copyTraOrderEntity.CopyType)) { traOrderEntity.CopyFromOrderId = copyTraOrderModel.CopyFromOrderId; } else { //如果当前原始订单是虚退复制的,那么它的虚退复制订单的马甲订单号继承原始订单的马甲订单号 if (copyTraOrderEntity.CopyType == "X" && copyTraOrderEntity.CopyFromOrderId.HasValue) { traOrderEntity.CopyFromOrderId = copyTraOrderEntity.CopyFromOrderId; } else { traOrderEntity.CopyFromOrderId = copyTraOrderModel.CopyFromOrderId; } } } traOrderEntity = _traOrderDal.Insert(traOrderEntity); TraOrderStatusEntity orderStatusEntity = new TraOrderStatusEntity(); orderStatusEntity.OrderId = traOrderEntity.OrderId; orderStatusEntity.ProccessStatus = 64;//设置处理中 _traOrderStatusDal.Insert(orderStatusEntity); foreach (var detail in traOrderDetailEntities) { detail.OrderId = traOrderEntity.OrderId; List <TraPassengerEntity> thisTravelPassengerList = traPassengerEntities.FindAll(n => n.OdId == detail.OdId); detail.ServiceFee = thisTravelPassengerList.Sum(n => (n.ServiceFee ?? 0)) / thisTravelPassengerList.Count; detail.FacePrice = thisTravelPassengerList.Sum(n => (n.FacePrice ?? 0)) / thisTravelPassengerList.Count; detail.TotalPrice = (detail.ServiceFee + detail.FacePrice) * (detail.TicketNum ?? 0); TraOrderDetailEntity traOrderDetailEntity = _traOrderDetailDal.Insert(detail); foreach (var p in traPassengerEntities) { p.OdId = traOrderDetailEntity.OdId; _traPassengerDal.Insert(p); } } _traOrderLogDal.Insert <TraOrderLogEntity>(new TraOrderLogEntity() { OrderId = traOrderEntity.OrderId, CreateOid = traOrderEntity.CreateOid, CreateTime = DateTime.Now, LogType = "OI", LogContent = "复制订单,来源订单号:" + copyTraOrderModel.CopyFromOrderId + ",马甲订单号:" + traOrderEntity.CopyFromOrderId }); //将原始订单设置为线上隐藏 if (copyTraOrderModel.CopyType == "X") { copyTraOrderEntity.IsOnlineShow = 1; _traOrderDal.Update(copyTraOrderEntity, new string[] { "IsOnlineShow" }); } return(traOrderEntity.OrderId); }
/// <summary> /// 获取抢票异步成功通知,并做处理 /// 则自动生成火车订单,通知抢票发起者 /// </summary> public void GetGrabTicketSuccessNotice(GrabTicketSuccessedDataAsyncResponseModel successedData) { int orderid = Convert.ToInt32(successedData.orderid); #region 1.更新抢票信息状态 TraGrabTicketEntity traGrabTicketEntity = _traGrabTicketDal.Query <TraGrabTicketEntity>(n => n.OrderId == orderid).FirstOrDefault(); if (traGrabTicketEntity == null) { throw new Exception("未找到对应的系统订单"); } traGrabTicketEntity.GrabStatus = TrainGrabStatusEnum.S.ToString(); _traGrabTicketDal.Update(traGrabTicketEntity, new string[] { "GrabStatus" }); #endregion #region 2.1 根据订单获取预设订单信息 TraOrderEntity traOrderEntity = _traOrderDal.Find <TraOrderEntity>(orderid); if (traOrderEntity == null) { throw new Exception("订单信息异常"); } if (traOrderEntity.OrderType == 0) { throw new Exception("该订单已经回调"); } TraOrderDetailEntity traOrderDetailEntity = _traOrderDetailDal.Query <TraOrderDetailEntity>(n => n.OrderId == traOrderEntity.OrderId) .FirstOrDefault(); if (traOrderDetailEntity == null) { throw new Exception("订单信息异常"); } TraOrderStatusEntity traOrderStatusEntity = _traOrderStatusDal.Query <TraOrderStatusEntity>(n => n.OrderId == traOrderEntity.OrderId) .FirstOrDefault(); if (traOrderStatusEntity == null) { throw new Exception("订单信息异常"); } List <TraPassengerEntity> traPassengerEntities = _traPassengerDal.Query <TraPassengerEntity>(n => n.OdId == traOrderDetailEntity.OdId).ToList(); if (traPassengerEntities.Count == 0) { throw new Exception("订单信息异常"); } #endregion #region 2.2根据返回结果,更新预设订单信息 traOrderEntity.TransactionId = successedData.transactionid; traOrderEntity.OrderType = 0; if (successedData.refund_online == "1") { traOrderEntity.IsRefundBy12306 = false; } else { traOrderEntity.IsRefundBy12306 = true; } traOrderDetailEntity.OrderId12306 = successedData.ordernumber; traOrderDetailEntity.StartName = successedData.from_station_name; traOrderDetailEntity.StartCode = successedData.from_station_code; traOrderDetailEntity.StartTime = Convert.ToDateTime(successedData.start_time); TraAddressEntity startAddressEntity = _traAddressDal.Query <TraAddressEntity>(n => n.Addr_Name == traOrderDetailEntity.StartName) .FirstOrDefault(); if (startAddressEntity != null) { traOrderDetailEntity.StartNameId = startAddressEntity.Aid; } traOrderDetailEntity.EndName = successedData.to_station_name; traOrderDetailEntity.EndCode = successedData.to_station_code; traOrderDetailEntity.EndTime = Convert.ToDateTime(successedData.arrive_time); TraAddressEntity endAddressEntity = _traAddressDal.Query <TraAddressEntity>(n => n.Addr_Name == traOrderDetailEntity.EndName) .FirstOrDefault(); if (endAddressEntity != null) { traOrderDetailEntity.EndNameId = endAddressEntity.Aid; } traOrderDetailEntity.TrainNo = successedData.checi; traOrderDetailEntity.FacePrice = Convert.ToDecimal(successedData.orderamount) / 2; traOrderDetailEntity.TotalPrice = traOrderDetailEntity.FacePrice + traOrderDetailEntity.ServiceFee; foreach (TraPassengerEntity traPassengerEntity in traPassengerEntities) { GrabTicketSuccessedPassengerAsyncResponseModel grabTicketPassenger = successedData.passengers.Find( n => n.passengersename == traPassengerEntity.Name && n.passportseno == traPassengerEntity.CardNo); traPassengerEntity.FacePrice = Convert.ToDecimal(grabTicketPassenger.price); List <string> cxinList = grabTicketPassenger.cxin.Split(',').ToList(); if (cxinList.Count == 2) { traPassengerEntity.PlaceCar = cxinList[0]; traPassengerEntity.PlaceSeatNo = cxinList[1]; } traPassengerEntity.PlaceGrade = grabTicketPassenger.zwname; traPassengerEntity.TicketNo = grabTicketPassenger.ticket_no; _traPassengerDal.Update(traPassengerEntity, new string[] { "FacePrice", "PlaceCar", "PlaceSeatNo", "PlaceGrade", "TicketNo" }); } traOrderEntity.TotalMoney = traPassengerEntities.Sum(n => (n.ServiceFee ?? 0) + (n.FacePrice ?? 0)); traOrderEntity.PayAmount = traOrderEntity.TotalMoney; traOrderStatusEntity.IsBuy = 1; traOrderStatusEntity.ProccessStatus = traOrderStatusEntity.ProccessStatus + 1 + 8 + 64; //已付款,已预定 traOrderStatusEntity.RealPayOid = "sys"; traOrderStatusEntity.RealPayDatetime = DateTime.Now; //更新订单 _traOrderDal.Update(traOrderEntity, new string[] { "TransactionId", "IsRefundBy12306", "TotalMoney", "PayAmount", "OrderType" }); //更新行程 _traOrderDetailDal.Update(traOrderDetailEntity, new string[] { "OrderId12306", "StartName", "StartCode", "StartTime", "EndName", "EndCode", "EndTime", "TrainNo", "FacePrice", "TotalPrice" }); //更新订单状态 _traOrderStatusDal.Update(traOrderStatusEntity, new[] { "IsBuy", "ProccessStatus", "RealPayOid", "RealPayDatetime" }); #endregion #region 2.3 设置付款信息,并记录日志 PaySupplierEvent?.Invoke(this, new CommonEventArgs <AccountDetailModel>(new AccountDetailModel() { Aid = 81, Amount = traPassengerEntities.Sum(n => (n.FacePrice ?? 0)) + 5, //抢票订单+5块 Detailtype = "火车票付票款", Oid = "sys", CreateTime = DateTime.Now, Source = "火车票付票款", OrderId = traOrderEntity.OrderId, OrderType = "Tra", Provider = 0, CollectionRemark = "", EstimateId = 0 })); _traOrderLogDal.Insert(new TraOrderLogEntity() { OrderId = traOrderEntity.OrderId, CreateOid = "sys", CreateTime = DateTime.Now, LogContent = "抢票出票回调,自动勾已预定、已付票款、已采购", LogType = "修改" }); #endregion #region 2.3插入Tra_InterFaceOrder表,以便退改签流程 TraInterFaceOrderEntity traInterFaceOrderEntity = _traInterFaceOrderDal.Insert <TraInterFaceOrderEntity>(new TraInterFaceOrderEntity() { OrderId = traOrderEntity.OrderId.ToString(), CreateTime = DateTime.Now, Status = (int)OrderTypeEnum.TicketSuccess, Transactionid = traOrderEntity.TransactionId, OrderNumber = traOrderDetailEntity.OrderId12306 }); _traOrderOperateDal.Insert(new TraOrderOperateEntity() { InterfaceId = traInterFaceOrderEntity.InterfaceId, AfterOperateStatus = (int)OrderTypeEnum.TicketSuccess, BeforOperateStatus = 0, OperateTime = DateTime.Now }); #endregion }