public static bool HotelRoomBookAvaible(int hotelId, int roomTypeCode, int roomCount, int guestCount, DateTime checkinTime, DateTime lastCheckInTime, bool? isPerRoom = null) { OTA_HotelAvailCallEntity callEntity = new OTA_HotelAvailCallEntity(); callEntity.HotelCode = hotelId; callEntity.HotelRoomCode = roomTypeCode; callEntity.CheckInTime = checkinTime; callEntity.CheckOutTime = lastCheckInTime; callEntity.GuestCount = guestCount; callEntity.IsPerRoom = isPerRoom; callEntity.LastCheckInTime = checkinTime; callEntity.RoomCount = roomCount; var rep = hotelOTAService.OTA_HotelAvail(callEntity); return false; }
/// <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; }