feat: 增加邀请码每周使用上限并调整翻牌规则(扩展免费次数、移除赠送翻牌与翻倍提示)
This commit is contained in:
@@ -25,11 +25,6 @@ public class FlipCardOutput
|
||||
/// </summary>
|
||||
public string? RewardDesc { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否显示翻倍包提示(第9次中奖后显示)
|
||||
/// </summary>
|
||||
public bool ShowDoubleRewardTip { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 剩余可翻次数
|
||||
/// </summary>
|
||||
|
||||
@@ -58,7 +58,7 @@ public class CardFlipService : ApplicationService, ICardFlipService
|
||||
{
|
||||
TotalFlips = task?.TotalFlips ?? 0,
|
||||
RemainingFreeFlips = CardFlipManager.MAX_FREE_FLIPS - (task?.FreeFlipsUsed ?? 0),
|
||||
RemainingBonusFlips = CardFlipManager.MAX_BONUS_FLIPS - (task?.BonusFlipsUsed ?? 0),
|
||||
RemainingBonusFlips = 0, // 已废弃
|
||||
RemainingInviteFlips = CardFlipManager.MAX_INVITE_FLIPS - (task?.InviteFlipsUsed ?? 0),
|
||||
CanFlip = _cardFlipManager.CanFlipCard(task),
|
||||
MyInviteCode = inviteCode?.Code,
|
||||
@@ -97,7 +97,6 @@ public class CardFlipService : ApplicationService, ICardFlipService
|
||||
IsWin = result.IsWin,
|
||||
RewardAmount = result.RewardAmount,
|
||||
RewardDesc = result.RewardDesc,
|
||||
ShowDoubleRewardTip = result.ShowDoubleRewardTip,
|
||||
RemainingFlips = CardFlipManager.TOTAL_MAX_FLIPS - input.FlipNumber
|
||||
};
|
||||
|
||||
|
||||
@@ -46,17 +46,17 @@ public class CardFlipTaskAggregateRoot : FullAuditedAggregateRoot<Guid>
|
||||
public int TotalFlips { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 已使用的免费次数(最多5次)
|
||||
/// 已使用的免费次数(最多7次)
|
||||
/// </summary>
|
||||
public int FreeFlipsUsed { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 已使用的赠送次数(最多3次)
|
||||
/// 已使用的赠送次数(已废弃,保持为0)
|
||||
/// </summary>
|
||||
public int BonusFlipsUsed { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 已使用的邀请解锁次数(最多2次)
|
||||
/// 已使用的邀请解锁次数(最多3次)
|
||||
/// </summary>
|
||||
public int InviteFlipsUsed { get; set; }
|
||||
|
||||
@@ -171,17 +171,17 @@ public class CardFlipTaskAggregateRoot : FullAuditedAggregateRoot<Guid>
|
||||
public enum FlipType
|
||||
{
|
||||
/// <summary>
|
||||
/// 免费翻牌(1-5次)
|
||||
/// 免费翻牌(1-7次)
|
||||
/// </summary>
|
||||
Free = 0,
|
||||
|
||||
/// <summary>
|
||||
/// 赠送翻牌(6-8次)
|
||||
/// 赠送翻牌(已废弃)
|
||||
/// </summary>
|
||||
Bonus = 1,
|
||||
|
||||
/// <summary>
|
||||
/// 邀请解锁翻牌(9-10次)
|
||||
/// 邀请解锁翻牌(8-10次)
|
||||
/// </summary>
|
||||
Invite = 2
|
||||
}
|
||||
|
||||
@@ -16,7 +16,6 @@ public class CardFlipManager : DomainService
|
||||
|
||||
// 翻牌规则配置
|
||||
public const int MAX_FREE_FLIPS = 7; // 免费翻牌次数
|
||||
public const int MAX_BONUS_FLIPS = 0; // 赠送翻牌次数(已废弃)
|
||||
public const int MAX_INVITE_FLIPS = 3; // 邀请解锁翻牌次数
|
||||
public const int TOTAL_MAX_FLIPS = 10; // 总最大翻牌次数
|
||||
|
||||
@@ -180,10 +179,6 @@ public class CardFlipManager : DomainService
|
||||
{
|
||||
return FlipType.Free;
|
||||
}
|
||||
else if (task.BonusFlipsUsed < MAX_BONUS_FLIPS)
|
||||
{
|
||||
return FlipType.Bonus;
|
||||
}
|
||||
else
|
||||
{
|
||||
return FlipType.Invite;
|
||||
@@ -198,7 +193,6 @@ public class CardFlipManager : DomainService
|
||||
return flipType switch
|
||||
{
|
||||
FlipType.Free => task.FreeFlipsUsed < MAX_FREE_FLIPS,
|
||||
FlipType.Bonus => task.BonusFlipsUsed < MAX_BONUS_FLIPS,
|
||||
FlipType.Invite => task.InviteFlipsUsed < MAX_INVITE_FLIPS,
|
||||
_ => false
|
||||
};
|
||||
@@ -213,8 +207,7 @@ public class CardFlipManager : DomainService
|
||||
var result = new FlipResult
|
||||
{
|
||||
FlipNumber = 0, // 稍后会被设置为实际的卡片序号
|
||||
IsWin = false,
|
||||
ShowDoubleRewardTip = false
|
||||
IsWin = false
|
||||
};
|
||||
|
||||
// 前7次固定失败
|
||||
@@ -259,7 +252,6 @@ public class CardFlipManager : DomainService
|
||||
return flipType switch
|
||||
{
|
||||
FlipType.Free => "免费翻牌次数已用完",
|
||||
FlipType.Bonus => "赠送翻牌次数已用完",
|
||||
FlipType.Invite => "需要使用邀请码解锁更多次数",
|
||||
_ => "无法翻牌"
|
||||
};
|
||||
@@ -338,9 +330,4 @@ public class FlipResult
|
||||
/// 奖励描述
|
||||
/// </summary>
|
||||
public string RewardDesc { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 是否显示翻倍奖励提示
|
||||
/// </summary>
|
||||
public bool ShowDoubleRewardTip { get; set; }
|
||||
}
|
||||
|
||||
@@ -131,28 +131,35 @@ public class InviteCodeManager : DomainService
|
||||
throw new UserFriendlyException("该用户已被邀请,邀请码无效");
|
||||
}
|
||||
|
||||
// 检查当前用户是否已被邀请
|
||||
// 验证本周邀请码使用次数
|
||||
var weekStart = CardFlipManager.GetWeekStartDate(DateTime.Now);
|
||||
var weeklyUseCount = await _invitationRecordRepository._DbQueryable
|
||||
.Where(x => x.InvitedUserId == userId)
|
||||
.Where(x => x.InvitationTime >= weekStart)
|
||||
.CountAsync();
|
||||
|
||||
if (weeklyUseCount >= CardFlipManager.MAX_INVITE_FLIPS)
|
||||
{
|
||||
throw new UserFriendlyException($"本周邀请码使用次数已达上限({CardFlipManager.MAX_INVITE_FLIPS}次),请下周再来");
|
||||
}
|
||||
|
||||
// 检查当前用户的邀请码信息
|
||||
var myInviteCode = await _inviteCodeRepository._DbQueryable
|
||||
.Where(x => x.UserId == userId)
|
||||
.FirstAsync();
|
||||
|
||||
if (myInviteCode?.IsUserInvited == true)
|
||||
{
|
||||
throw new UserFriendlyException("您已使用过邀请码,无法重复使用");
|
||||
}
|
||||
|
||||
// 标记邀请码为已使用
|
||||
inviteCodeEntity.MarkAsUsed(userId);
|
||||
await _inviteCodeRepository.UpdateAsync(inviteCodeEntity);
|
||||
|
||||
// 标记当前用户已被邀请
|
||||
// 标记当前用户已被邀请(仅第一次使用邀请码时标记)
|
||||
if (myInviteCode == null)
|
||||
{
|
||||
myInviteCode = new InviteCodeAggregateRoot(userId, GenerateUniqueInviteCode());
|
||||
myInviteCode.MarkUserAsInvited();
|
||||
await _inviteCodeRepository.InsertAsync(myInviteCode);
|
||||
}
|
||||
else
|
||||
else if (!myInviteCode.IsUserInvited)
|
||||
{
|
||||
myInviteCode.MarkUserAsInvited();
|
||||
await _inviteCodeRepository.UpdateAsync(myInviteCode);
|
||||
|
||||
Reference in New Issue
Block a user