internal static BaseBunk CreateBunk(string airline, string bunkCode, Common.Enums.BunkType bunkType, string departure, string arrival, DateTime flightDate, PassengerType passengerType, PolicyMatch.MatchedPolicy policy, decimal ybPrice, decimal?patFare) { if (string.IsNullOrWhiteSpace(bunkCode) && policy.PolicyType != PolicyType.Special) { throw new CustomException("缺少舱位代码"); } if (passengerType == PassengerType.Child) { return(CreateChildrenBunk(airline, bunkCode, departure, arrival, flightDate, policy, ybPrice, patFare)); } else { var bunks = FoundationService.QueryBunk(airline, departure, arrival, flightDate, bunkCode); //更改EI项 var pattern = new Regex("^[a-zA-Z\\d/]+$"); var details = FoundationService.QueryDetailList(airline, bunkCode).Where(item => pattern.IsMatch(item.Bunks)); string refundRegulation = string.Empty; string changeRegulation = string.Empty; string endorseRegulation = string.Empty; foreach (var item in details) { refundRegulation += ("航班起飞前:" + item.ScrapBefore + ";航班起飞后:" + item.ScrapAfter).Replace("<br/>", "").Replace("\r", "").Replace("\n", "").Replace("\t", ""); changeRegulation += ("航班起飞前:" + item.ChangeBefore + ";航班起飞后:" + item.ChangeAfter).Replace("<br/>", "").Replace("\r", "").Replace("\n", "").Replace("\t", ""); endorseRegulation += item.Endorse.Replace("<br/>", "").Replace("\r", "").Replace("\n", "").Replace("\t", ""); } if (string.IsNullOrWhiteSpace(refundRegulation)) { refundRegulation = "以航司具体规定为准"; } if (string.IsNullOrWhiteSpace(changeRegulation)) { changeRegulation = "以航司具体规定为准"; } foreach (var item in bunks) { item.ChangeRegulation = changeRegulation; item.EndorseRegulation = endorseRegulation; item.RefundRegulation = refundRegulation; } if (policy.PolicyType == PolicyType.Special) { return(CreateSpecialBunk(bunks, bunkCode, bunkType, policy.OriginalPolicy as DataTransferObject.Policy.SpecialPolicyInfo, ybPrice, policy.RelationType)); } else if (policy.PolicyType == PolicyType.Normal) { return(CreateGeneralBunk(bunks, bunkCode)); } else if (policy.PolicyType == PolicyType.Bargain) { var promotionPolicy = policy.OriginalPolicy as DataTransferObject.Policy.BargainPolicyInfo; if (bunkType == Common.Enums.BunkType.Production) { var fare = promotionPolicy.Price > 0 ? promotionPolicy.Price / 2 : (patFare.HasValue ? patFare.Value : 0); return(CreateProductionBunk(bunks, bunkCode, promotionPolicy, fare)); } else if (bunkType == Common.Enums.BunkType.Transfer) { if (!patFare.HasValue) { throw new CustomException("缺少价格信息"); } return(CreateTransferBunk(bunks, bunkCode, patFare.Value)); } else { return(CreatePromotionBunk(bunks, bunkCode, promotionPolicy, patFare)); } } else if (policy.PolicyType == PolicyType.Team) { switch (bunkType) { case Common.Enums.BunkType.Economic: case Common.Enums.BunkType.FirstOrBusiness: return(CreateGeneralBunk(bunks, bunkCode)); case Common.Enums.BunkType.Team: if (!patFare.HasValue) { throw new CustomException("缺少价格信息"); } return(CreateTeamBunk(bunks, bunkCode, patFare.Value)); case Common.Enums.BunkType.Promotion: if (!patFare.HasValue) { throw new CustomException("缺少价格信息"); } return(CreatePromotionBunk(bunks, bunkCode, null, patFare)); case Common.Enums.BunkType.Production: if (!patFare.HasValue) { throw new CustomException("缺少价格信息"); } return(CreateProductionBunk(bunks, bunkCode, null, patFare.Value)); case Common.Enums.BunkType.Transfer: if (!patFare.HasValue) { throw new CustomException("缺少价格信息"); } return(CreateTransferBunk(bunks, bunkCode, patFare.Value)); default: throw new CustomException("团队政策仅支持普通、特价、联程和团队舱位"); } } else if (policy.PolicyType == PolicyType.NormalDefault) { switch (bunkType) { case Common.Enums.BunkType.Economic: case Common.Enums.BunkType.FirstOrBusiness: return(CreateGeneralBunk(bunks, bunkCode)); case Common.Enums.BunkType.Team: if (!patFare.HasValue) { throw new CustomException("缺少价格信息"); } return(CreateTeamBunk(bunks, bunkCode, patFare.Value)); default: throw new CustomException("普通默认政策仅支持普通舱位、团队舱位"); } } else if (policy.PolicyType == PolicyType.BargainDefault) { if (!patFare.HasValue) { throw new CustomException("缺少价格信息"); } switch (bunkType) { case Common.Enums.BunkType.Economic: case Common.Enums.BunkType.FirstOrBusiness: return(CreateGeneralBunk(bunks, bunkCode)); case Common.Enums.BunkType.Promotion: return(CreatePromotionBunk(bunks, bunkCode, null, patFare)); case Common.Enums.BunkType.Production: return(CreateProductionBunk(bunks, bunkCode, null, patFare.Value)); case Common.Enums.BunkType.Transfer: return(CreateTransferBunk(bunks, bunkCode, patFare.Value)); default: throw new CustomException("特价默认政策仅支持特价舱位、往返产品舱和中转或多段联程舱"); } } else if (policy.PolicyType == PolicyType.OwnerDefault) { switch (bunkType) { case Common.Enums.BunkType.Economic: case Common.Enums.BunkType.FirstOrBusiness: return(CreateGeneralBunk(bunks, bunkCode)); case Common.Enums.BunkType.Promotion: if (!patFare.HasValue) { throw new CustomException("缺少价格信息"); } return(CreatePromotionBunk(bunks, bunkCode, null, patFare)); case Common.Enums.BunkType.Production: if (!patFare.HasValue) { throw new CustomException("缺少价格信息"); } return(CreateProductionBunk(bunks, bunkCode, null, patFare.Value)); case Common.Enums.BunkType.Transfer: if (!patFare.HasValue) { throw new CustomException("缺少价格信息"); } return(CreateTransferBunk(bunks, bunkCode, patFare.Value)); case Common.Enums.BunkType.Team: if (!patFare.HasValue) { throw new CustomException("缺少价格信息"); } return(CreateTeamBunk(bunks, bunkCode, patFare.Value)); default: throw new CustomException("默认政策仅支持普通舱位、团队舱位、特价舱位、往返产品舱和中转或多段联程舱"); } } throw new NotSupportedException("未知政策类型"); } }
private static SpecialBunk CreateSpecialBunk(IEnumerable <Foundation.Domain.Bunk> bunks, string bunkCode, Common.Enums.BunkType bunkType, DataTransferObject.Policy.SpecialPolicyInfo policy, decimal ybPrice, RelationType relation) { decimal discount = 0; if (policy.Type == SpecialProductType.CostFree) { var ei = string.Empty; var description = string.Empty; var code = string.Empty; if (policy.SynBlackScreen) { var freeBunk = bunks.FirstOrDefault(b => b is Foundation.Domain.FreeBunk && b.Code.Value == bunkCode); code = freeBunk == null ? string.Empty : freeBunk.Code.Value; ei = freeBunk == null ? string.Empty : freeBunk.EI; description = freeBunk == null ? string.Empty : (freeBunk as Foundation.Domain.FreeBunk).Description; } var settleAmount = PolicyMatch.Domain.Calculator.ComputeSpecialSettlementPrice(policy, ybPrice, discount, PolicyMatch.Domain.Calculator.GetDeductionType(relation)); return(new FreeBunk(code, settleAmount, ei, description)); } else if (policy.Type == SpecialProductType.Business || policy.Type == SpecialProductType.Bloc) { if (bunkType == Common.Enums.BunkType.Economic || bunkType == Common.Enums.BunkType.FirstOrBusiness) { var generalBunk = CreateGeneralBunk(bunks, bunkCode); generalBunk.SetYBPrice(ybPrice); var fare = PolicyMatch.Domain.Calculator.ComputeSpecialParValue(policy, ybPrice, generalBunk.Discount, PolicyMatch.Domain.Calculator.GetDeductionType(relation)); var releasedFare = PolicyMatch.Domain.Calculator.ComputeSpecialSettlementPrice(policy, ybPrice, generalBunk.Discount, PolicyMatch.Domain.Calculator.GetDeductionType(relation)); generalBunk.ReviseFare(fare); return(new SpecialBunk(bunkCode, generalBunk.Discount, generalBunk.Fare, releasedFare, generalBunk.EI)); } else if (bunkType == Common.Enums.BunkType.Promotion) { var fare = PolicyMatch.Domain.Calculator.ComputeSpecialParValue(policy, ybPrice, discount, PolicyMatch.Domain.Calculator.GetDeductionType(relation)); var promotionBunk = CreatePromotionBunk(bunks, bunkCode, null, fare); promotionBunk.SetYBPrice(ybPrice); var releasedFare = PolicyMatch.Domain.Calculator.ComputeSpecialSettlementPrice(policy, ybPrice, discount, PolicyMatch.Domain.Calculator.GetDeductionType(relation)); return(new SpecialBunk(bunkCode, promotionBunk.Discount, promotionBunk.Fare, releasedFare, promotionBunk.EI)); } else { throw new CustomException("集团票和商旅卡仅支持普通舱和特价舱"); } } else if (policy.Type == SpecialProductType.LowToHigh) { var bunk = bunks.First(); if (bunk.Type == Common.Enums.BunkType.FirstOrBusiness || bunk.Type == Common.Enums.BunkType.Economic) { var generalBunk = CreateGeneralBunk(bunks, bunkCode); generalBunk.SetYBPrice(ybPrice); discount = generalBunk.Discount; return(new SpecialBunk(bunk.Code.Value, discount, ybPrice, ybPrice * discount, string.Empty));//TODO 暂不确定的这里的退改签规定是否需要构造 } else { throw new CustomException("低打高返政策仅支持普通舱位"); } } var releasedSettleAmount = PolicyMatch.Domain.Calculator.ComputeSpecialSettlementPrice(policy, ybPrice, discount, PolicyMatch.Domain.Calculator.GetDeductionType(relation)); return(new SpecialBunk(releasedSettleAmount)); }