/// <summary> /// 匹配出票方 /// </summary> internal void MatchProvider(PolicyMatch.MatchedPolicy policy) { if (this.IsSpecial) { if (this.Status == OrderStatus.Ordered || this.Status == OrderStatus.PaidForETDZ) { if (this.IsThirdRelation) { var deduction = Deduction.GetDeduction(policy); var product = ProductInfo.GetProductInfo(policy); this.Supplier.Rebate = deduction.Purchaser; this.Provider = getProvider(policy, product); if (policy.PolicyType == PolicyType.BargainDefault || policy.PolicyType == PolicyType.NormalDefault) { this.Provider.Product.IsDefaultPolicy = true; } CustomNo = policy.OriginalPolicy == null ? string.Empty : policy.OriginalPolicy.CustomCode; return; } throw new CustomException("资源方具有出票资质,不能选择其他出票方出票"); } throw new StatusException(this.Id.ToString()); } throw new CustomException("特殊票才需要匹配出票方出票"); }
internal static bool IsStandby(PolicyMatch.MatchedPolicy policy) { if (policy.PolicyType == PolicyType.Special) { var specialPolicy = policy.OriginalPolicy as SpecialPolicyInfo; return(specialPolicy.Type == SpecialProductType.CostFree && !specialPolicy.IsSeat); } return(false); }
internal static ExternalOrder NewExternalOrder(OrderView orderView, PolicyMatch.MatchedPolicy matchedPolicy, DataTransferObject.Organization.EmployeeDetailInfo employee, AuthenticationChoise choise = AuthenticationChoise.NoNeedAUTH) { if (!orderView.Flights.Any()) { throw new ArgumentNullException("orderView", "缺少航段信息"); } if (!orderView.Passengers.Any()) { throw new ArgumentNullException("orderView", "缺少乘机人信息"); } if (matchedPolicy == null) { throw new CustomException("无相关政策信息"); } #region 构造BASE var result = new ExternalOrder { Contact = orderView.Contact, ReservationPNR = PNRPair.IsNullOrEmpty(orderView.PNR) ? null : orderView.PNR, IsReduce = orderView.IsReduce, IsTeam = orderView.IsTeam, AssociateOrderId = orderView.AssociateOrderId, AssociatePNR = orderView.AssociatePNR, Source = orderView.Source, Choise = choise, CustomNo = matchedPolicy.OriginalPolicy == null ? string.Empty : matchedPolicy.OriginalPolicy.CustomCode, VisibleRole = OrderRole.Platform | OrderRole.Purchaser, ForbidChangPNR = false, NeedAUTH = matchedPolicy.OriginalPolicy == null ? matchedPolicy.NeedAUTH : matchedPolicy.OriginalPolicy.NeedAUTH }; var deduction = Deduction.GetDeduction(matchedPolicy); var product = ProductInfo.GetProductInfo(matchedPolicy); var specialProduct = product as SpeicalProductInfo; if (specialProduct != null && !hasETDZPermission(matchedPolicy.Provider, specialProduct)) { result.Supplier = getSupplierInfo(matchedPolicy, specialProduct); } else { result.Provider = getProvider(matchedPolicy, product); } result.IsCustomerResource = ProductInfo.IsCustomerResource(matchedPolicy); result.IsStandby = ProductInfo.IsStandby(matchedPolicy); result.Purchaser = getPurchaserInfo(employee, deduction); var pnrInfo = PNRInfo.GetPNRInfo(orderView, matchedPolicy); result.AddPNRInfo(pnrInfo); result.TripType = pnrInfo.TripType; result.Status = result.RequireConfirm ? OrderStatus.Applied : OrderStatus.Ordered; if (result.Status == OrderStatus.Applied) { result.VisibleRole |= result.IsThirdRelation ? OrderRole.Supplier : OrderRole.Provider; } #endregion return(result); }
internal static Deduction GetDeduction(PolicyMatch.MatchedPolicy policy) { if (policy.PolicyType == PolicyType.Special && ((SpecialPolicyInfo)policy.OriginalPolicy).Type != SpecialProductType.LowToHigh) //Xie. 2013-03-07 { return(Deduction.Empty); } else { return(new Deduction() { Provider = policy.Rebate, Purchaser = policy.Commission, Platform = policy.Deduction }); } }
void checkCanChangeProvider(PolicyMatch.MatchedPolicy policy) { if (this.Status == OrderStatus.DeniedWithETDZ) { if (this.IsSpecial) { if (this.IsThirdRelation) { if (policy.PolicyType != PolicyType.Normal && policy.PolicyType != PolicyType.NormalDefault && policy.PolicyType != PolicyType.OwnerDefault) { throw new CustomException("特殊产品只能匹配出票方的普通政策"); } } else { throw new CustomException("该特殊产品发布方具有出票资质,不能更换出票方"); } } else { if (this.Product.ProductType == ProductType.General) { if (policy.PolicyType != PolicyType.Normal && policy.PolicyType != PolicyType.NormalDefault && policy.PolicyType != PolicyType.OwnerDefault) { throw new CustomException("普通票只能更换到普通政策"); } } else if (this.Product.ProductType == ProductType.Team) { if (policy.PolicyType != PolicyType.Team && policy.PolicyType != PolicyType.NormalDefault && policy.PolicyType != PolicyType.OwnerDefault) { throw new CustomException("团队票只能更换到团队政策"); } } else { throw new CustomException("仅普通政策订单可以更换出票方"); } } } else { throw new StatusException(this.Id.ToString()); } }
internal static bool IsCustomerResource(PolicyMatch.MatchedPolicy policy) { if (policy.PolicyType == PolicyType.Special) { var specialPolicy = policy.OriginalPolicy as SpecialPolicyInfo; switch (specialPolicy.Type) { case SpecialProductType.CostFree: return(!specialPolicy.SynBlackScreen); case SpecialProductType.Bloc: case SpecialProductType.Business: case SpecialProductType.OtherSpecial: case SpecialProductType.LowToHigh: return(false); default: return(true); } } return(false); }
private static ProductType GetProductType(PolicyMatch.MatchedPolicy policy) { switch (policy.PolicyType) { case PolicyType.Normal: return(ProductType.General); case PolicyType.Bargain: return(ProductType.Promotion); case PolicyType.Special: return(ProductType.Special); case PolicyType.Team: return(ProductType.Team); case PolicyType.Notch: return(ProductType.Notch); default: throw new NotSupportedException(policy.PolicyType.ToString()); } }
internal static RoundTrip CreateRoundTrip(FlightView outwardFlightView, FlightView returnFlightView, PassengerType passengerType, PolicyMatch.MatchedPolicy policy) { if (outwardFlightView.Airline != returnFlightView.Airline) { throw new NotSupportedException("暂只支持同一航空公司的往返程"); } Carrier carrier = new Carrier(outwardFlightView.Airline); switch (policy.PolicyType) { case ChinaPay.B3B.DataTransferObject.Policy.PolicyType.General: return(new GeneralRoundTrip(carrier, Flight.GetFlight(outwardFlightView, passengerType, policy), Flight.GetFlight(returnFlightView, passengerType, policy))); case ChinaPay.B3B.DataTransferObject.Policy.PolicyType.Prodution: return(new ProductionRoundTrip(carrier, Flight.GetFlight(outwardFlightView, passengerType, policy), Flight.GetFlight(returnFlightView, passengerType, policy), ((PolicyMatch.MatchedProductionPolicy)policy).Price)); default: throw new NotSupportedException("产品类型与行程类型不匹配"); } }
internal static Flight GetFlight(DataTransferObject.Order.FlightView flightView, PassengerType passengerType, PolicyMatch.MatchedPolicy policy, decimal?fare) { var result = new Flight(flightView.Airline, flightView.Departure, flightView.Arrival, flightView.TakeoffTime) { TakeoffTime = flightView.TakeoffTime, LandingTime = flightView.LandingTime, FlightNo = flightView.FlightNo, AirCraft = flightView.AirCraft, IsShare = flightView.IsShare, ArrivalTerminal = flightView.ArrivalTerminal, DepartureTerminal = flightView.DepartureTerminal }; result.Bunk = BaseBunk.CreateBunk(flightView.Airline, flightView.Bunk, flightView.Type, flightView.Departure, flightView.Arrival, flightView.TakeoffTime, passengerType, policy, result.YBPrice, fare); if (result.Bunk is SpecialBunk) { if ((result.Bunk as SpecialBunk).ReleasedFare <= 0) { throw new CustomException("价格异常,不能生成订单"); } } else if (result.Bunk.Fare <= 0) { throw new CustomException("价格异常,不能生成订单"); } decimal airportFee = 0M, baf = 0M; var bafView = FoundationService.QueryBAF(flightView.Airline, flightView.Departure, flightView.Arrival, flightView.TakeoffTime); if (passengerType == PassengerType.Adult) { airportFee = FoundationService.QueryAirportFee(flightView.AirCraft); baf = bafView == null ? 0 : bafView.Adult; } else { baf = bafView == null ? 0 : bafView.Child; } result.AirportFee = airportFee; result.BAF = baf; return(result); }
internal static OneWay CreateOneWay(FlightView flightView, PassengerType passengerType, PolicyMatch.MatchedPolicy policy) { var carrier = new Carrier(flightView.Airline); return(new OneWay(carrier, Flight.GetFlight(flightView, passengerType, policy))); }
internal static ProductInfo GetProductInfo(PolicyMatch.MatchedPolicy policy) { ProductInfo productInfo = null; if (policy.PolicyType == PolicyType.NormalDefault || policy.PolicyType == PolicyType.BargainDefault || policy.PolicyType == PolicyType.OwnerDefault || (policy.PolicyType == PolicyType.Normal && policy.OriginalPolicy == null && policy.OriginalExternalPolicy == null)) { return(new CommonProductInfo { OfficeNo = policy.OfficeNumber, //NeedAuth = policy.NeedAUTH, ProductType = policy.PolicyType == PolicyType.BargainDefault ? ProductType.Promotion : ProductType.General, RequireChangePNR = false, ETDZMode = ETDZMode.Manual, TicketType = TicketType.BSP, Id = policy.Id, Remark = string.Empty, Condition = string.Empty, IsDefaultPolicy = policy.PolicyType == PolicyType.NormalDefault || policy.PolicyType == PolicyType.BargainDefault || policy.PolicyType == PolicyType.OwnerDefault, RefundAndReschedulingProvision = new RefundAndReschedulingProvision() }); } if (policy.PolicyType == PolicyType.Special) { var specialPolicy = policy.OriginalPolicy as SpecialPolicyInfo; productInfo = new SpeicalProductInfo { RequireConfirm = specialPolicy.ConfirmResource, SpeicalProductType = specialPolicy.Type, ProductType = ProductType.Special, OfficeNo = specialPolicy.OfficeCode, //NeedAuth = policy.NeedAUTH }; } else if (policy.IsExternal) { productInfo = new CommonProductInfo { ProductType = GetProductType(policy), RequireChangePNR = policy.OriginalExternalPolicy.RequireChangePNR, ETDZMode = ETDZMode.Manual }; } else { var generalPolicy = policy.OriginalPolicy as IGeneralPolicy; productInfo = new CommonProductInfo { ProductType = GetProductType(policy), RequireChangePNR = generalPolicy.ChangePNR, ETDZMode = generalPolicy.AutoPrint ? ETDZMode.Auto : ETDZMode.Manual }; } if (policy.IsExternal) { productInfo.Id = Guid.NewGuid(); productInfo.OfficeNo = policy.OriginalExternalPolicy.OfficeNo; //productInfo.NeedAuth = policy.OriginalExternalPolicy.RequireAuth; productInfo.TicketType = policy.OriginalExternalPolicy.TicketType; productInfo.Remark = policy.OriginalExternalPolicy.Remark; productInfo.Condition = policy.OriginalExternalPolicy.Condition; } else { productInfo.Id = policy.OriginalPolicy.Id; productInfo.OfficeNo = policy.OriginalPolicy.OfficeCode; //productInfo.NeedAuth = policy.OriginalPolicy.NeedAUTH; productInfo.TicketType = policy.OriginalPolicy.TicketType; productInfo.Remark = policy.OriginalPolicy.Remark; productInfo.Condition = policy.OriginalPolicy.Condition; } if (policy.OriginalPolicy is IHasRegulation) { var regulation = (IHasRegulation)policy.OriginalPolicy; productInfo.RefundAndReschedulingProvision = new RefundAndReschedulingProvision() { Refund = regulation.RefundRegulation, Scrap = regulation.InvalidRegulation, Alteration = regulation.ChangeRegulation, Transfer = regulation.EndorseRegulation }; } else { productInfo.RefundAndReschedulingProvision = new RefundAndReschedulingProvision(); } return(productInfo); }
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 BaseBunk CreateChildrenBunk(string airline, string bunkCode, string departure, string arrival, DateTime flightDate, PolicyMatch.MatchedPolicy policy, decimal ybPrice, decimal?patPrice) { if (policy.PolicyType == PolicyType.Normal || policy.PolicyType == PolicyType.NormalDefault) { var childBunk = FoundationService.QueryBunk(airline, departure, arrival, flightDate, bunkCode).FirstOrDefault(); if (childBunk is Foundation.Domain.GeneralBunk) { var adultDiscount = (childBunk as Foundation.Domain.GeneralBunk).Discount; decimal fare = 0M; if (adultDiscount >= 1) { var adultFare = Utility.Calculator.Round(ybPrice * adultDiscount, 1); fare = Utility.Calculator.Round(adultFare / 2, 1); } else { fare = Utility.Calculator.Round(ybPrice / 2, 1); } var discount = Utility.Calculator.Round(fare / ybPrice, -3); return(new EconomicBunk(bunkCode, discount, fare, childBunk.EI)); } else if (childBunk is Foundation.Domain.PromotionBunk) { if (patPrice == null) { throw new CustomException("缺少儿童价格信息"); } var promotionBunk = childBunk as Foundation.Domain.PromotionBunk; return(new PromotionBunk(bunkCode, patPrice.Value, PriceType.Price, promotionBunk.EI, promotionBunk.Description)); } else if (childBunk is Foundation.Domain.ProductionBunk) { if (patPrice == null) { throw new CustomException("缺少儿童价格信息"); } return(new TransferBunk(bunkCode, patPrice.Value, childBunk.EI)); } else if (childBunk is Foundation.Domain.TeamBunk) { if (patPrice == null) { throw new CustomException("缺少儿童价格信息"); } return(new TeamBunk(bunkCode, patPrice.Value, PriceType.Price, childBunk.EI, string.Empty)); } else if (childBunk is Foundation.Domain.TransferBunk) { if (patPrice == null) { throw new CustomException("缺少儿童价格信息"); } return(new TransferBunk(bunkCode, patPrice.Value, childBunk.EI)); } else if (childBunk is Foundation.Domain.FreeBunk) { if (patPrice == null) { throw new CustomException("缺少儿童价格信息"); } var freeBunk = childBunk as Foundation.Domain.FreeBunk; return(new FreeBunk(bunkCode, patPrice.Value, freeBunk.EI, freeBunk.Description)); } throw new CustomException("当前舱位不支持儿童"); } throw new CustomException("儿童票只能匹配普通政策"); }
internal static Segment CreateSegment(OrderView orderView, PassengerType passengerType, PolicyMatch.MatchedPolicy policy) { int flightCount = orderView.Flights.Count(); if (flightCount == 1) { return(OneWay.CreateOneWay(orderView.Flights.ElementAt(0), passengerType, policy)); } else if (flightCount == 2) { return(RoundTrip.CreateRoundTrip(orderView.Flights.ElementAt(0), orderView.Flights.ElementAt(1), passengerType, policy)); } else { throw new NotSupportedException("暂只支持最多两个航段"); } }