feat: 翻牌与邀请码逻辑重构,新增中奖记录与前7次中奖概率
- CardFlipTaskAggregateRoot.cs
- 用 WinRecords(Dictionary<int,long>) 替代原先第8/9/10次的各自字段,且以 JSON 存库(SugarColumn IsJson)。
- 构造函数初始化 WinRecords。
- 新增 SetWinReward(int flipCount, long amount) 统一记录中奖。
- CardFlipService.cs
- 读取并展示 WinRecords,按翻牌顺序映射中奖信息(不再依赖单独的第8/9/10字段)。
- CardFlipManager.cs
- 重构中奖逻辑:
- 前7次翻牌改为 50% 概率可中奖,奖励范围 1w–3w(新增配置常量 FREE_*)。
- 统一通过 SetWinReward 记录任意次的中奖金额。
- GenerateRandomReward 根据最小值自动选单位(1w 或 100w)。
- 邀请类型翻牌校验由“仅统计被填写次数”改为“统计本周作为邀请人或被邀请人的邀请记录数量”(双方都计入),并据此判断是否可解锁邀请翻牌次数。
- InviteCodeManager.cs
- 使用邀请码时:
- 验证规则调整:一个账号只能填写别人的邀请码一次(hasUsedOthersCode 检查)。
- 邀请记录的语义变化:当使用邀请码时,邀请记录同时代表邀请人和被邀请人各增加一次翻牌机会。
- 不再将邀请码标记为单次已用;改为增加 UsedCount(一个邀请码可以被多人使用)。
- 优化日志与提示信息。
- InviteCodeAggregateRoot.cs
- 移除 IsUsed、UsedTime、UsedByUserId、MarkAsUsed 等单次使用相关字段/方法。
- 保留 IsUserInvited(被邀请后不能再作为被邀请者使用)和 UsedCount(统计多人使用次数)。
注意事项
- 这是数据结构与业务逻辑的变更,数据库表结构发生变化(新增 WinRecords JSON 字段,移除若干字段)。上线前请准备相应的迁移脚本或数据迁移方案,确保历史中奖数据平滑迁移到 WinRecords。
- 变更会影响相关单元/集成测试、前端展示字段,需同步更新对应测试与界面展示逻辑。
This commit is contained in:
@@ -183,6 +183,9 @@ public class CardFlipService : ApplicationService, ICardFlipService
|
|||||||
var flippedOrder = task != null ? _cardFlipManager.GetFlippedOrder(task) : new List<int>();
|
var flippedOrder = task != null ? _cardFlipManager.GetFlippedOrder(task) : new List<int>();
|
||||||
var flippedNumbers = new HashSet<int>(flippedOrder);
|
var flippedNumbers = new HashSet<int>(flippedOrder);
|
||||||
|
|
||||||
|
// 获取中奖记录
|
||||||
|
var winRecords = task?.WinRecords ?? new Dictionary<int, long>();
|
||||||
|
|
||||||
// 构建记录,按照原始序号1-10排列
|
// 构建记录,按照原始序号1-10排列
|
||||||
for (int i = 1; i <= CardFlipManager.TOTAL_MAX_FLIPS; i++)
|
for (int i = 1; i <= CardFlipManager.TOTAL_MAX_FLIPS; i++)
|
||||||
{
|
{
|
||||||
@@ -202,23 +205,11 @@ public class CardFlipService : ApplicationService, ICardFlipService
|
|||||||
{
|
{
|
||||||
var flipOrderIndex = flippedOrder.IndexOf(i) + 1; // 第几次翻的(1-based)
|
var flipOrderIndex = flippedOrder.IndexOf(i) + 1; // 第几次翻的(1-based)
|
||||||
|
|
||||||
// 第8次翻的卡中奖
|
// 检查这次翻牌是否中奖
|
||||||
if (flipOrderIndex == 8)
|
if (winRecords.TryGetValue(flipOrderIndex, out var rewardAmount))
|
||||||
{
|
{
|
||||||
record.IsWin = true;
|
record.IsWin = true;
|
||||||
record.RewardAmount = task.EighthRewardAmount;
|
record.RewardAmount = rewardAmount;
|
||||||
}
|
|
||||||
// 第9次翻的卡中奖
|
|
||||||
else if (flipOrderIndex == 9)
|
|
||||||
{
|
|
||||||
record.IsWin = true;
|
|
||||||
record.RewardAmount = task.NinthRewardAmount;
|
|
||||||
}
|
|
||||||
// 第10次翻的卡中奖
|
|
||||||
else if (flipOrderIndex == 10)
|
|
||||||
{
|
|
||||||
record.IsWin = true;
|
|
||||||
record.RewardAmount = task.TenthRewardAmount;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -25,9 +25,8 @@ public class CardFlipTaskAggregateRoot : FullAuditedAggregateRoot<Guid>
|
|||||||
BonusFlipsUsed = 0;
|
BonusFlipsUsed = 0;
|
||||||
InviteFlipsUsed = 0;
|
InviteFlipsUsed = 0;
|
||||||
IsFirstFlipDone = false;
|
IsFirstFlipDone = false;
|
||||||
HasNinthReward = false;
|
|
||||||
HasTenthReward = false;
|
|
||||||
FlippedOrder = new List<int>();
|
FlippedOrder = new List<int>();
|
||||||
|
WinRecords = new Dictionary<int, long>();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -66,34 +65,10 @@ public class CardFlipTaskAggregateRoot : FullAuditedAggregateRoot<Guid>
|
|||||||
public bool IsFirstFlipDone { get; set; }
|
public bool IsFirstFlipDone { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 是否已获得第8次奖励
|
/// 中奖记录(以翻牌顺序为key,例如第1次翻牌中奖则key为1,奖励金额为value)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool HasEighthReward { get; set; }
|
[SugarColumn(IsJson = true, IsNullable = true)]
|
||||||
|
public Dictionary<int, long>? WinRecords { get; set; }
|
||||||
/// <summary>
|
|
||||||
/// 第8次奖励金额(100-300w)
|
|
||||||
/// </summary>
|
|
||||||
public long? EighthRewardAmount { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 是否已获得第9次奖励
|
|
||||||
/// </summary>
|
|
||||||
public bool HasNinthReward { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 第9次奖励金额(100-500w)
|
|
||||||
/// </summary>
|
|
||||||
public long? NinthRewardAmount { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 是否已获得第10次奖励
|
|
||||||
/// </summary>
|
|
||||||
public bool HasTenthReward { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 第10次奖励金额(100-1000w)
|
|
||||||
/// </summary>
|
|
||||||
public long? TenthRewardAmount { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 备注信息
|
/// 备注信息
|
||||||
@@ -135,33 +110,17 @@ public class CardFlipTaskAggregateRoot : FullAuditedAggregateRoot<Guid>
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 记录第8次奖励
|
/// 记录中奖
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
/// <param name="flipCount">第几次翻牌(1-10)</param>
|
||||||
/// <param name="amount">奖励金额</param>
|
/// <param name="amount">奖励金额</param>
|
||||||
public void SetEighthReward(long amount)
|
public void SetWinReward(int flipCount, long amount)
|
||||||
{
|
{
|
||||||
HasEighthReward = true;
|
if (WinRecords == null)
|
||||||
EighthRewardAmount = amount;
|
{
|
||||||
}
|
WinRecords = new Dictionary<int, long>();
|
||||||
|
}
|
||||||
/// <summary>
|
WinRecords[flipCount] = amount;
|
||||||
/// 记录第9次奖励
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="amount">奖励金额</param>
|
|
||||||
public void SetNinthReward(long amount)
|
|
||||||
{
|
|
||||||
HasNinthReward = true;
|
|
||||||
NinthRewardAmount = amount;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 记录第10次奖励
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="amount">奖励金额</param>
|
|
||||||
public void SetTenthReward(long amount)
|
|
||||||
{
|
|
||||||
HasTenthReward = true;
|
|
||||||
TenthRewardAmount = amount;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -19,7 +19,6 @@ public class InviteCodeAggregateRoot : FullAuditedAggregateRoot<Guid>
|
|||||||
{
|
{
|
||||||
UserId = userId;
|
UserId = userId;
|
||||||
Code = code;
|
Code = code;
|
||||||
IsUsed = false;
|
|
||||||
IsUserInvited = false;
|
IsUserInvited = false;
|
||||||
UsedCount = 0;
|
UsedCount = 0;
|
||||||
}
|
}
|
||||||
@@ -35,49 +34,22 @@ public class InviteCodeAggregateRoot : FullAuditedAggregateRoot<Guid>
|
|||||||
[SugarColumn(Length = 50)]
|
[SugarColumn(Length = 50)]
|
||||||
public string Code { get; set; } = string.Empty;
|
public string Code { get; set; } = string.Empty;
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 是否已被使用(一个邀请码只能被使用一次)
|
|
||||||
/// </summary>
|
|
||||||
public bool IsUsed { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 邀请码拥有者是否已被他人邀请(被邀请后不可再提供邀请码)
|
/// 邀请码拥有者是否已被他人邀请(被邀请后不可再提供邀请码)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool IsUserInvited { get; set; }
|
public bool IsUserInvited { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 被使用次数(统计用)
|
/// 被使用次数(统计用,一个邀请码可以被多人使用)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int UsedCount { get; set; }
|
public int UsedCount { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 使用时间
|
|
||||||
/// </summary>
|
|
||||||
public DateTime? UsedTime { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 使用人ID
|
|
||||||
/// </summary>
|
|
||||||
public Guid? UsedByUserId { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 备注信息
|
/// 备注信息
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[SugarColumn(Length = 500, IsNullable = true)]
|
[SugarColumn(Length = 500, IsNullable = true)]
|
||||||
public string? Remark { get; set; }
|
public string? Remark { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 标记邀请码已被使用
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="usedByUserId">使用者ID</param>
|
|
||||||
public void MarkAsUsed(Guid usedByUserId)
|
|
||||||
{
|
|
||||||
IsUsed = true;
|
|
||||||
UsedTime = DateTime.Now;
|
|
||||||
UsedByUserId = usedByUserId;
|
|
||||||
UsedCount++;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 标记用户已被邀请
|
/// 标记用户已被邀请
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -24,6 +24,11 @@ public class CardFlipManager : DomainService
|
|||||||
private const int NINTH_FLIP = 9; // 第9次翻牌
|
private const int NINTH_FLIP = 9; // 第9次翻牌
|
||||||
private const int TENTH_FLIP = 10; // 第10次翻牌
|
private const int TENTH_FLIP = 10; // 第10次翻牌
|
||||||
|
|
||||||
|
// 前7次免费翻牌奖励配置
|
||||||
|
private const long FREE_MIN_REWARD = 10000; // 前7次最小奖励 1w
|
||||||
|
private const long FREE_MAX_REWARD = 30000; // 前7次最大奖励 3w
|
||||||
|
private const double FREE_WIN_RATE = 0.5; // 前7次中奖概率 50%
|
||||||
|
|
||||||
private const long EIGHTH_MIN_REWARD = 1000000; // 第8次最小奖励 100w
|
private const long EIGHTH_MIN_REWARD = 1000000; // 第8次最小奖励 100w
|
||||||
private const long EIGHTH_MAX_REWARD = 3000000; // 第8次最大奖励 300w
|
private const long EIGHTH_MAX_REWARD = 3000000; // 第8次最大奖励 300w
|
||||||
private const long NINTH_MIN_REWARD = 1000000; // 第9次最小奖励 100w
|
private const long NINTH_MIN_REWARD = 1000000; // 第9次最小奖励 100w
|
||||||
@@ -112,23 +117,23 @@ public class CardFlipManager : DomainService
|
|||||||
throw new UserFriendlyException(GetFlipTypeErrorMessage(flipType));
|
throw new UserFriendlyException(GetFlipTypeErrorMessage(flipType));
|
||||||
}
|
}
|
||||||
|
|
||||||
// 如果是邀请类型翻牌,必须验证用户本周填写的邀请码数量足够
|
// 如果是邀请类型翻牌,必须验证用户本周的邀请记录数量足够(包括填写别人的邀请码和别人填写我的邀请码)
|
||||||
if (flipType == FlipType.Invite)
|
if (flipType == FlipType.Invite)
|
||||||
{
|
{
|
||||||
// 查询本周已使用的邀请码数量
|
// 查询本周作为邀请人或被邀请人的记录数量(双方都会增加翻牌次数)
|
||||||
var weeklyInviteCodeUsedCount = await _invitationRecordRepository._DbQueryable
|
var weeklyInviteRecordCount = await _invitationRecordRepository._DbQueryable
|
||||||
.Where(x => x.InvitedUserId == userId)
|
.Where(x => x.InviterId == userId || x.InvitedUserId == userId)
|
||||||
.Where(x => x.InvitationTime >= weekStart)
|
.Where(x => x.InvitationTime >= weekStart)
|
||||||
.CountAsync();
|
.CountAsync();
|
||||||
|
|
||||||
// 本周填写的邀请码数量必须 >= 即将使用的邀请翻牌次数
|
// 本周邀请记录数量必须 >= 即将使用的邀请翻牌次数
|
||||||
// 例如: 要翻第8次(InviteFlipsUsed=0->1), 需要至少填写了1个邀请码
|
// 例如: 要翻第8次(InviteFlipsUsed=0->1), 需要至少有1条邀请记录(我邀请别人或别人邀请我)
|
||||||
// 要翻第9次(InviteFlipsUsed=1->2), 需要至少填写了2个邀请码
|
// 要翻第9次(InviteFlipsUsed=1->2), 需要至少有2条邀请记录
|
||||||
// 要翻第10次(InviteFlipsUsed=2->3), 需要至少填写了3个邀请码
|
// 要翻第10次(InviteFlipsUsed=2->3), 需要至少有3条邀请记录
|
||||||
var requiredInviteCodeCount = task.InviteFlipsUsed + 1;
|
var requiredInviteRecordCount = task.InviteFlipsUsed + 1;
|
||||||
if (weeklyInviteCodeUsedCount < requiredInviteCodeCount)
|
if (weeklyInviteRecordCount < requiredInviteRecordCount)
|
||||||
{
|
{
|
||||||
throw new UserFriendlyException($"需本周累积使用{requiredInviteCodeCount}个他人邀请码才能解锁第{task.TotalFlips + 1}次翻牌,您还差一个~");
|
throw new UserFriendlyException($"需本周累积{requiredInviteRecordCount}次邀请记录(填写别人的邀请码或别人填写你的邀请码)才能解锁第{task.TotalFlips + 1}次翻牌");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -152,18 +157,7 @@ public class CardFlipManager : DomainService
|
|||||||
// 如果中奖,记录奖励金额(用于后续查询显示)
|
// 如果中奖,记录奖励金额(用于后续查询显示)
|
||||||
if (result.IsWin)
|
if (result.IsWin)
|
||||||
{
|
{
|
||||||
if (flipCount == EIGHTH_FLIP)
|
task.SetWinReward(flipCount, result.RewardAmount);
|
||||||
{
|
|
||||||
task.SetEighthReward(result.RewardAmount);
|
|
||||||
}
|
|
||||||
else if (flipCount == NINTH_FLIP)
|
|
||||||
{
|
|
||||||
task.SetNinthReward(result.RewardAmount);
|
|
||||||
}
|
|
||||||
else if (flipCount == TENTH_FLIP)
|
|
||||||
{
|
|
||||||
task.SetTenthReward(result.RewardAmount);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
await _cardFlipTaskRepository.UpdateAsync(task);
|
await _cardFlipTaskRepository.UpdateAsync(task);
|
||||||
@@ -223,11 +217,24 @@ public class CardFlipManager : DomainService
|
|||||||
IsWin = false
|
IsWin = false
|
||||||
};
|
};
|
||||||
|
|
||||||
// 前7次固定失败
|
var random = new Random();
|
||||||
|
|
||||||
|
// 前7次: 50%概率中奖,奖励1w-3w
|
||||||
if (flipCount <= 7)
|
if (flipCount <= 7)
|
||||||
{
|
{
|
||||||
result.IsWin = false;
|
// 50%概率中奖
|
||||||
result.RewardDesc = "很遗憾,未中奖";
|
if (random.NextDouble() < FREE_WIN_RATE)
|
||||||
|
{
|
||||||
|
var rewardAmount = GenerateRandomReward(FREE_MIN_REWARD, FREE_MAX_REWARD);
|
||||||
|
result.IsWin = true;
|
||||||
|
result.RewardAmount = rewardAmount;
|
||||||
|
result.RewardDesc = $"恭喜获得尊享包 {rewardAmount / 10000m:0.##}w tokens!";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
result.IsWin = false;
|
||||||
|
result.RewardDesc = "很遗憾,未中奖";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// 第8次中奖 (邀请码解锁)
|
// 第8次中奖 (邀请码解锁)
|
||||||
else if (flipCount == EIGHTH_FLIP)
|
else if (flipCount == EIGHTH_FLIP)
|
||||||
@@ -271,21 +278,24 @@ public class CardFlipManager : DomainService
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 生成随机奖励金额 (最小单位100w)
|
/// 生成随机奖励金额
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private long GenerateRandomReward(long min, long max)
|
private long GenerateRandomReward(long min, long max)
|
||||||
{
|
{
|
||||||
var random = new Random();
|
var random = new Random();
|
||||||
const long unit = 1000000; // 100w的单位
|
|
||||||
|
|
||||||
// 将min和max转换为100w的倍数
|
// 根据最小值判断单位
|
||||||
|
// 如果min小于100000,则使用1w(10000)作为单位;否则使用100w(1000000)作为单位
|
||||||
|
long unit = min < 100000 ? 10000 : 1000000;
|
||||||
|
|
||||||
|
// 将min和max转换为单位的倍数
|
||||||
long minUnits = min / unit;
|
long minUnits = min / unit;
|
||||||
long maxUnits = max / unit;
|
long maxUnits = max / unit;
|
||||||
|
|
||||||
// 在倍数范围内随机
|
// 在倍数范围内随机
|
||||||
long randomUnits = random.Next((int)minUnits, (int)maxUnits + 1);
|
long randomUnits = random.Next((int)minUnits, (int)maxUnits + 1);
|
||||||
|
|
||||||
// 返回100w的倍数
|
// 返回单位的倍数
|
||||||
return randomUnits * unit;
|
return randomUnits * unit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -63,12 +63,12 @@ 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
|
return await _invitationRecordRepository._DbQueryable
|
||||||
.Where(x => x.InvitedUserId == userId)
|
.Where(x => x.InviterId == userId)
|
||||||
.Where(x => x.InvitationTime >= weekStart)
|
.Where(x => x.InvitationTime >= weekStart)
|
||||||
.CountAsync();
|
.CountAsync();
|
||||||
}
|
}
|
||||||
@@ -91,7 +91,7 @@ public class InviteCodeManager : DomainService
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 使用邀请码
|
/// 使用邀请码(双方都增加翻牌次数)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="userId">使用者ID</param>
|
/// <param name="userId">使用者ID</param>
|
||||||
/// <param name="inviteCode">邀请码</param>
|
/// <param name="inviteCode">邀请码</param>
|
||||||
@@ -119,28 +119,20 @@ public class InviteCodeManager : DomainService
|
|||||||
throw new UserFriendlyException("不能使用自己的邀请码");
|
throw new UserFriendlyException("不能使用自己的邀请码");
|
||||||
}
|
}
|
||||||
|
|
||||||
// 验证邀请码是否已被使用
|
|
||||||
if (inviteCodeEntity.IsUsed)
|
|
||||||
{
|
|
||||||
throw new UserFriendlyException("该邀请码已被使用");
|
|
||||||
}
|
|
||||||
|
|
||||||
// 验证邀请码拥有者是否已被邀请
|
// 验证邀请码拥有者是否已被邀请
|
||||||
if (inviteCodeEntity.IsUserInvited)
|
if (inviteCodeEntity.IsUserInvited)
|
||||||
{
|
{
|
||||||
throw new UserFriendlyException("该用户已被邀请,邀请码无效");
|
throw new UserFriendlyException("该用户已被邀请,邀请码无效");
|
||||||
}
|
}
|
||||||
|
|
||||||
// 验证本周邀请码使用次数
|
// 检查当前用户是否已经填写过别人的邀请码(一辈子只能填写一次)
|
||||||
var weekStart = CardFlipManager.GetWeekStartDate(DateTime.Now);
|
var hasUsedOthersCode = await _invitationRecordRepository._DbQueryable
|
||||||
var weeklyUseCount = await _invitationRecordRepository._DbQueryable
|
|
||||||
.Where(x => x.InvitedUserId == userId)
|
.Where(x => x.InvitedUserId == userId)
|
||||||
.Where(x => x.InvitationTime >= weekStart)
|
.AnyAsync();
|
||||||
.CountAsync();
|
|
||||||
|
|
||||||
if (weeklyUseCount >= CardFlipManager.MAX_INVITE_FLIPS)
|
if (hasUsedOthersCode)
|
||||||
{
|
{
|
||||||
throw new UserFriendlyException($"本周邀请码使用次数已达上限({CardFlipManager.MAX_INVITE_FLIPS}次),请下周再来");
|
throw new UserFriendlyException("您已经填写过别人的邀请码了,每个账号只能填写一次");
|
||||||
}
|
}
|
||||||
|
|
||||||
// 检查当前用户的邀请码信息
|
// 检查当前用户的邀请码信息
|
||||||
@@ -148,11 +140,11 @@ public class InviteCodeManager : DomainService
|
|||||||
.Where(x => x.UserId == userId)
|
.Where(x => x.UserId == userId)
|
||||||
.FirstAsync();
|
.FirstAsync();
|
||||||
|
|
||||||
// 标记邀请码为已使用
|
// 增加邀请码被使用次数
|
||||||
inviteCodeEntity.MarkAsUsed(userId);
|
inviteCodeEntity.UsedCount++;
|
||||||
await _inviteCodeRepository.UpdateAsync(inviteCodeEntity);
|
await _inviteCodeRepository.UpdateAsync(inviteCodeEntity);
|
||||||
|
|
||||||
// 标记当前用户已被邀请(仅第一次使用邀请码时标记)
|
// 标记当前用户已被邀请(一辈子只能填写一次)
|
||||||
if (myInviteCode == null)
|
if (myInviteCode == null)
|
||||||
{
|
{
|
||||||
myInviteCode = new InviteCodeAggregateRoot(userId, GenerateUniqueInviteCode());
|
myInviteCode = new InviteCodeAggregateRoot(userId, GenerateUniqueInviteCode());
|
||||||
@@ -165,14 +157,14 @@ public class InviteCodeManager : DomainService
|
|||||||
await _inviteCodeRepository.UpdateAsync(myInviteCode);
|
await _inviteCodeRepository.UpdateAsync(myInviteCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 创建邀请记录
|
// 创建邀请记录(双方都会因为这条记录增加一次翻牌机会)
|
||||||
var invitationRecord = new InvitationRecordAggregateRoot(
|
var invitationRecord = new InvitationRecordAggregateRoot(
|
||||||
inviteCodeEntity.UserId,
|
inviteCodeEntity.UserId,
|
||||||
userId,
|
userId,
|
||||||
inviteCode);
|
inviteCode);
|
||||||
await _invitationRecordRepository.InsertAsync(invitationRecord);
|
await _invitationRecordRepository.InsertAsync(invitationRecord);
|
||||||
|
|
||||||
_logger.LogInformation($"用户 {userId} 使用邀请码 {inviteCode} 成功");
|
_logger.LogInformation($"用户 {userId} 使用邀请码 {inviteCode} 成功,邀请人 {inviteCodeEntity.UserId} 和被邀请人 {userId} 都增加一次翻牌机会");
|
||||||
|
|
||||||
return inviteCodeEntity.UserId;
|
return inviteCodeEntity.UserId;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user