/// <summary> /// 单酒店处理房型价格 /// </summary> /// <param name="hotel"></param> private static DataResult SetRoomRate(H_HotelInfoModel hotel, DateTime start, int top) { var result = new DataResult(); result.Data = string.Empty; result.Message = $"{hotel.Id}-{hotel.HIName}-"; start = start.Year <= 2000 ? DateTime.Now : start; var roomdb = new H_HotelRoomAccess(); var roomType = roomdb.Query().Where(x => x.HIId == hotel.Id && x.HROutType == 1).ToList(); roomType?.ForEach(x => { try { var priceRtn = GetYdPrice(hotel.HIOutId, start, top, x); //价格 var storeRtn = GetYdStore(hotel.HIOutId, start, top, x); //库存 if (priceRtn != null && priceRtn.result != null) { var rrDb = new H_HotelRoomRuleAccess(); var pDb = new H_HoteRulePriceAccess(); priceRtn.result.ForEach(p => { var oldRule = rrDb.Query().Where(rr => rr.HRROutId == p.roomTypeId && rr.HRROutType == 1 && rr.HIId == hotel.Id && rr.HRRName == p.roomRateTypeName ).FirstOrDefault(); var newStore = storeRtn?.result?.FirstOrDefault(ns => ns.roomTypeId == p.roomTypeId && ns.accDate == p.accDate); if (oldRule == null) { oldRule = new H_HotelRoomRuleModel { HRRName = p.roomRateTypeName ?? string.Empty, HRROutId = p.roomTypeId, HRRIsValid = 1, HRROutType = 1, HIId = hotel.Id, Id = 0, HRId = x.Id, HRRAddName = "亚朵新增", HRRAddTime = DateTime.Now, HRRBreakfastRule = 0, HRRBreakfastRuleName = string.Empty, HRRCancelRule = 0, HRRCancelRuleName = string.Empty, HRRSourceId = 10104, HRRSourceName = "集团直连", HRRSupplierId = 1, HRRSupplierName = "亚朵集团", HRRUpdateName = string.Empty, HRRUpdateTime = DateTime.Now }; oldRule.Id = (int)rrDb.Add(oldRule); logDb.AddLog(hotel.Id, $"亚朵新增策略:{hotel.HIOutId}:{hotel.HIName}:{ p.roomTypeId}", ResourceLogType.RuleAdd); } //else //{ // rrDb.Update().Set(rr => rr.HRRSupplierName == "亚朵集团" && rr.HRRSupplierId == 1).Execute(); //} if (oldRule != null && oldRule.Id > 0) { var date = DateTime.MinValue; DateTime.TryParse(p.accDate, out date); var dateInit = ConvertHelper.ToInt32(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 = hotel.Id, HRId = x.Id, HRPAddName = "亚朵新增", HRPAddTime = DateTime.Now, HRPContractPrice = p.roomRate, HRPDate = date, HRPCount = newStore?.inventoryNum ?? 0, HRPDateInt = dateInit, HRPIsValid = 1, HRPRetainCount = 0, HRPSellPrice = p.roomRate, HRPStatus = 1, HRPUpdateName = string.Empty, HRPUpdateTime = DateTime.Now, HRRId = oldRule.Id }; price.Id = (int)pDb.Add(price); logDb.AddLog(hotel.Id, $"亚朵新增价格:{hotel.HIOutId}:{hotel.HIName}:{ p.roomTypeId}:{p.roomRate }:{newStore?.inventoryNum ?? 0}:{price.HRPDateInt}", ResourceLogType.PriceAdd); } else { var sql = pDb.Update().Where(pr => pr.Id == price.Id); if (newStore != null) { sql.Set(pr => pr.HRPCount == newStore.inventoryNum); } sql.Set(pr => pr.HRPContractPrice == p.roomRate && pr.HRPSellPrice == p.roomRate && pr.HRPUpdateName == "亚朵更新" && pr.HRPUpdateTime == DateTime.Now ).Execute(); logDb.AddLog(hotel.Id, $"亚朵更新价格:{hotel.HIOutId}:{hotel.HIName}:{ p.roomTypeId}:{p.roomRate }:{newStore?.inventoryNum ?? 0}:{price.HRPDateInt}", ResourceLogType.PriceUpdate); } OpenApi.AddRuleInfo(hotel.Id, x.Id, 0, price.Id, 1); OpenApi.SysInfo(x.Id); } }); } else { result.Message += $"{x.Id}-{x.HRName}没有价格数据;"; } } catch (Exception ex) { LogHelper.Error($"{hotel.Id}-{hotel.HIName}-{x.Id}-{x.HRName}", ex); } }); 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); }