Пример #1
0
        /// <summary>
        /// 基于查询条件,查询酒店可卖的房间产品(RoomStay),包括价格信息、房型信息等
        /// 建议在开始预订时或提交订单时调用可订检查
        /// </summary>
        /// <param name="req"></param>
        /// <returns></returns>
        public OTA_HotelAvailReturnEntity OTA_HotelAvail(OTA_HotelAvailCallEntity req)
        {
            var rep = new OTA_HotelAvailReturnEntity();
            StringBuilder reqXml = new StringBuilder();
            reqXml.AppendFormat("<ns:OTA_HotelAvailRQ Version=\"1.0\" TimeStamp=\"{0}\">", "2012-04-20T00:00:00.000+08:00");
            reqXml.Append("<ns:AvailRequestSegments>");
            reqXml.Append("<ns:AvailRequestSegment>");
            reqXml.Append("<ns:HotelSearchCriteria>");
            reqXml.Append("<ns:Criterion>");

            reqXml.AppendFormat("<ns:HotelRef HotelCode=\"{0}\"/>", req.HotelCode);
            reqXml.AppendFormat("<ns:StayDateRange Start=\"{0}\" End=\"{1}\"/>", req.CheckInTime.ToCtripDateFormat(), req.CheckOutTime.ToCtripDateFormat());
            reqXml.Append("<ns:RatePlanCandidates>");
            reqXml.AppendFormat("<ns:RatePlanCandidate RatePlanCode=\"{0}\"/>",req.HotelRoomCode);
            reqXml.Append("</ns:RatePlanCandidates>");
            reqXml.Append("<ns:RoomStayCandidates>");

            reqXml.AppendFormat("<ns:RoomStayCandidate Quantity=\"{0}\">", req.RoomCount);
            reqXml.Append("<ns:GuestCounts");
            if (req.IsPerRoom != null)
            {
                reqXml.AppendFormat("IsPerRoom=\"{0}\"", req.IsPerRoom.ToString().ToLower());
            }
            reqXml.Append(">");
            reqXml.AppendFormat("<ns:GuestCount Count=\"{0}\"/>", req.GuestCount);
            reqXml.Append("</ns:GuestCounts>");

            reqXml.Append("</ns:RoomStayCandidate>");
            reqXml.Append("</ns:RoomStayCandidates>");
            reqXml.Append("<ns:TPA_Extensions>");
            reqXml.AppendFormat("<ns:LateArrivalTime>{0}</ns:LateArrivalTime>", req.LastCheckInTime.ToCtripDateFormat());
            reqXml.Append("</ns:TPA_Extensions>");

            reqXml.Append("</ns:Criterion>");
            reqXml.Append("</ns:HotelSearchCriteria>");
            reqXml.Append("</ns:AvailRequestSegment>");
            reqXml.Append("</ns:AvailRequestSegments>");
            reqXml.Append("</ns:OTA_HotelAvailRQ>");
            

            req.RequestContent = reqXml.ToString();
            string repXml = HotelApiCall(req);
            XmlDocument xmlDoc = new XmlDocument();
            xmlDoc.LoadXml(repXml);

            var errorsNode = xmlDoc.SelectSingleNode("Response/HotelResponse/OTA_HotelAvailRS/Errors");
            if(errorsNode!=null)
            {
                return rep;
            }

            var roomStayNode = xmlDoc.SelectSingleNode("Response/HotelResponse/OTA_HotelAvailRS/RoomStays/RoomStay");
            rep.AvailabilityStatus = ((XmlElement)roomStayNode).GetAttribute("AvailabilityStatus").Trim();
            XmlElement totalNode = (XmlElement)roomStayNode.SelectSingleNode("Total");
            rep.TotalAmountBeforeTax = totalNode.GetAttribute("AmountBeforeTax").Trim().ToDecimal();
            rep.CurrencyCode = totalNode.GetAttribute("CurrencyCode").Trim();

            var ratePlanNode = roomStayNode.SelectSingleNode("RatePlans/RatePlan");

            rep.RatePlanCode = ((XmlElement)ratePlanNode).GetAttribute("RatePlanCode").Trim();
            rep.HotelRoomCode = rep.RatePlanCode;
            rep.RoomTypeCode = rep.RatePlanCode;
            rep.RatePlanName = ((XmlElement)ratePlanNode).GetAttribute("RatePlanName").Trim();
            rep.PrepaidIndicator = ((XmlElement)ratePlanNode).GetAttribute("PrepaidIndicator").Trim();

            rep.Breakfast = ((XmlElement)ratePlanNode.SelectSingleNode("MealsIncluded")).GetAttribute("Breakfast");

            var roomTypenode = roomStayNode.SelectSingleNode("RoomTypes/RoomType");
            rep.RoomTypeCode = ((XmlElement)roomTypenode).GetAttribute("RoomTypeCode").Trim();
            rep.RoomTypeName = ((XmlElement)roomTypenode).GetAttribute("RoomType").Trim();

            var roomTypeDescriptionTextNode = roomTypenode.SelectSingleNode("RoomDescription/Text");
            if (roomTypeDescriptionTextNode != null)
            {
                rep.RoomTypeDescriptiveText = roomTypeDescriptionTextNode.InnerText.Trim();
            }

            var ratesNodes = roomStayNode.SelectNodes("RoomRates/RoomRate/Rates/Rate");
            List<AvaiRoomRate> avaiRoomRates = new List<AvaiRoomRate>();
            AvaiRoomRate roomRate = null;
            foreach (XmlNode n in ratesNodes)
            {
                roomRate = new AvaiRoomRate();
                roomRate.EffectiveDate = ((XmlElement)n).GetAttribute("EffectiveDate").Trim().ToDateTime();
                roomRate.ExpireDate = ((XmlElement)n).GetAttribute("ExpireDate").Trim().ToDateTime();
                roomRate.MaxGuestApplicable = ((XmlElement)n).GetAttribute("MaxGuestApplicable").Trim();

                List<Pertain> pertains = new List<Pertain>();
                var feeNodes = n.SelectNodes("Fees/Fee");
                Pertain pertain = null;
                foreach (XmlNode f in feeNodes)
                {
                    pertain = new Pertain();
                    pertain.Amount = ((XmlElement)f).GetAttribute("Amount").Trim().ToDecimal();
                    pertain.ChargeUnit = ((XmlElement)f).GetAttribute("ChargeUnit").Trim();
                    pertain.Code = ((XmlElement)f).GetAttribute("Code").Trim();
                    pertain.CurrencyCode = ((XmlElement)f).GetAttribute("CurrencyCode").Trim();
                    XmlNode descText = f.SelectSingleNode("Description/Text");
                    if (descText != null)
                    {
                        pertain.Description = descText.InnerText.Trim();
                    }
                    pertains.Add(pertain);
                }
                roomRate.PertainList = pertains;
                avaiRoomRates.Add(roomRate);
            }

            rep.RoomRateList = avaiRoomRates;

            XmlNode guaranteePaymentNode = roomStayNode.SelectSingleNode("DepositPayments/GuaranteePayment");
            if(guaranteePaymentNode!=null)
            {
                GuaranteePayment guaranteePayment = new GuaranteePayment();
                guaranteePayment.StartTime = ((XmlElement)guaranteePaymentNode).GetAttribute("Start").Trim().ToDateTime();
                guaranteePayment.EndTime = ((XmlElement)guaranteePaymentNode).GetAttribute("End").Trim().ToDateTime();
                guaranteePayment.GuaranteeCode = ((XmlElement)guaranteePaymentNode).GetAttribute("GuaranteeCode").Trim();
                //guaranteePayment.GuaranteeCurrencyCode = ((XmlElement)guaranteePaymentNode).GetAttribute("GuaranteeCode").Trim();
                XmlNode amountPercentNode = guaranteePaymentNode.SelectSingleNode("AmountPercent");
                guaranteePayment.GuaranteeAmount = ((XmlElement)amountPercentNode).GetAttribute("Amount").Trim().ToDecimal();
                guaranteePayment.GuaranteeCurrencyCode = ((XmlElement)amountPercentNode).GetAttribute("CurrencyCode").Trim();
                XmlNode g_text = amountPercentNode.SelectSingleNode("Description/Text");
                if (g_text != null)
                {
                    guaranteePayment.Description = g_text.InnerText.Trim();
                }
                rep.GuaranteePayment = guaranteePayment;
            }
            

            XmlNode cancelPenaltyNode = roomStayNode.SelectSingleNode("CancelPenalties/CancelPenalty");
            if(cancelPenaltyNode!=null)
            {
                CancelPenalty cancelPenalty = new CancelPenalty();

                cancelPenalty.StartTime = ((XmlElement)cancelPenaltyNode).GetAttribute("Start").ToDateTime();
                cancelPenalty.EndTime = ((XmlElement)cancelPenaltyNode).GetAttribute("End").ToDateTime();
                cancelPenalty.GuaranteeCode = ((XmlElement)cancelPenaltyNode).GetAttribute("GuaranteeCode").Trim();
                XmlNode c_AmountPercentNode = cancelPenaltyNode.SelectSingleNode("AmountPercent");
                cancelPenalty.AmountPercent = ((XmlElement)c_AmountPercentNode).GetAttribute("Amount").Trim().ToDecimal();
                cancelPenalty.CurrencyCode = ((XmlElement)c_AmountPercentNode).GetAttribute("CurrencyCode").Trim();
                XmlNode c_node = c_AmountPercentNode.SelectSingleNode("Description/Text");
                if (c_node != null)
                {
                    cancelPenalty.Description = c_node.InnerText.Trim();
                }
                rep.CancelPenalty = cancelPenalty;
            }
            
            return rep; 
        }
Пример #2
0
        /// <summary>
        /// 根据查询条件查询可用的Rate Plan,包括房价、可卖渠道。通常用于双方系统保持一致性
        /// 参数Start,End,HotelCode为必填;参数AvailRatesOnlyInd为空时值为false
        /// </summary>
        /// <param name="req"></param>
        /// <returns></returns>
        public OTA_HotelRatePlanReturnEntity OTA_HotelRatePlan(OTA_HotelRatePlanCallEntity req)
        {
            var rep = new OTA_HotelRatePlanReturnEntity();
            try
            {
                StringBuilder reqXml = new StringBuilder("<ns:OTA_HotelRatePlanRQ TimeStamp=\"2013-06-01T00:00:00.000+08:00\" Version=\"1.0\">");
                reqXml.Append("<ns:RatePlans>");
                foreach (var item in req.HotelRatePlanList)
                {
                    reqXml.Append("<ns:RatePlan>");
                    reqXml.AppendFormat("<ns:DateRange Start=\"{0}\" End=\"{1}\"/>", item.StartDate.ToString("yyyy-MM-dd"), item.EndDate.ToString("yyyy-MM-dd"));
                    reqXml.Append("<ns:RatePlanCandidates>");
                    reqXml.AppendFormat("<ns:RatePlanCandidate AvailRatesOnlyInd=\"{0}\" >", item.AvailRatesOnlyInd.ToString().ToLower());
                    reqXml.Append("<ns:HotelRefs>");
                    reqXml.AppendFormat("<ns:HotelRef HotelCode=\"{0}\"/>", item.HotelCode);
                    reqXml.Append("</ns:HotelRefs>");
                    reqXml.Append("</ns:RatePlanCandidate>");
                    reqXml.Append("</ns:RatePlanCandidates>");
                    reqXml.Append("<ns:TPA_Extensions RestrictedDisplayIndicator=\"false\"/>");
                    reqXml.Append("</ns:RatePlan>");
                }
                reqXml.Append("</ns:RatePlans>");
                reqXml.Append("</ns:OTA_HotelRatePlanRQ>");

                req.RequestContent = reqXml.ToString();
                string repXml = HotelApiCall(req);
                //LogHelper.Debug(repXml);
                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.LoadXml(repXml);
                GetHeaderResult(xmlDoc, rep);
                var hotelRatePlanNodes = xmlDoc.SelectNodes("Response/HotelResponse/OTA_HotelRatePlanRS/RatePlans");
                List<HotelRatePlan> hotelRatePlanList = new List<HotelRatePlan>();

                HotelRatePlan ratePlan = null;

                foreach (XmlNode hp in hotelRatePlanNodes)
                {
                    ratePlan = new HotelRatePlan();
                    ratePlan.HotelCode = ((XmlElement)hp).GetAttribute("HotelCode").Trim().ToInt32();
                    var roomRatePlanNodes = hp.SelectNodes("RatePlan");
                    List<RoomRatePlan> roomRatePlanList = new List<RoomRatePlan>();
                    RoomRatePlan roomRatePlan = null;
                    foreach (XmlNode rp in roomRatePlanNodes)
                    {
                        roomRatePlan = new RoomRatePlan();

                        XmlNode desNode = rp.SelectSingleNode("Description/Text");
                        if (desNode != null)
                        {
                            roomRatePlan.Description = desNode.InnerText.Trim();
                        }
                        roomRatePlan.MarketCode = ((XmlElement)rp).GetAttribute("MarketCode").Trim().ToInt32();
                        roomRatePlan.RatePlanCategory = ((XmlElement)rp).GetAttribute("RatePlanCategory").Trim().ToInt32();
                        roomRatePlan.HotelRoomCode = ((XmlElement)rp).GetAttribute("RatePlanCode").Trim().ToInt32();
                        
                        var SellableProductNodes = rp.SelectNodes("SellableProducts/SellableProduct");
                        List<string> sellableProductList = new List<string>();
                        if (SellableProductNodes != null)
                        {
                            foreach (XmlNode n in SellableProductNodes)
                            {
                                sellableProductList.Add(((XmlElement)n).GetAttribute("InvCode").Trim());
                            }
                        }
                        roomRatePlan.SellableProductList = sellableProductList;

                        List<RoomRate> roomRateList = new List<RoomRate>();
                        var roomRateNodes = rp.SelectNodes("Rates/Rate");
                        RoomRate roomRate = null;
                        foreach (XmlNode rn in roomRateNodes)
                        {
                            roomRate = new RoomRate();
                            roomRate.StartTime = ((XmlElement)rn).GetAttribute("Start").Trim().ToDateTime();
                            roomRate.EndTime = ((XmlElement)rn).GetAttribute("End").Trim().ToDateTime();
                            roomRate.Status = ((XmlElement)rn).GetAttribute("Status").Trim();
                            roomRate.IsInstantConfirm = ((XmlElement)rn).GetAttribute("IsInstantConfirm").Trim()=="false"?0:1;

                            XmlElement baseByGuestAmtNode = (XmlElement)rn.SelectSingleNode("BaseByGuestAmts/BaseByGuestAmt");
                            roomRate.AmountBeforeTax = baseByGuestAmtNode.GetAttribute("AmountBeforeTax").Trim().ToDecimal();
                            roomRate.CurrencyCode = baseByGuestAmtNode.GetAttribute("CurrencyCode").Trim();
                            roomRate.NumberOfGuests = baseByGuestAmtNode.GetAttribute("NumberOfGuests").Trim().ToInt32();
                            string listprice = baseByGuestAmtNode.GetAttribute("ListPrice").Trim();

                            if (!string.IsNullOrEmpty(listprice))
                            {
                                roomRate.ListPrice = listprice.ToDecimal();
                            }

                            XmlNode CancelPenaltyNode = rn.SelectSingleNode("CancelPolicies/CancelPenalty");

                            if(CancelPenaltyNode!=null)
                            {
                                roomRate.CancelPenaltyStartTime = ((XmlElement)CancelPenaltyNode).GetAttribute("Start").Trim().ToDateTime();
                                roomRate.CancelPenaltyEndTime = ((XmlElement)CancelPenaltyNode).GetAttribute("End").Trim().ToDateTime();

                                XmlNode AmountPercentNode = CancelPenaltyNode.SelectSingleNode("AmountPercent");
                                roomRate.CancelAmount = ((XmlElement)AmountPercentNode).GetAttribute("Amount").Trim().ToDecimal();
                                roomRate.CancelCurrencyCode = ((XmlElement)AmountPercentNode).GetAttribute("CurrencyCode").Trim();

                                XmlElement GuaranteePolicyEle = (XmlElement)rn.SelectSingleNode("GuaranteePolicies/GuaranteePolicy");
                                if(GuaranteePolicyEle!=null)
                                {
                                    
                                    roomRate.GuaranteeCode = GuaranteePolicyEle.GetAttribute("GuaranteeCode").Trim();
                                    roomRate.HoldTime = GuaranteePolicyEle.GetAttribute("HoldTime").Trim();
                                }
                                
                            }
                            else
                            {
                                roomRate.CancelPenaltyStartTime = DateTime.Parse("1900-1-1");
                                roomRate.CancelPenaltyEndTime = DateTime.Parse("1900-1-1");
                                roomRate.CancelAmount = 0;
                                roomRate.CancelCurrencyCode = "";
                                roomRate.GuaranteeCode = "";
                                roomRate.HoldTime = "1900-1-1";
                            }

                            
                            XmlElement MealsIncludedEle = (XmlElement)rn.SelectSingleNode("MealsIncluded");
                            roomRate.Breakfast = MealsIncludedEle.GetAttribute("Breakfast").Trim();
                            roomRate.NumberOfBreakfast = MealsIncludedEle.GetAttribute("NumberOfBreakfast").Trim().ToInt32();


                            List<Pertain> pertainList = new List<Pertain>();
                            var feeNodes = rn.SelectNodes("Fees/Fee");
                            Pertain pertain = null;
                            foreach (XmlNode fn in feeNodes)
                            {
                                pertain = new Pertain();
                                pertain.Amount = ((XmlElement)fn).GetAttribute("Amount").Trim().ToDecimal();
                                pertain.ChargeUnit = ((XmlElement)fn).GetAttribute("ChargeUnit").Trim();
                                pertain.CurrencyCode = ((XmlElement)fn).GetAttribute("CurrencyCode").Trim();
                                pertain.Code = ((XmlElement)fn).GetAttribute("Code").Trim();
                                pertain.Description = fn.SelectSingleNode("Description/Text").InnerText.Trim();
                                pertainList.Add(pertain);
                            }

                            roomRate.PertainList = pertainList;

                            XmlNode RebatePromotionNode = rn.SelectSingleNode("TPA_Extensions/RebatePromotion");
                            if (RebatePromotionNode != null)
                            {
                                roomRate.StartPeriod = ((XmlElement)RebatePromotionNode).GetAttribute("StartPeriod").Trim().ToDateTime();
                                roomRate.EndPeriod = ((XmlElement)RebatePromotionNode).GetAttribute("EndPeriod").Trim().ToDateTime();
                                roomRate.BackCurrencyCode = ((XmlElement)RebatePromotionNode).GetAttribute("CurrencyCode").Trim();
                                roomRate.BackCode = ((XmlElement)RebatePromotionNode).GetAttribute("Code").Trim();
                                roomRate.ProgramName = ((XmlElement)RebatePromotionNode).GetAttribute("ProgramName").Trim();
                                roomRate.BackAmount = ((XmlElement)RebatePromotionNode).GetAttribute("Amount").Trim().ToDecimal();
                                roomRate.BackDescription = RebatePromotionNode.SelectSingleNode("Description/Text").InnerText.Trim();
                                roomRate.RoomCode = roomRatePlan.HotelRoomCode;
                            }
                            else
                            {
                                roomRate.StartPeriod = DateTime.Parse("1900-1-1");
                                roomRate.EndPeriod = DateTime.Parse("1900-1-1");
                                roomRate.BackCurrencyCode = "";
                                roomRate.BackCode = "";
                                roomRate.ProgramName = "";
                                roomRate.BackAmount = 0;
                                roomRate.BackDescription = "";
                                roomRate.RoomCode = 0;

                            }
                            roomRateList.Add(roomRate);

                        }
                        roomRatePlan.RoomRateList = roomRateList;
                        roomRatePlanList.Add(roomRatePlan);
                    }
                    ratePlan.RoomRatePlanList = roomRatePlanList;
                    hotelRatePlanList.Add(ratePlan);
                }
                rep.HotelRatePlanList = hotelRatePlanList;
            }
            catch
            {
                throw;
            }
            return rep;
        }