private int AddOrder(List <TraPassengerEntity> pList1, List <TraOrderDetailEntity> tList1, TraOrderEntity order1, string oid) { List <TraOrderDetailEntity> tList = Mapper.Map <List <TraOrderDetailEntity>, List <TraOrderDetailEntity> >(tList1); List <TraPassengerEntity> pList = Mapper.Map <List <TraPassengerEntity>, List <TraPassengerEntity> >(pList1); TraOrderEntity order = Mapper.Map <TraOrderEntity, TraOrderEntity>(order1); //重新计算订单金额,创建人重新赋值,创建时间重新赋值。。。。,一些时间置NULL order.CreateOid = oid; order.PayAmount = pList.Sum(n => (n.ServiceFee ?? 0) + (n.FacePrice ?? 0)); order.TotalMoney = order.PayAmount ?? 0; order.PrintProcurementTime = null; order.CreateTime = DateTime.Now; order.IsNeedPrintTime = null; //插入订单信息 TraOrderEntity newOrder = _traOrderDal.Insert(order); //插入订单状态信息 TraOrderStatusEntity orderStatusEntity = new TraOrderStatusEntity(); orderStatusEntity.OrderId = newOrder.OrderId; orderStatusEntity.ProccessStatus = 64;//设置处理中 _traOrderStatusDal.Insert(orderStatusEntity); foreach (var detail in tList) { detail.OrderId = newOrder.OrderId; //查询行程表中OdId关联旅客表的旅客信息 TraPassengerEntity Passengers = pList.Find(n => n.OdId == detail.OdId); //修改原订单中的价格赋值在行程表 detail.ServiceFee = Passengers.ServiceFee ?? 0; detail.FacePrice = Passengers.FacePrice ?? 0; detail.TicketNum = 1; detail.TotalPrice = (detail.ServiceFee + detail.FacePrice); //插入行程信息 TraOrderDetailEntity traOrderDetailEntity = _traOrderDetailDal.Insert(detail); //乘客信息 Passengers.OdId = traOrderDetailEntity.OdId; _traPassengerDal.Insert(Passengers); } _traOrderLogDal.Insert <TraOrderLogEntity>(new TraOrderLogEntity() { OrderId = newOrder.OrderId, CreateOid = newOrder.CreateOid, CreateTime = DateTime.Now, LogType = "OI", LogContent = "拆分订单,来源订单号:" + order1.OrderId, }); return(newOrder.OrderId); }
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); }
public int AddTraOrder(TraAddOrderModel newOrder) { newOrder.Order.TrainPlace = "代售点"; newOrder.Order.OrderRoot = 0; newOrder.Order.CreateTime = DateTime.Now; if (newOrder.Order.PayAmount == 0) { newOrder.Order.PayAmount = newOrder.Order.TotalMoney; } newOrder.Order.OpeartorId = newOrder.Order.CreateOid; newOrder.Order.OrderSource = newOrder.OrderSource; if (newOrder.AddOrderType == 1)//手动 { newOrder.Order.OrderType = 0; } else { newOrder.Order.OrderType = 1; } if (newOrder.Customer != null && !string.IsNullOrEmpty(newOrder.Customer.Category) && newOrder.Customer.Category.ToUpper() == "D") { newOrder.Order.BalanceType = 1; newOrder.Order.TravelType = 0; } else { newOrder.Order.BalanceType = 0; newOrder.Order.TravelType = 1; } //如果存在项目名称 if (newOrder.ProjectName != null && newOrder.ProjectName.ProjectId > 0) { newOrder.Order.ProjectId = newOrder.ProjectName.ProjectId; } if (newOrder.CostCenter != null && newOrder.CostCenter.Cid > 0) { newOrder.Order.CostCenter = newOrder.CostCenter.Depart; } if (string.IsNullOrEmpty(newOrder.Order.CostCenter)) { newOrder.Order.CostCenter = ""; } if (newOrder.AddOrderType == 0) { newOrder.Order.OrderFrom = TraOrderFromEnum.Interface.ToString(); } else { newOrder.Order.OrderFrom = TraOrderFromEnum.Hand.ToString(); } if (newOrder.Order.OrderSource == "O") { newOrder.Order.IsOnline = "F"; } else { newOrder.Order.IsOnline = "T"; } TraOrderEntity orderEntity = Mapper.Map <TraOrderModel, TraOrderEntity>(newOrder.Order); orderEntity.CorpPolicy = string.Empty; orderEntity.ChoiceReason = string.Empty; foreach (var traOrderDetailModel in newOrder.OrderDetailList) { if (!string.IsNullOrEmpty(traOrderDetailModel.CorpPolicy)) { orderEntity.CorpPolicy += "|" + traOrderDetailModel.CorpPolicy; } if (!string.IsNullOrEmpty(traOrderDetailModel.ChoiceReason)) { orderEntity.ChoiceReason += "|" + traOrderDetailModel.ChoiceReason; } } orderEntity = _traOrderDal.Insert(orderEntity); if (newOrder.OrderStatus == null) { newOrder.OrderStatus = new TraOrderStatusModel(); } newOrder.OrderStatus.OrderId = orderEntity.OrderId; if (newOrder.Order.CreateOid != "sys" && (newOrder.OrderStatus.ProccessStatus & 64) != 64) { newOrder.OrderStatus.ProccessStatus = newOrder.OrderStatus.ProccessStatus + 64; } TraOrderStatusEntity orderStatusEntity = Mapper.Map <TraOrderStatusModel, TraOrderStatusEntity>(newOrder.OrderStatus); orderStatusEntity = _traOrderStatusDal.Insert(orderStatusEntity); foreach (var detail in newOrder.OrderDetailList) { detail.OrderId = orderEntity.OrderId; detail.TicketNum = detail.PassengerList.Count; detail.TotalPrice = detail.PassengerList.Sum(n => (n.FacePrice ?? 0)) + detail.PassengerList.Sum(n => (n.ServiceFee ?? 0));//乘客面价+乘客服务费 detail.ServiceFee = (detail.PassengerList?[0].ServiceFee ?? 0); var childPerson = detail.PassengerList.Find(n => n.AgeType == AgeTypeEnum.E); //儿童 var person = detail.PassengerList.Find(n => n.AgeType == AgeTypeEnum.C); //成人 detail.FacePrice = (person?.FacePrice ?? 0); detail.TrainChdSalePrice = (childPerson?.FacePrice ?? 0); detail.PlaceGrade = detail.PassengerList?[0].PlaceGrade; detail.PlaceType = GetPlaceType(detail.PlaceGrade); detail.TrainNoRemark = string.IsNullOrEmpty(detail.TrainNoRemark) ? "" : detail.TrainNoRemark; detail.TrainNoStatus = string.IsNullOrEmpty(detail.TrainNoStatus) ? "" : detail.TrainNoStatus; detail.OnTrainTimeTemp = detail.StartTime; detail.OnTrainTime = detail.StartTime; TraAddressEntity startAddressEntity = _traAddressDal.Query <TraAddressEntity>(n => n.Addr_Name == detail.StartName).FirstOrDefault(); if (startAddressEntity == null) { startAddressEntity = new TraAddressEntity(); startAddressEntity.Addr_Name = detail.StartName; startAddressEntity.Addr_Type = 0; startAddressEntity.Addr_S = detail.StartCode; startAddressEntity = _traAddressDal.Insert <TraAddressEntity>(startAddressEntity); } detail.StartNameId = startAddressEntity.Aid; TraAddressEntity endAddressEntity = _traAddressDal.Query <TraAddressEntity>(n => n.Addr_Name == detail.EndName) .FirstOrDefault(); if (endAddressEntity == null) { endAddressEntity = new TraAddressEntity(); endAddressEntity.Addr_Name = detail.EndName; endAddressEntity.Addr_Type = 0; endAddressEntity.Addr_S = detail.EndCode; endAddressEntity = _traAddressDal.Insert <TraAddressEntity>(endAddressEntity); } detail.EndNameId = endAddressEntity.Aid; TraOrderDetailEntity traOrderDetailEntity = Mapper.Map <TraOrderDetailModel, TraOrderDetailEntity>(detail); traOrderDetailEntity = _traOrderDetailDal.Insert(traOrderDetailEntity); foreach (var p in detail.PassengerList) { p.OdId = traOrderDetailEntity.OdId; TraPassengerEntity traPassengerEntity = Mapper.Map <TraPassengerModel, TraPassengerEntity>(p); traPassengerEntity.Name = traPassengerEntity.Name.Replace("/", " "); _traPassengerDal.Insert(traPassengerEntity); } } string logContent = newOrder.Log?.LogContent; if (string.IsNullOrEmpty(logContent)) { logContent = $"{(newOrder.Order.IsOnline == "T" ? "线上" : "线下")}添加火车订单"; } _traOrderLogDal.Insert <TraOrderLogEntity>(new TraOrderLogEntity() { OrderId = orderEntity.OrderId, CreateOid = orderEntity.CreateOid, CreateTime = DateTime.Now, LogType = "OI", LogContent = logContent }); return(orderEntity.OrderId); }