/// <summary> /// 更新分享红包组中的用户 /// </summary> /// <param name="pkid"></param> /// <param name="userId"></param> /// <returns></returns> public static async Task <OperationResult <bool> > UpdateFightGroupsPacketByUserId(FightGroupsPacketsUpdateRequest request) { //if (request.PKID <= 0) // return OperationResult.FromError<bool>("0","参数错误"); using (var zookeeperClient = new Tuhu.ZooKeeper.ZooKeeperLock(SecurityHelper.Hash(request.FightGroupsIdentity.ToString()))) { try { if (await zookeeperClient.WaitAsync(3000)) { List <FightGroupsPacketsLogModel> result = new List <FightGroupsPacketsLogModel>(); using (var client = CacheHelper.CreateCacheClient(FightGroupPacketsListRedisKey)) { var response = await client.GetOrSetAsync <List <FightGroupsPacketsLogModel> >(request.FightGroupsIdentity.ToString(), async() => await DalFightGroupsPacketsLog.GetFightGroupsPacketsList(request.FightGroupsIdentity), TimeSpan.FromDays(1)); if (response?.Value == null) { client.Remove(request.FightGroupsIdentity.ToString()); response = await client.GetOrSetAsync <List <FightGroupsPacketsLogModel> >(request.FightGroupsIdentity.ToString(), async() => await DalFightGroupsPacketsLog.GetFightGroupsPacketsList(request.FightGroupsIdentity), TimeSpan.FromDays(1)); } result = response?.Value; if (result?.Count(x => x.UserId == null || x.UserId.Value == Guid.Empty) == 0) { return(OperationResult.FromError <bool>("-1", "该红包组已领取完毕")); } if (result.Where(_ => _.UserId == request.UserId)?.Count() > 0) { return(OperationResult.FromError <bool>("-2", "该用户已经领取")); } } var groupLeader = result?.Where(_ => _.IsLeader == true)?.FirstOrDefault()?.UserId.ToString(); using (var client = CacheHelper.CreateCounterClient( "UpdateFightGroupsPacketByUserId" + groupLeader + request.UserId, TimeSpan.FromDays(7))) { var response = await client.IncrementAsync("UpdateFightGroupsPacketByUserId", 1); if (response.Success && response.Value > 1) { return(OperationResult.FromError <bool>("-3", "7天内无法为同一好友拆红包哦")); } } using (var client = CacheHelper.CreateCacheClient(FightGroupPacketsListRedisKey)) { var resPkid = await DalFightGroupsPacketsLog.UpdateFightGroupsPacketByUserId( request.FightGroupsIdentity, request.UserId); if (resPkid > 0) { var userItem = result?.Where(_ => _.PKID == resPkid)?.FirstOrDefault(); if (userItem != null) { userItem.UserId = request.UserId; } await client.SetAsync <List <FightGroupsPacketsLogModel> >( request.FightGroupsIdentity.ToString(), result); await client.SetAsync <List <FightGroupsPacketsLogModel> >( result?.Where(_ => _.IsLeader == true)?.FirstOrDefault()?.UserId.ToString(), result); return(OperationResult.FromResult(true)); } } } return(OperationResult.FromError <bool>("-3", "更新失败")); } catch (Exception em) { Logger.ErrorException("更新分享红包组中的用户失败", em); return(OperationResult.FromError <bool>("500", em.Message)); } finally { zookeeperClient.Release(); } } }
/// <summary> /// 更新分享组红包中的用户 /// </summary> /// <param name="request"></param> /// <returns></returns> public async Task <OperationResult <bool> > UpdateFightGroupsPacketByUserIdAsync(FightGroupsPacketsUpdateRequest request) => await FightGroupsPacketsManager.UpdateFightGroupsPacketByUserId(request);