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