refactor: 邀请码逻辑调整,支持双方填写/使用邀请码统计,并移除已被邀请状态字段
This commit is contained in:
@@ -39,12 +39,7 @@ public class CardFlipStatusOutput
|
||||
/// 本周邀请人数
|
||||
/// </summary>
|
||||
public int InvitedCount { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否已被邀请(被邀请后不可再提供邀请码)
|
||||
/// </summary>
|
||||
public bool IsInvited { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 翻牌记录
|
||||
/// </summary>
|
||||
@@ -54,6 +49,11 @@ public class CardFlipStatusOutput
|
||||
/// 下次可翻牌提示
|
||||
/// </summary>
|
||||
public string? NextFlipTip { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 当前用户是否已经填写过邀请码
|
||||
/// </summary>
|
||||
public bool IsFilledInviteCode { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -51,9 +51,8 @@ public class CardFlipService : ApplicationService, ICardFlipService
|
||||
// 统计本周邀请人数
|
||||
var invitedCount = await _inviteCodeManager.GetWeeklyInvitationCountAsync(userId, weekStart);
|
||||
|
||||
// 检查用户是否已被邀请
|
||||
var isInvited = await _inviteCodeManager.IsUserInvitedAsync(userId);
|
||||
|
||||
//当前用户是否已填写过邀请码
|
||||
var isFilledInviteCode = await _inviteCodeManager.IsFilledInviteCodeAsync(userId);
|
||||
var output = new CardFlipStatusOutput
|
||||
{
|
||||
TotalFlips = task?.TotalFlips ?? 0,
|
||||
@@ -63,8 +62,8 @@ public class CardFlipService : ApplicationService, ICardFlipService
|
||||
CanFlip = _cardFlipManager.CanFlipCard(task),
|
||||
MyInviteCode = inviteCode?.Code,
|
||||
InvitedCount = invitedCount,
|
||||
IsInvited = isInvited,
|
||||
FlipRecords = BuildFlipRecords(task)
|
||||
FlipRecords = BuildFlipRecords(task),
|
||||
IsFilledInviteCode = isFilledInviteCode
|
||||
};
|
||||
|
||||
// 生成提示信息
|
||||
@@ -87,7 +86,7 @@ public class CardFlipService : ApplicationService, ICardFlipService
|
||||
// 如果中奖,发放奖励
|
||||
if (result.IsWin)
|
||||
{
|
||||
await GrantRewardAsync(userId, result.RewardAmount, $"翻牌活动第{input.FlipNumber}次中奖");
|
||||
await GrantRewardAsync(userId, result.RewardAmount, $"翻牌活动-序号{input.FlipNumber}中奖");
|
||||
}
|
||||
|
||||
// 构建输出
|
||||
@@ -147,7 +146,6 @@ public class CardFlipService : ApplicationService, ICardFlipService
|
||||
{
|
||||
MyInviteCode = inviteCode?.Code,
|
||||
InvitedCount = invitedCount,
|
||||
IsInvited = inviteCode?.IsUserInvited ?? false,
|
||||
InvitationHistory = invitationHistory.Select(x => new InvitationHistoryItem
|
||||
{
|
||||
InvitedUserName = x.InvitedUserName,
|
||||
@@ -237,10 +235,10 @@ public class CardFlipService : ApplicationService, ICardFlipService
|
||||
{
|
||||
if (status.TotalFlips >= 7)
|
||||
{
|
||||
return $"本周使用他人邀请码可解锁{status.RemainingInviteFlips}次翻牌,且必中大奖!每次中奖最大额度将翻倍!";
|
||||
return $"本周使用他人邀请码或他人使用你的邀请码,可解锁{status.RemainingInviteFlips}次翻牌,且必中大奖!每次中奖最大额度将翻倍!";
|
||||
}
|
||||
|
||||
return $"本周使用他人邀请码可解锁{status.RemainingInviteFlips}次翻牌,必中大奖!每次中奖最大额度将翻倍!";
|
||||
return $"本周使用他人邀请码或他人使用你的邀请码,可解锁{status.RemainingInviteFlips}次翻牌,必中大奖!每次中奖最大额度将翻倍!";
|
||||
}
|
||||
|
||||
return "继续加油!";
|
||||
|
||||
@@ -19,7 +19,6 @@ public class InviteCodeAggregateRoot : FullAuditedAggregateRoot<Guid>
|
||||
{
|
||||
UserId = userId;
|
||||
Code = code;
|
||||
IsUserInvited = false;
|
||||
UsedCount = 0;
|
||||
}
|
||||
|
||||
@@ -33,12 +32,7 @@ public class InviteCodeAggregateRoot : FullAuditedAggregateRoot<Guid>
|
||||
/// </summary>
|
||||
[SugarColumn(Length = 50)]
|
||||
public string Code { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 邀请码拥有者是否已被他人邀请(被邀请后不可再提供邀请码)
|
||||
/// </summary>
|
||||
public bool IsUserInvited { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 被使用次数(统计用,一个邀请码可以被多人使用)
|
||||
/// </summary>
|
||||
@@ -49,12 +43,5 @@ public class InviteCodeAggregateRoot : FullAuditedAggregateRoot<Guid>
|
||||
/// </summary>
|
||||
[SugarColumn(Length = 500, IsNullable = true)]
|
||||
public string? Remark { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 标记用户已被邀请
|
||||
/// </summary>
|
||||
public void MarkUserAsInvited()
|
||||
{
|
||||
IsUserInvited = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -63,14 +63,19 @@ public class InviteCodeManager : DomainService
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 统计用户本周邀请人数(别人填写我的邀请码的次数)
|
||||
/// 统计用户本周邀请人数(别人填写我的邀请码的次数/或者我填写别人邀请码)
|
||||
/// </summary>
|
||||
public async Task<int> GetWeeklyInvitationCountAsync(Guid userId, DateTime weekStart)
|
||||
{
|
||||
return await _invitationRecordRepository._DbQueryable
|
||||
var inviterCount= await _invitationRecordRepository._DbQueryable
|
||||
.Where(x => x.InviterId == userId)
|
||||
.Where(x => x.InvitationTime >= weekStart)
|
||||
.CountAsync();
|
||||
var invitedUserIdCount= await _invitationRecordRepository._DbQueryable
|
||||
.Where(x => x.InvitedUserId == userId)
|
||||
.Where(x => x.InvitationTime >= weekStart)
|
||||
.CountAsync();
|
||||
return inviterCount + invitedUserIdCount;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -118,45 +123,19 @@ public class InviteCodeManager : DomainService
|
||||
{
|
||||
throw new UserFriendlyException("不能使用自己的邀请码");
|
||||
}
|
||||
|
||||
// 验证邀请码拥有者是否已被邀请
|
||||
if (inviteCodeEntity.IsUserInvited)
|
||||
{
|
||||
throw new UserFriendlyException("该用户已被邀请,邀请码无效");
|
||||
}
|
||||
|
||||
|
||||
// 检查当前用户是否已经填写过别人的邀请码(一辈子只能填写一次)
|
||||
var hasUsedOthersCode = await _invitationRecordRepository._DbQueryable
|
||||
.Where(x => x.InvitedUserId == userId)
|
||||
.AnyAsync();
|
||||
var hasUsedOthersCode = await IsFilledInviteCodeAsync(userId);
|
||||
|
||||
if (hasUsedOthersCode)
|
||||
{
|
||||
throw new UserFriendlyException("您已经填写过别人的邀请码了,每个账号只能填写一次");
|
||||
}
|
||||
|
||||
// 检查当前用户的邀请码信息
|
||||
var myInviteCode = await _inviteCodeRepository._DbQueryable
|
||||
.Where(x => x.UserId == userId)
|
||||
.FirstAsync();
|
||||
|
||||
|
||||
// 增加邀请码被使用次数
|
||||
inviteCodeEntity.UsedCount++;
|
||||
await _inviteCodeRepository.UpdateAsync(inviteCodeEntity);
|
||||
|
||||
// 标记当前用户已被邀请(一辈子只能填写一次)
|
||||
if (myInviteCode == null)
|
||||
{
|
||||
myInviteCode = new InviteCodeAggregateRoot(userId, GenerateUniqueInviteCode());
|
||||
myInviteCode.MarkUserAsInvited();
|
||||
await _inviteCodeRepository.InsertAsync(myInviteCode);
|
||||
}
|
||||
else if (!myInviteCode.IsUserInvited)
|
||||
{
|
||||
myInviteCode.MarkUserAsInvited();
|
||||
await _inviteCodeRepository.UpdateAsync(myInviteCode);
|
||||
}
|
||||
|
||||
|
||||
// 创建邀请记录(双方都会因为这条记录增加一次翻牌机会)
|
||||
var invitationRecord = new InvitationRecordAggregateRoot(
|
||||
inviteCodeEntity.UserId,
|
||||
@@ -170,15 +149,14 @@ public class InviteCodeManager : DomainService
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 检查用户是否已被邀请
|
||||
/// 检查用户是否已填写过邀请码
|
||||
/// </summary>
|
||||
public async Task<bool> IsUserInvitedAsync(Guid userId)
|
||||
public async Task<bool> IsFilledInviteCodeAsync(Guid userId)
|
||||
{
|
||||
var inviteCode = await _inviteCodeRepository._DbQueryable
|
||||
.Where(x => x.UserId == userId)
|
||||
.FirstAsync();
|
||||
|
||||
return inviteCode?.IsUserInvited ?? false;
|
||||
// 检查当前用户是否已经填写过别人的邀请码(一辈子只能填写一次)
|
||||
return await _invitationRecordRepository._DbQueryable
|
||||
.Where(x => x.InvitedUserId == userId)
|
||||
.AnyAsync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user