//房型 baoku/hotel/getRoomTypeList /// <summary> /// 酒店房型 /// </summary> /// <param name="maxId"></param> /// <param name="top"></param> /// <returns></returns> public static DataResult GetRoomType(int id, int top) { var result = new DataResult(); result.Data = string.Empty; var hDb = new H_HotelInfoAccess(); var hotelList = hDb.Query().Where(h => h.Id >= id && h.HIOutType == 1).Top(top)?.ToList(); if (hotelList == null || hotelList.Count == 0) { result.Message = "未查询到酒店"; return(result); } var indexCount = 0; hotelList.ForEach(x => { var dic = new Dictionary <string, string>(); dic.Add("appId", AtourSignUtil.AtourAuth_APPID); dic.Add("hotelId", x.HIOutId.ToString()); var sign = AtourSignUtil.GetSignUtil(dic); var url = AtourSignUtil.AtourAuth_URL + "baoku/hotel/getRoomTypeList"; url += "?appId=" + AtourSignUtil.AtourAuth_APPID + "&hotelId=" + x.HIOutId + "&sign=" + sign; var rtn = ApiHelper.HttpGet(url)?.ToObject <YdRoomTypeResponse>(); var list = rtn?.result; if (list?.Count > 0) { if (x.HIIsValid == 0) { hDb.Update().Where(h => h.Id == x.Id) .Set(h => h.HIIsValid == 1 && h.HIUpdateName == "亚朵更新有效" && h.HIUpdateTime == DateTime.Now) .Execute(); OpenApi.HotelOffline(x.Id, 1); logDb.AddLog(x.Id, $"亚朵更新有效:{x.HIOutId}:{x.HIName}", ResourceLogType.HotelUpdate); } var listId = list.Select(l => l.roomTypeId).ToList(); var db = new H_HotelRoomAccess(); var room = db.Query().Where(r => r.HIId == x.Id).ToList(); var updateList = room?.Where(r => listId.Contains(r.HROutId) && r.HROutType == 1)?.ToList(); result.Data += $"[{indexCount++}]{x.HIName}新增房型{list.Count()}个;"; list.ForEach(l => { var baseRoom = room?.Where(r => r.HROutId == l.roomTypeId && r.HIId == x.Id && r.HROutType == 1)?.FirstOrDefault(); if (baseRoom == null || baseRoom.Id <= 0) { var roomId = db.Add(new H_HotelRoomModel { Id = 0, HIId = x.Id, HROutType = 1, HROutId = l.roomTypeId, HRName = l.roomTypeName ?? string.Empty, HRRoomSIze = string.Empty, HRAddName = "亚朵新增", HRAddTime = DateTime.Now, HRBedType = GetBedType(l.bedRemark, l.roomTypeName ?? string.Empty), HRBedSize = GetBedSize(l.bedRemark, l.roomTypeName ?? string.Empty), HRFloor = string.Empty, HRIsValid = 1, HRPersonCount = 0, HRUpdateName = string.Empty, HRUpdateTime = DateTime.Now, HRWindowsType = 0 }); logDb.AddLog(x.Id, $"亚朵新增房型:{x.HIOutId}:{x.HIName};{l.roomTypeId}", ResourceLogType.RoomAdd); } else { if (baseRoom.HRBedType == 0) { db.Update().Set(rr => rr.HRBedType == GetBedType(l.bedRemark, l.roomTypeName ?? string.Empty)) .Set(rr => rr.HRBedSize == GetBedSize(l.bedRemark, l.roomTypeName ?? string.Empty)) .Set(rr => rr.HRUpdateTime == DateTime.Now) .Where(rr => rr.Id == baseRoom.Id).Execute(); logDb.AddLog(x.Id, $"亚朵更新房型床型:{x.HIOutId}:{x.HIName};{l.roomTypeId}", ResourceLogType.RoomUpdate); } } //是否要修改 }); OpenApi.AddRoomInfo(x.Id); } else { //房型数量为0 酒店无效 hDb.Update().Where(h => h.Id == x.Id) .Set(h => h.HIIsValid == 0 && h.HIUpdateName == "亚朵无房型更新" && h.HIUpdateTime == DateTime.Now) .Execute(); OpenApi.HotelOffline(x.Id, 0); result.Message = rtn?.msg ?? "系统异常"; logDb.AddLog(x.Id, $"亚朵无房型更新:{x.HIOutId}:{x.HIName}", ResourceLogType.HotelDelete); } //查询最近三天的价格和库存 var rrRtn = GetRoomRate(x.HIOutId, DateTime.Now, 7); result.Data += rrRtn.Message?.ToString() ?? string.Empty; }); return(result); }
/// <summary> /// 喜玩价格 /// </summary> /// <returns></returns> public static DataResult Xw_HotelPrice(long id = 0) { var rtn = new DataResult(); var roomDb = new H_HotelRoomAccess(); var hDb = new H_HotelInfoAccess(); var query = hDb?.Query().Where(h => h.HIOutType == 2); if (id > 0) { query?.Where(x => x.Id == id); } var hotelList = query.ToList(); hotelList?.ForEach(x => { var hotel = GetHotelPrice(x.HIOutId); if (hotel != null && hotel.HotelId > 0) { var c = hotel?.Rooms?.Count() ?? 0; rtn.Message += $"{c}个;"; if (c == 0) {//房型数量为0 酒店无效 hDb.Update().Where(h => h.Id == x.Id) .Set(h => h.HIIsValid == 0 && h.HIUpdateName == "喜玩无房型更新" && h.HIUpdateTime == DateTime.Now) .Execute(); OpenApi.HotelOffline(x.Id, 0); logDb.AddLog(x.Id, $"喜玩无房型更新:{hotel.HotelId}:{hotel.HotelName}", ResourceLogType.HotelDelete); rtn.Message += $"[无效]"; } else { if (x.HIIsValid == 0) { hDb.Update().Where(h => h.Id == x.Id) .Set(h => h.HIIsValid == 1 && h.HIUpdateName == "喜玩更新酒店有效" && h.HIUpdateTime == DateTime.Now) .Execute(); OpenApi.HotelOffline(x.Id, 1); logDb.AddLog(x.Id, $"喜玩更新酒店有效:{hotel.HotelId}:{hotel.HotelName}", ResourceLogType.HotelUpdate); rtn.Message += $"[有效]"; } hotel?.Rooms?.ForEach(r => { var oldRoom = roomDb.Query().Where(rd => rd.HIId == x.Id && rd.HROutId == r.RoomTypeId.ToInt()).FirstOrDefault(); if (oldRoom == null || oldRoom.Id <= 0) { oldRoom = new H_HotelRoomModel { HROutId = r.RoomTypeId.ToInt(), HIId = x.Id, Id = 0, HRAddName = "喜玩新增", HRAddTime = DateTime.Now, HRBedType = GetBedType(r.RoomName, r.BedType),//需要转化 HRBedSize = GetBedSize(r.RoomName, r.BedType), HRFloor = string.Empty, HRIsValid = 1, HRName = r.RoomName ?? String.Empty, HROutType = 2, HRPersonCount = 0, HRRoomSIze = r.Description ?? string.Empty, HRUpdateName = string.Empty, HRUpdateTime = new DateTime(2000, 1, 1), HRWindowsType = 0//需要转化 }; oldRoom.Id = (int)roomDb.Add(oldRoom); logDb.AddLog(x.Id, $"喜玩新增房型:{hotel.HotelId}:{hotel.HotelName}:{r.RoomTypeId}", ResourceLogType.RoomAdd); } else {//修改暂时不弄 if (oldRoom.HRBedType == 0) { roomDb.Update().Set(rr => rr.HRBedType == GetBedType(r.RoomName, r.BedType)) .Set(rr => rr.HRBedSize == GetBedSize(r.RoomName, r.BedType)) .Where(rr => rr.Id == oldRoom.Id).Execute(); logDb.AddLog(x.Id, $"喜玩更新房型床型:{hotel.HotelId}:{hotel.HotelName}:{r.RoomTypeId}", ResourceLogType.RoomUpdate); } } if (oldRoom.Id > 0) { var rrDb = new H_HotelRoomRuleAccess(); //价格策略 var oldRule = rrDb.Query().Where(rr => rr.HRId == oldRoom.Id && rr.HRROutCode == r.RoomId && rr.HRROutType == 2).FirstOrDefault(); if (oldRule == null || oldRule.Id <= 0) { oldRule = new H_HotelRoomRuleModel { Id = 0, HRROutCode = r.RoomId, HRRXwProductSerial = r.ProductSerial, HIId = x.Id, HRId = oldRoom.Id, HRRAddName = "喜玩新增", HRRAddTime = DateTime.Now, HRRBreakfastRule = 0, HRRBreakfastRuleName = string.Empty, HRRCancelRule = 0, HRRCancelRuleName = string.Empty, HRRIsValid = 1, HRRName = r.RoomName ?? String.Empty, HRROutId = 0, HRROutType = 2, HRRSourceId = 10103, HRRSourceName = "代理", HRRSupplierId = 2, HRRSupplierName = "喜玩", HRRUpdateName = string.Empty, HRRUpdateTime = new DateTime(2000, 1, 1), }; oldRule.Id = (int)rrDb.Add(oldRule); logDb.AddLog(x.Id, $"喜玩新增策略:{hotel.HotelId}:{hotel.HotelName}:{r.RoomId}", ResourceLogType.RuleAdd); } else { var sql = rrDb.Update().Where(rr => rr.Id == oldRule.Id); sql.Set(rr => rr.HRRXwProductSerial == r.ProductSerial && rr.HRRUpdateName == "喜玩更新" && rr.HRRIsValid == 1 && rr.HRRUpdateTime == DateTime.Now ).Execute(); logDb.AddLog(x.Id, $"喜玩更新策略:{hotel.HotelId}:{hotel.HotelName}:{r.RoomId}", ResourceLogType.RuleUpdate); } if (oldRule.Id > 0) { var pDb = new H_HoteRulePriceAccess(); r.Rates?.ForEach(p => { var dateInit = ConvertHelper.ToInt32(p.Date.ToString("yyyyMMdd"), 0); var price = pDb.Query().Where(pr => pr.HRRId == oldRule.Id && pr.HRPDateInt == dateInit).FirstOrDefault(); if (price == null || price.Id <= 0) {//新增价格和库存 price = new H_HoteRulePriceModel { Id = 0, HIId = x.Id, HRId = oldRoom.Id, HRPAddName = "喜玩新增", HRPAddTime = DateTime.Now, HRPContractPrice = p.Price, HRPDate = p.Date, HRPCount = p.AvailableNum == 0 && p.Status ? 5 : p.AvailableNum, HRPDateInt = dateInit, HRPIsValid = 1, HRPRetainCount = 0, HRPSellPrice = p.Price, HRPStatus = 1, HRPUpdateName = string.Empty, HRPUpdateTime = new DateTime(2000, 1, 1), HRRId = oldRule.Id }; price.Id = (int)pDb.Add(price); logDb.AddLog(x.Id, $"喜玩新增价格:{hotel.HotelId}:{hotel.HotelName}:{r.RoomId}:{p.Price}:{price.HRPCount}:{price.HRPDateInt}", ResourceLogType.PriceAdd); } else { var sql = pDb.Update().Where(pr => pr.Id == price.Id); sql.Set(pr => pr.HRPCount == (p.AvailableNum == 0 && p.Status ? 5 : p.AvailableNum)); sql.Set(pr => pr.HRPContractPrice == p.Price && pr.HRPIsValid == (p.Status ? 1 : 0) && pr.HRPSellPrice == p.Price && pr.HRPUpdateName == "喜玩更新" && pr.HRPUpdateTime == DateTime.Now ).Execute(); logDb.AddLog(x.Id, $"喜玩更新价格:{hotel.HotelId}:{hotel.HotelName}:{r.RoomId}:{p.Price}:{price.HRPCount}:{price.HRPDateInt}", ResourceLogType.PriceUpdate); } OpenApi.AddRuleInfo(x.Id, oldRoom.Id, p.BreakfastNum, price.Id, p.Status ? 1 : 0); OpenApi.SysInfo(x.Id); }); } } }); var outRoomIds = hotel?.Rooms?.Select(r => r.RoomTypeId.ToInt()).ToList() ?? new List <int>(); //接口返回的房型Id var dbRooms = roomDb.Query().Where(rd => rd.HIId == x.Id).ToList(); var errDbRooms = dbRooms?.Where(rd => !outRoomIds.Contains(rd.HROutId))?.ToList(); if (errDbRooms != null && errDbRooms.Any()) { LogHelper.Info("待无效房型id:" + JsonHelper.ToJson(errDbRooms) + "|| 更新时间:" + DateTime.Now.ToString(), "喜玩更新无效房型"); } errDbRooms?.ForEach(err => { //更新房型无效 roomDb.Update().Set(rr => rr.HRIsValid == 0) .Where(rr => rr.Id == err.Id).Execute(); var pDb = new H_HoteRulePriceAccess(); //查询价格Id var errDbPrice = pDb.Query().Where(pr => pr.HRId == err.Id).ToList(); //更新库存为0 var sql = pDb.Update().Where(pr => pr.HRId == err.Id); sql.Set(pr => pr.HRPCount == 0 && pr.HRPIsValid == 0 && pr.HRPUpdateName == "喜玩更新" && pr.HRPUpdateTime == DateTime.Now ).Execute(); //同步价格策略 errDbPrice.ForEach(pr => { OpenApi.AddRuleInfo(x.Id, err.Id, 0, pr.Id, 0); }); logDb.AddLog(x.Id, $"喜玩更新房型无效:{hotel.HotelId}:{hotel.HotelName}:{err.HROutId}", ResourceLogType.RoomDelete); }); //同步房型 OpenApi.AddRoomInfo(x.Id); } } else {//查询不到酒店信息无效 hDb.Update().Where(h => h.Id == x.Id) .Set(h => h.HIIsValid == 0 && h.HIUpdateName == "喜玩酒店无信息更新" && h.HIUpdateTime == DateTime.Now) .Execute(); OpenApi.HotelOffline(x.Id, 0); logDb.AddLog(x.Id, $"喜玩酒店无信息更新:{hotel.HotelId}:{hotel.HotelName}:{x.HIOutId}", ResourceLogType.HotelDelete); rtn.Message += $"[无效]"; } }); return(rtn); }