/// <summary> /// 添加分享红包组 /// </summary> /// <param name="userId"></param> /// <returns></returns> public static async Task <Tuhu.Service.Activity.Models.Response.FightGroupPacketListResponse> InsertFightGroupsPacket(Guid userId) { try { Guid fightGroupsIdentity = Guid.NewGuid(); List <FightGroupsPacketsLogModel> list = new List <FightGroupsPacketsLogModel>() { new FightGroupsPacketsLogModel() { CreateDateTime = DateTime.Now, FightGroupsIdentity = fightGroupsIdentity, IsLeader = true, LastUpdateDateTime = DateTime.Now, OrderBy = 1, UserId = userId }, new FightGroupsPacketsLogModel() { CreateDateTime = DateTime.Now, FightGroupsIdentity = fightGroupsIdentity, IsLeader = false, LastUpdateDateTime = DateTime.Now, OrderBy = 2 }, new FightGroupsPacketsLogModel() { CreateDateTime = DateTime.Now, FightGroupsIdentity = fightGroupsIdentity, IsLeader = false, LastUpdateDateTime = DateTime.Now, OrderBy = 3 }, new FightGroupsPacketsLogModel() { CreateDateTime = DateTime.Now, FightGroupsIdentity = fightGroupsIdentity, IsLeader = false, LastUpdateDateTime = DateTime.Now, OrderBy = 4 } }; List <string> array = System.Configuration.ConfigurationManager.AppSettings["FightGroupsGuids"]?.ToString()?.Split(',')?.ToList(); foreach (var item in list) { Random random = new Random(Guid.NewGuid().GetHashCode()); int index = random.Next(0, array.Count); item.GetRuleGuid = Guid.Parse(array[index]); array.Remove(array[index]); } var result = await DalFightGroupsPacketsLog.InsertFightGroupsPacket(list); using (var client = CacheHelper.CreateCacheClient(FightGroupPacketsListRedisKey)) { await client.SetAsync <List <FightGroupsPacketsLogModel> >(fightGroupsIdentity.ToString(), list, TimeSpan.FromDays(1)); await client.SetAsync <List <FightGroupsPacketsLogModel> >(list?.Where(_ => _.IsLeader == true)?.FirstOrDefault()?.UserId?.ToString(), list, TimeSpan.FromDays(1)); } Tuhu.Service.Activity.Models.Response.FightGroupPacketListResponse responseModel = new FightGroupPacketListResponse() { EndDateTask = ConvertDateTimeLong(list?.FirstOrDefault()?.CreateDateTime.AddDays(1)), Items = list, ProvideCount = list?.Where(_ => _.UserId != null)?.Count() }; return(responseModel); } catch (Exception em) { Logger.ErrorException("创建分享红包组失败", em); return(null); } }
/// <summary> /// 获取分享红包组列表 /// </summary> /// <param name="fightGroupsIdentity"></param> /// <returns></returns> public static async Task <Tuhu.Service.Activity.Models.Response.FightGroupPacketListResponse> GetFightGroupsPacketsList(Guid?fightGroupsIdentity, Guid userId) { using (var client = CacheHelper.CreateCacheClient(FightGroupPacketsListRedisKey)) { if (fightGroupsIdentity == null) { var resultIng = await client.GetOrSetAsync <List <FightGroupsPacketsLogModel> >(userId.ToString(), async() => await DalFightGroupsPacketsLog.SelectFightGroupsPacketByUser(userId), TimeSpan.FromDays(1)); if (resultIng?.Value == null || resultIng?.Value?.Count <= 0) { return(null); } Tuhu.Service.Activity.Models.Response.FightGroupPacketListResponse repModel = new FightGroupPacketListResponse() { EndDateTask = ConvertDateTimeLong(resultIng?.Value?.FirstOrDefault()?.CreateDateTime.AddDays(1)), Items = resultIng?.Value, ProvideCount = resultIng?.Value?.Where(_ => _.UserId != null)?.Count() }; return(repModel); } else { var result = await client.GetOrSetAsync <List <FightGroupsPacketsLogModel> >(fightGroupsIdentity.Value.ToString(), async() => await DalFightGroupsPacketsLog.GetFightGroupsPacketsList(fightGroupsIdentity.Value), TimeSpan.FromDays(1)); if (result.Value == null || result?.Value?.Count <= 0) { await client.RemoveAsync(fightGroupsIdentity.Value.ToString()); result = await client.GetOrSetAsync <List <FightGroupsPacketsLogModel> >(fightGroupsIdentity.Value.ToString(), async() => await DalFightGroupsPacketsLog.GetFightGroupsPacketsList(fightGroupsIdentity.Value), TimeSpan.FromDays(1)); } if (result.Value == null || result?.Value?.Count <= 0) { return(null); } Tuhu.Service.Activity.Models.Response.FightGroupPacketListResponse responseModel = new FightGroupPacketListResponse() { EndDateTask = ConvertDateTimeLong(result?.Value?.FirstOrDefault()?.CreateDateTime.AddDays(1)), Items = result?.Value, ProvideCount = result?.Value?.Where(_ => _.UserId != null)?.Count() }; return(responseModel); } } }