feat: 新增翻牌活动入口与全局组件声明
- 在 Header Avatar 菜单新增翻牌活动(cardFlip)入口,并添加对应插槽 <card-flip-activity/> - 在 types/components.d.ts 中添加 CardFlipActivity 与 ElCollapseTransition 类型声明 - 在 .eslintrc-auto-import.json 中新增 ElMessage 与 ElMessageBox 自动导入 - 从 import_meta.d.ts 中移除 VITE_BUILD_COMPRESS 环境声明 - 在 YiAbpWebModule.cs 中添加相关 using 并保留数据库建表初始化的注释(CodeFirst.InitTables)
This commit is contained in:
@@ -0,0 +1,88 @@
|
|||||||
|
namespace Yi.Framework.AiHub.Application.Contracts.Dtos.CardFlip;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 翻牌任务状态输出
|
||||||
|
/// </summary>
|
||||||
|
public class CardFlipStatusOutput
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 本周总翻牌次数
|
||||||
|
/// </summary>
|
||||||
|
public int TotalFlips { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 剩余免费次数
|
||||||
|
/// </summary>
|
||||||
|
public int RemainingFreeFlips { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 剩余赠送次数
|
||||||
|
/// </summary>
|
||||||
|
public int RemainingBonusFlips { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 剩余邀请解锁次数
|
||||||
|
/// </summary>
|
||||||
|
public int RemainingInviteFlips { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 是否可以翻牌
|
||||||
|
/// </summary>
|
||||||
|
public bool CanFlip { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 用户的邀请码
|
||||||
|
/// </summary>
|
||||||
|
public string? MyInviteCode { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 本周邀请人数
|
||||||
|
/// </summary>
|
||||||
|
public int InvitedCount { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 是否已被邀请(被邀请后不可再提供邀请码)
|
||||||
|
/// </summary>
|
||||||
|
public bool IsInvited { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 翻牌记录
|
||||||
|
/// </summary>
|
||||||
|
public List<CardFlipRecord> FlipRecords { get; set; } = new();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 下次可翻牌提示
|
||||||
|
/// </summary>
|
||||||
|
public string? NextFlipTip { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 翻牌记录
|
||||||
|
/// </summary>
|
||||||
|
public class CardFlipRecord
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 翻牌序号(1-10)
|
||||||
|
/// </summary>
|
||||||
|
public int FlipNumber { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 是否已翻
|
||||||
|
/// </summary>
|
||||||
|
public bool IsFlipped { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 是否中奖
|
||||||
|
/// </summary>
|
||||||
|
public bool IsWin { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 奖励金额(token数)
|
||||||
|
/// </summary>
|
||||||
|
public long? RewardAmount { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 翻牌类型描述
|
||||||
|
/// </summary>
|
||||||
|
public string? FlipTypeDesc { get; set; }
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
namespace Yi.Framework.AiHub.Application.Contracts.Dtos.CardFlip;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 翻牌输入
|
||||||
|
/// </summary>
|
||||||
|
public class FlipCardInput
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 翻牌序号(1-10)
|
||||||
|
/// </summary>
|
||||||
|
public int FlipNumber { get; set; }
|
||||||
|
}
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
namespace Yi.Framework.AiHub.Application.Contracts.Dtos.CardFlip;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 翻牌输出
|
||||||
|
/// </summary>
|
||||||
|
public class FlipCardOutput
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 翻牌序号(1-10)
|
||||||
|
/// </summary>
|
||||||
|
public int FlipNumber { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 是否中奖
|
||||||
|
/// </summary>
|
||||||
|
public bool IsWin { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 奖励金额(token数)
|
||||||
|
/// </summary>
|
||||||
|
public long? RewardAmount { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 奖励描述
|
||||||
|
/// </summary>
|
||||||
|
public string? RewardDesc { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 是否显示翻倍包提示(第9次中奖后显示)
|
||||||
|
/// </summary>
|
||||||
|
public bool ShowDoubleRewardTip { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 剩余可翻次数
|
||||||
|
/// </summary>
|
||||||
|
public int RemainingFlips { get; set; }
|
||||||
|
}
|
||||||
@@ -0,0 +1,48 @@
|
|||||||
|
namespace Yi.Framework.AiHub.Application.Contracts.Dtos.CardFlip;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 邀请码信息输出
|
||||||
|
/// </summary>
|
||||||
|
public class InviteCodeOutput
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 我的邀请码
|
||||||
|
/// </summary>
|
||||||
|
public string? MyInviteCode { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 本周邀请人数
|
||||||
|
/// </summary>
|
||||||
|
public int InvitedCount { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 是否已被邀请
|
||||||
|
/// </summary>
|
||||||
|
public bool IsInvited { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 邀请历史记录
|
||||||
|
/// </summary>
|
||||||
|
public List<InvitationHistoryItem> InvitationHistory { get; set; } = new();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 邀请历史记录项
|
||||||
|
/// </summary>
|
||||||
|
public class InvitationHistoryItem
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 被邀请人昵称(脱敏)
|
||||||
|
/// </summary>
|
||||||
|
public string InvitedUserName { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 邀请时间
|
||||||
|
/// </summary>
|
||||||
|
public DateTime InvitationTime { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 本周所在
|
||||||
|
/// </summary>
|
||||||
|
public string WeekDescription { get; set; } = string.Empty;
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
namespace Yi.Framework.AiHub.Application.Contracts.Dtos.CardFlip;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 使用邀请码输入
|
||||||
|
/// </summary>
|
||||||
|
public class UseInviteCodeInput
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 邀请码
|
||||||
|
/// </summary>
|
||||||
|
public string InviteCode { get; set; } = string.Empty;
|
||||||
|
}
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
using Yi.Framework.AiHub.Application.Contracts.Dtos.CardFlip;
|
||||||
|
|
||||||
|
namespace Yi.Framework.AiHub.Application.Contracts.IServices;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 翻牌服务接口
|
||||||
|
/// </summary>
|
||||||
|
public interface ICardFlipService
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 获取本周翻牌任务状态
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<CardFlipStatusOutput> GetWeeklyTaskStatusAsync();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 翻牌
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="input">翻牌输入</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<FlipCardOutput> FlipCardAsync(FlipCardInput input);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 使用邀请码解锁翻牌次数
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="input">邀请码输入</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task UseInviteCodeAsync(UseInviteCodeInput input);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取我的邀请码信息
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<InviteCodeOutput> GetMyInviteCodeAsync();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 生成我的邀请码(如果没有)
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<string> GenerateMyInviteCodeAsync();
|
||||||
|
}
|
||||||
@@ -0,0 +1,581 @@
|
|||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using SqlSugar;
|
||||||
|
using Volo.Abp.Application.Services;
|
||||||
|
using Volo.Abp.Users;
|
||||||
|
using Yi.Framework.AiHub.Application.Contracts.Dtos.CardFlip;
|
||||||
|
using Yi.Framework.AiHub.Application.Contracts.IServices;
|
||||||
|
using Yi.Framework.AiHub.Domain.Entities;
|
||||||
|
using Yi.Framework.AiHub.Domain.Extensions;
|
||||||
|
using Yi.Framework.SqlSugarCore.Abstractions;
|
||||||
|
|
||||||
|
namespace Yi.Framework.AiHub.Application.Services;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 翻牌服务
|
||||||
|
/// </summary>
|
||||||
|
[Authorize]
|
||||||
|
public class CardFlipService : ApplicationService, ICardFlipService
|
||||||
|
{
|
||||||
|
private readonly ISqlSugarRepository<CardFlipTaskAggregateRoot> _cardFlipTaskRepository;
|
||||||
|
private readonly ISqlSugarRepository<InviteCodeAggregateRoot> _inviteCodeRepository;
|
||||||
|
private readonly ISqlSugarRepository<InvitationRecordAggregateRoot> _invitationRecordRepository;
|
||||||
|
private readonly ISqlSugarRepository<PremiumPackageAggregateRoot> _premiumPackageRepository;
|
||||||
|
private readonly ILogger<CardFlipService> _logger;
|
||||||
|
|
||||||
|
// 翻牌规则配置
|
||||||
|
private const int MAX_FREE_FLIPS = 5; // 免费翻牌次数
|
||||||
|
private const int MAX_BONUS_FLIPS = 3; // 赠送翻牌次数
|
||||||
|
private const int MAX_INVITE_FLIPS = 2; // 邀请解锁翻牌次数
|
||||||
|
private const int TOTAL_MAX_FLIPS = 10; // 总最大翻牌次数
|
||||||
|
|
||||||
|
private const int NINTH_FLIP = 9; // 第9次翻牌
|
||||||
|
private const int TENTH_FLIP = 10; // 第10次翻牌
|
||||||
|
|
||||||
|
private const long NINTH_MIN_REWARD = 3000000; // 第9次最小奖励 300w
|
||||||
|
private const long NINTH_MAX_REWARD = 7000000; // 第9次最大奖励 700w
|
||||||
|
private const long TENTH_MIN_REWARD = 8000000; // 第10次最小奖励 800w
|
||||||
|
private const long TENTH_MAX_REWARD = 12000000; // 第10次最大奖励 1200w
|
||||||
|
|
||||||
|
public CardFlipService(
|
||||||
|
ISqlSugarRepository<CardFlipTaskAggregateRoot> cardFlipTaskRepository,
|
||||||
|
ISqlSugarRepository<InviteCodeAggregateRoot> inviteCodeRepository,
|
||||||
|
ISqlSugarRepository<InvitationRecordAggregateRoot> invitationRecordRepository,
|
||||||
|
ISqlSugarRepository<PremiumPackageAggregateRoot> premiumPackageRepository,
|
||||||
|
ILogger<CardFlipService> logger)
|
||||||
|
{
|
||||||
|
_cardFlipTaskRepository = cardFlipTaskRepository;
|
||||||
|
_inviteCodeRepository = inviteCodeRepository;
|
||||||
|
_invitationRecordRepository = invitationRecordRepository;
|
||||||
|
_premiumPackageRepository = premiumPackageRepository;
|
||||||
|
_logger = logger;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取本周翻牌任务状态
|
||||||
|
/// </summary>
|
||||||
|
public async Task<CardFlipStatusOutput> GetWeeklyTaskStatusAsync()
|
||||||
|
{
|
||||||
|
var userId = CurrentUser.GetId();
|
||||||
|
var weekStart = GetWeekStartDate(DateTime.Now);
|
||||||
|
|
||||||
|
// 获取或创建本周任务
|
||||||
|
var task = await GetOrCreateWeeklyTaskAsync(userId, weekStart, createIfNotExists: false);
|
||||||
|
|
||||||
|
// 获取邀请码信息
|
||||||
|
var inviteCode = await _inviteCodeRepository._DbQueryable
|
||||||
|
.Where(x => x.UserId == userId)
|
||||||
|
.FirstAsync();
|
||||||
|
|
||||||
|
// 统计本周邀请人数
|
||||||
|
var invitedCount = await _invitationRecordRepository._DbQueryable
|
||||||
|
.Where(x => x.InviterId == userId)
|
||||||
|
.Where(x => x.InvitationTime >= weekStart)
|
||||||
|
.CountAsync();
|
||||||
|
|
||||||
|
// 检查用户是否已被邀请
|
||||||
|
var isInvited = inviteCode?.IsUserInvited ?? false;
|
||||||
|
|
||||||
|
var output = new CardFlipStatusOutput
|
||||||
|
{
|
||||||
|
TotalFlips = task?.TotalFlips ?? 0,
|
||||||
|
RemainingFreeFlips = MAX_FREE_FLIPS - (task?.FreeFlipsUsed ?? 0),
|
||||||
|
RemainingBonusFlips = MAX_BONUS_FLIPS - (task?.BonusFlipsUsed ?? 0),
|
||||||
|
RemainingInviteFlips = MAX_INVITE_FLIPS - (task?.InviteFlipsUsed ?? 0),
|
||||||
|
CanFlip = CanFlipCard(task),
|
||||||
|
MyInviteCode = inviteCode?.Code,
|
||||||
|
InvitedCount = invitedCount,
|
||||||
|
IsInvited = isInvited,
|
||||||
|
FlipRecords = BuildFlipRecords(task)
|
||||||
|
};
|
||||||
|
|
||||||
|
// 生成提示信息
|
||||||
|
output.NextFlipTip = GenerateNextFlipTip(output);
|
||||||
|
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 翻牌
|
||||||
|
/// </summary>
|
||||||
|
public async Task<FlipCardOutput> FlipCardAsync(FlipCardInput input)
|
||||||
|
{
|
||||||
|
var userId = CurrentUser.GetId();
|
||||||
|
var weekStart = GetWeekStartDate(DateTime.Now);
|
||||||
|
|
||||||
|
if (input.FlipNumber < 1 || input.FlipNumber > TOTAL_MAX_FLIPS)
|
||||||
|
{
|
||||||
|
throw new UserFriendlyException($"翻牌序号必须在1-{TOTAL_MAX_FLIPS}之间");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取或创建本周任务
|
||||||
|
var task = await GetOrCreateWeeklyTaskAsync(userId, weekStart, createIfNotExists: true);
|
||||||
|
|
||||||
|
// 验证翻牌次数
|
||||||
|
if (task.TotalFlips >= TOTAL_MAX_FLIPS)
|
||||||
|
{
|
||||||
|
throw new UserFriendlyException("本周翻牌次数已用完,请下周再来!");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 验证顺序翻牌
|
||||||
|
if (input.FlipNumber != task.TotalFlips + 1)
|
||||||
|
{
|
||||||
|
throw new UserFriendlyException("请按顺序翻牌!");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 判断翻牌类型
|
||||||
|
var flipType = DetermineFlipType(task);
|
||||||
|
|
||||||
|
// 验证是否有足够的次数
|
||||||
|
if (!CanUseFlipType(task, flipType))
|
||||||
|
{
|
||||||
|
throw new UserFriendlyException(GetFlipTypeErrorMessage(flipType));
|
||||||
|
}
|
||||||
|
|
||||||
|
// 翻牌逻辑
|
||||||
|
var output = new FlipCardOutput
|
||||||
|
{
|
||||||
|
FlipNumber = input.FlipNumber,
|
||||||
|
IsWin = false,
|
||||||
|
ShowDoubleRewardTip = false
|
||||||
|
};
|
||||||
|
|
||||||
|
// 前8次固定失败
|
||||||
|
if (input.FlipNumber <= 8)
|
||||||
|
{
|
||||||
|
output.IsWin = false;
|
||||||
|
output.RewardDesc = "很遗憾,未中奖";
|
||||||
|
}
|
||||||
|
// 第9次中奖
|
||||||
|
else if (input.FlipNumber == NINTH_FLIP)
|
||||||
|
{
|
||||||
|
var rewardAmount = GenerateRandomReward(NINTH_MIN_REWARD, NINTH_MAX_REWARD);
|
||||||
|
output.IsWin = true;
|
||||||
|
output.RewardAmount = rewardAmount;
|
||||||
|
output.RewardDesc = $"恭喜获得尊享包 {rewardAmount / 10000}w tokens!";
|
||||||
|
output.ShowDoubleRewardTip = true; // 显示翻倍包提示
|
||||||
|
|
||||||
|
// 发放奖励
|
||||||
|
await GrantRewardAsync(userId, rewardAmount, $"翻牌活动第{input.FlipNumber}次中奖");
|
||||||
|
|
||||||
|
// 记录奖励
|
||||||
|
task.SetNinthReward(rewardAmount);
|
||||||
|
}
|
||||||
|
// 第10次中奖(翻倍)
|
||||||
|
else if (input.FlipNumber == TENTH_FLIP)
|
||||||
|
{
|
||||||
|
var rewardAmount = GenerateRandomReward(TENTH_MIN_REWARD, TENTH_MAX_REWARD);
|
||||||
|
output.IsWin = true;
|
||||||
|
output.RewardAmount = rewardAmount;
|
||||||
|
output.RewardDesc = $"恭喜获得尊享包 {rewardAmount / 10000}w tokens(翻倍奖励)!";
|
||||||
|
|
||||||
|
// 发放奖励
|
||||||
|
await GrantRewardAsync(userId, rewardAmount, $"翻牌活动第{input.FlipNumber}次中奖(翻倍)");
|
||||||
|
|
||||||
|
// 记录奖励
|
||||||
|
task.SetTenthReward(rewardAmount);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 更新翻牌次数
|
||||||
|
task.IncrementFlip(flipType);
|
||||||
|
await _cardFlipTaskRepository.UpdateAsync(task);
|
||||||
|
|
||||||
|
// 计算剩余次数
|
||||||
|
output.RemainingFlips = TOTAL_MAX_FLIPS - task.TotalFlips;
|
||||||
|
|
||||||
|
_logger.LogInformation($"用户 {userId} 完成第 {input.FlipNumber} 次翻牌,中奖:{output.IsWin}");
|
||||||
|
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 使用邀请码解锁翻牌次数
|
||||||
|
/// </summary>
|
||||||
|
public async Task UseInviteCodeAsync(UseInviteCodeInput input)
|
||||||
|
{
|
||||||
|
var userId = CurrentUser.GetId();
|
||||||
|
var weekStart = GetWeekStartDate(DateTime.Now);
|
||||||
|
|
||||||
|
if (string.IsNullOrWhiteSpace(input.InviteCode))
|
||||||
|
{
|
||||||
|
throw new UserFriendlyException("邀请码不能为空");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 查找邀请码
|
||||||
|
var inviteCode = await _inviteCodeRepository._DbQueryable
|
||||||
|
.Where(x => x.Code == input.InviteCode)
|
||||||
|
.FirstAsync();
|
||||||
|
|
||||||
|
if (inviteCode == null)
|
||||||
|
{
|
||||||
|
throw new UserFriendlyException("邀请码不存在");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 验证不能使用自己的邀请码
|
||||||
|
if (inviteCode.UserId == userId)
|
||||||
|
{
|
||||||
|
throw new UserFriendlyException("不能使用自己的邀请码");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 验证邀请码是否已被使用
|
||||||
|
if (inviteCode.IsUsed)
|
||||||
|
{
|
||||||
|
throw new UserFriendlyException("该邀请码已被使用");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 验证邀请码拥有者是否已被邀请
|
||||||
|
if (inviteCode.IsUserInvited)
|
||||||
|
{
|
||||||
|
throw new UserFriendlyException("该用户已被邀请,邀请码无效");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 检查当前用户是否已被邀请
|
||||||
|
var myInviteCode = await _inviteCodeRepository._DbQueryable
|
||||||
|
.Where(x => x.UserId == userId)
|
||||||
|
.FirstAsync();
|
||||||
|
|
||||||
|
if (myInviteCode?.IsUserInvited == true)
|
||||||
|
{
|
||||||
|
throw new UserFriendlyException("您已使用过邀请码,无法重复使用");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取本周任务
|
||||||
|
var task = await GetOrCreateWeeklyTaskAsync(userId, weekStart, createIfNotExists: true);
|
||||||
|
|
||||||
|
// 验证是否已经使用了所有邀请解锁次数
|
||||||
|
if (task.InviteFlipsUsed >= MAX_INVITE_FLIPS)
|
||||||
|
{
|
||||||
|
throw new UserFriendlyException("本周邀请解锁次数已用完");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 标记邀请码为已使用
|
||||||
|
inviteCode.MarkAsUsed(userId);
|
||||||
|
await _inviteCodeRepository.UpdateAsync(inviteCode);
|
||||||
|
|
||||||
|
// 标记当前用户已被邀请
|
||||||
|
if (myInviteCode == null)
|
||||||
|
{
|
||||||
|
myInviteCode = new InviteCodeAggregateRoot(userId, GenerateInviteCode());
|
||||||
|
myInviteCode.MarkUserAsInvited();
|
||||||
|
await _inviteCodeRepository.InsertAsync(myInviteCode);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
myInviteCode.MarkUserAsInvited();
|
||||||
|
await _inviteCodeRepository.UpdateAsync(myInviteCode);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 创建邀请记录
|
||||||
|
var invitationRecord = new InvitationRecordAggregateRoot(
|
||||||
|
inviteCode.UserId,
|
||||||
|
userId,
|
||||||
|
input.InviteCode);
|
||||||
|
await _invitationRecordRepository.InsertAsync(invitationRecord);
|
||||||
|
|
||||||
|
_logger.LogInformation($"用户 {userId} 使用邀请码 {input.InviteCode} 成功");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取我的邀请码信息
|
||||||
|
/// </summary>
|
||||||
|
public async Task<InviteCodeOutput> GetMyInviteCodeAsync()
|
||||||
|
{
|
||||||
|
var userId = CurrentUser.GetId();
|
||||||
|
var weekStart = GetWeekStartDate(DateTime.Now);
|
||||||
|
|
||||||
|
// 获取我的邀请码
|
||||||
|
var inviteCode = await _inviteCodeRepository._DbQueryable
|
||||||
|
.Where(x => x.UserId == userId)
|
||||||
|
.FirstAsync();
|
||||||
|
|
||||||
|
// 统计本周邀请人数
|
||||||
|
var invitedCount = await _invitationRecordRepository._DbQueryable
|
||||||
|
.Where(x => x.InviterId == userId)
|
||||||
|
.Where(x => x.InvitationTime >= weekStart)
|
||||||
|
.CountAsync();
|
||||||
|
|
||||||
|
// 获取邀请历史
|
||||||
|
var invitationHistory = await _invitationRecordRepository._DbQueryable
|
||||||
|
.Where(x => x.InviterId == userId)
|
||||||
|
.OrderBy(x => x.InvitationTime, OrderByType.Desc)
|
||||||
|
.Take(10)
|
||||||
|
.Select(x => new InvitationHistoryItem
|
||||||
|
{
|
||||||
|
InvitedUserName = "用户***", // 脱敏处理
|
||||||
|
InvitationTime = x.InvitationTime,
|
||||||
|
WeekDescription = GetWeekDescription(x.InvitationTime)
|
||||||
|
})
|
||||||
|
.ToListAsync();
|
||||||
|
|
||||||
|
return new InviteCodeOutput
|
||||||
|
{
|
||||||
|
MyInviteCode = inviteCode?.Code,
|
||||||
|
InvitedCount = invitedCount,
|
||||||
|
IsInvited = inviteCode?.IsUserInvited ?? false,
|
||||||
|
InvitationHistory = invitationHistory
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 生成我的邀请码
|
||||||
|
/// </summary>
|
||||||
|
public async Task<string> GenerateMyInviteCodeAsync()
|
||||||
|
{
|
||||||
|
var userId = CurrentUser.GetId();
|
||||||
|
|
||||||
|
// 检查是否已有邀请码
|
||||||
|
var existingCode = await _inviteCodeRepository._DbQueryable
|
||||||
|
.Where(x => x.UserId == userId)
|
||||||
|
.FirstAsync();
|
||||||
|
|
||||||
|
if (existingCode != null)
|
||||||
|
{
|
||||||
|
return existingCode.Code;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 生成新邀请码
|
||||||
|
var code = GenerateInviteCode();
|
||||||
|
var inviteCode = new InviteCodeAggregateRoot(userId, code);
|
||||||
|
await _inviteCodeRepository.InsertAsync(inviteCode);
|
||||||
|
|
||||||
|
_logger.LogInformation($"用户 {userId} 生成邀请码 {code}");
|
||||||
|
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
#region 私有辅助方法
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取或创建本周任务
|
||||||
|
/// </summary>
|
||||||
|
private async Task<CardFlipTaskAggregateRoot> GetOrCreateWeeklyTaskAsync(
|
||||||
|
Guid userId,
|
||||||
|
DateTime weekStart,
|
||||||
|
bool createIfNotExists)
|
||||||
|
{
|
||||||
|
var task = await _cardFlipTaskRepository._DbQueryable
|
||||||
|
.Where(x => x.UserId == userId && x.WeekStartDate == weekStart)
|
||||||
|
.FirstAsync();
|
||||||
|
|
||||||
|
if (task == null && createIfNotExists)
|
||||||
|
{
|
||||||
|
task = new CardFlipTaskAggregateRoot(userId, weekStart);
|
||||||
|
await _cardFlipTaskRepository.InsertAsync(task);
|
||||||
|
}
|
||||||
|
|
||||||
|
return task;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取本周开始日期(周一)
|
||||||
|
/// </summary>
|
||||||
|
private DateTime GetWeekStartDate(DateTime date)
|
||||||
|
{
|
||||||
|
var dayOfWeek = (int)date.DayOfWeek;
|
||||||
|
// 将周日(0)转换为7
|
||||||
|
if (dayOfWeek == 0) dayOfWeek = 7;
|
||||||
|
|
||||||
|
// 计算本周一的日期
|
||||||
|
var monday = date.Date.AddDays(-(dayOfWeek - 1));
|
||||||
|
return monday;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 判断是否可以翻牌
|
||||||
|
/// </summary>
|
||||||
|
private bool CanFlipCard(CardFlipTaskAggregateRoot? task)
|
||||||
|
{
|
||||||
|
if (task == null) return true; // 没有任务记录,可以开始翻牌
|
||||||
|
|
||||||
|
return task.TotalFlips < TOTAL_MAX_FLIPS;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 判断翻牌类型
|
||||||
|
/// </summary>
|
||||||
|
private FlipType DetermineFlipType(CardFlipTaskAggregateRoot task)
|
||||||
|
{
|
||||||
|
if (task.FreeFlipsUsed < MAX_FREE_FLIPS)
|
||||||
|
{
|
||||||
|
return FlipType.Free;
|
||||||
|
}
|
||||||
|
else if (task.BonusFlipsUsed < MAX_BONUS_FLIPS)
|
||||||
|
{
|
||||||
|
return FlipType.Bonus;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return FlipType.Invite;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 判断是否可以使用该翻牌类型
|
||||||
|
/// </summary>
|
||||||
|
private bool CanUseFlipType(CardFlipTaskAggregateRoot task, FlipType flipType)
|
||||||
|
{
|
||||||
|
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
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取翻牌类型错误提示
|
||||||
|
/// </summary>
|
||||||
|
private string GetFlipTypeErrorMessage(FlipType flipType)
|
||||||
|
{
|
||||||
|
return flipType switch
|
||||||
|
{
|
||||||
|
FlipType.Free => "免费翻牌次数已用完",
|
||||||
|
FlipType.Bonus => "赠送翻牌次数已用完",
|
||||||
|
FlipType.Invite => "需要使用邀请码解锁更多次数",
|
||||||
|
_ => "无法翻牌"
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 构建翻牌记录列表
|
||||||
|
/// </summary>
|
||||||
|
private List<CardFlipRecord> BuildFlipRecords(CardFlipTaskAggregateRoot? task)
|
||||||
|
{
|
||||||
|
var records = new List<CardFlipRecord>();
|
||||||
|
|
||||||
|
for (int i = 1; i <= TOTAL_MAX_FLIPS; i++)
|
||||||
|
{
|
||||||
|
var record = new CardFlipRecord
|
||||||
|
{
|
||||||
|
FlipNumber = i,
|
||||||
|
IsFlipped = task != null && i <= task.TotalFlips,
|
||||||
|
IsWin = false,
|
||||||
|
FlipTypeDesc = GetFlipTypeDesc(i)
|
||||||
|
};
|
||||||
|
|
||||||
|
// 设置中奖信息
|
||||||
|
if (task != null && i <= task.TotalFlips)
|
||||||
|
{
|
||||||
|
if (i == NINTH_FLIP && task.HasNinthReward)
|
||||||
|
{
|
||||||
|
record.IsWin = true;
|
||||||
|
record.RewardAmount = task.NinthRewardAmount;
|
||||||
|
}
|
||||||
|
else if (i == TENTH_FLIP && task.HasTenthReward)
|
||||||
|
{
|
||||||
|
record.IsWin = true;
|
||||||
|
record.RewardAmount = task.TenthRewardAmount;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
records.Add(record);
|
||||||
|
}
|
||||||
|
|
||||||
|
return records;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取翻牌类型描述
|
||||||
|
/// </summary>
|
||||||
|
private string GetFlipTypeDesc(int flipNumber)
|
||||||
|
{
|
||||||
|
if (flipNumber <= MAX_FREE_FLIPS)
|
||||||
|
{
|
||||||
|
return "免费";
|
||||||
|
}
|
||||||
|
else if (flipNumber <= MAX_FREE_FLIPS + MAX_BONUS_FLIPS)
|
||||||
|
{
|
||||||
|
return "赠送";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return "邀请解锁";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 生成下次翻牌提示
|
||||||
|
/// </summary>
|
||||||
|
private string GenerateNextFlipTip(CardFlipStatusOutput status)
|
||||||
|
{
|
||||||
|
if (status.TotalFlips >= TOTAL_MAX_FLIPS)
|
||||||
|
{
|
||||||
|
return "本周翻牌次数已用完,请下周再来!";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (status.RemainingFreeFlips > 0)
|
||||||
|
{
|
||||||
|
return $"还有{status.RemainingFreeFlips}次免费翻牌机会";
|
||||||
|
}
|
||||||
|
else if (status.RemainingBonusFlips > 0)
|
||||||
|
{
|
||||||
|
return $"还有{status.RemainingBonusFlips}次赠送翻牌机会";
|
||||||
|
}
|
||||||
|
else if (status.RemainingInviteFlips > 0)
|
||||||
|
{
|
||||||
|
if (status.TotalFlips == 8)
|
||||||
|
{
|
||||||
|
return "再邀请一个人,马上中奖!";
|
||||||
|
}
|
||||||
|
return $"使用邀请码可解锁{status.RemainingInviteFlips}次翻牌";
|
||||||
|
}
|
||||||
|
|
||||||
|
return "继续加油!";
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 生成随机奖励金额
|
||||||
|
/// </summary>
|
||||||
|
private long GenerateRandomReward(long min, long max)
|
||||||
|
{
|
||||||
|
var random = new Random();
|
||||||
|
return (long)(random.NextDouble() * (max - min) + min);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 发放奖励
|
||||||
|
/// </summary>
|
||||||
|
private async Task GrantRewardAsync(Guid userId, long amount, string description)
|
||||||
|
{
|
||||||
|
var premiumPackage = new PremiumPackageAggregateRoot(userId, amount, description)
|
||||||
|
{
|
||||||
|
PurchaseAmount = 0, // 奖励不需要付费
|
||||||
|
Remark = $"翻牌活动奖励:{amount / 10000}w tokens"
|
||||||
|
};
|
||||||
|
|
||||||
|
await _premiumPackageRepository.InsertAsync(premiumPackage);
|
||||||
|
|
||||||
|
_logger.LogInformation($"用户 {userId} 获得翻牌奖励 {amount / 10000}w tokens");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 生成邀请码
|
||||||
|
/// </summary>
|
||||||
|
private string GenerateInviteCode()
|
||||||
|
{
|
||||||
|
const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
|
||||||
|
var random = new Random();
|
||||||
|
var code = new char[8];
|
||||||
|
|
||||||
|
for (int i = 0; i < code.Length; i++)
|
||||||
|
{
|
||||||
|
code[i] = chars[random.Next(chars.Length)];
|
||||||
|
}
|
||||||
|
|
||||||
|
return new string(code);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取周描述
|
||||||
|
/// </summary>
|
||||||
|
private string GetWeekDescription(DateTime date)
|
||||||
|
{
|
||||||
|
var weekStart = GetWeekStartDate(date);
|
||||||
|
var weekEnd = weekStart.AddDays(6);
|
||||||
|
|
||||||
|
return $"{weekStart:MM-dd} 至 {weekEnd:MM-dd}";
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
@@ -0,0 +1,160 @@
|
|||||||
|
using SqlSugar;
|
||||||
|
using Volo.Abp.Domain.Entities.Auditing;
|
||||||
|
|
||||||
|
namespace Yi.Framework.AiHub.Domain.Entities;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 翻牌任务记录
|
||||||
|
/// </summary>
|
||||||
|
[SugarTable("Ai_CardFlipTask")]
|
||||||
|
[SugarIndex($"index_{nameof(UserId)}_{nameof(WeekStartDate)}",
|
||||||
|
nameof(UserId), OrderByType.Asc,
|
||||||
|
nameof(WeekStartDate), OrderByType.Desc)]
|
||||||
|
public class CardFlipTaskAggregateRoot : FullAuditedAggregateRoot<Guid>
|
||||||
|
{
|
||||||
|
public CardFlipTaskAggregateRoot()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public CardFlipTaskAggregateRoot(Guid userId, DateTime weekStartDate)
|
||||||
|
{
|
||||||
|
UserId = userId;
|
||||||
|
WeekStartDate = weekStartDate.Date; // 确保只存储日期部分
|
||||||
|
TotalFlips = 0;
|
||||||
|
FreeFlipsUsed = 0;
|
||||||
|
BonusFlipsUsed = 0;
|
||||||
|
InviteFlipsUsed = 0;
|
||||||
|
IsFirstFlipDone = false;
|
||||||
|
HasNinthReward = false;
|
||||||
|
HasTenthReward = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 用户ID
|
||||||
|
/// </summary>
|
||||||
|
public Guid UserId { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 本周开始日期(每周一)
|
||||||
|
/// </summary>
|
||||||
|
public DateTime WeekStartDate { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 总共已翻牌次数
|
||||||
|
/// </summary>
|
||||||
|
public int TotalFlips { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 已使用的免费次数(最多5次)
|
||||||
|
/// </summary>
|
||||||
|
public int FreeFlipsUsed { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 已使用的赠送次数(最多3次)
|
||||||
|
/// </summary>
|
||||||
|
public int BonusFlipsUsed { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 已使用的邀请解锁次数(最多2次)
|
||||||
|
/// </summary>
|
||||||
|
public int InviteFlipsUsed { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 是否已完成首次翻牌(用于判断是否创建任务)
|
||||||
|
/// </summary>
|
||||||
|
public bool IsFirstFlipDone { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 是否已获得第9次奖励
|
||||||
|
/// </summary>
|
||||||
|
public bool HasNinthReward { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 第9次奖励金额(300-700w)
|
||||||
|
/// </summary>
|
||||||
|
public long? NinthRewardAmount { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 是否已获得第10次奖励
|
||||||
|
/// </summary>
|
||||||
|
public bool HasTenthReward { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 第10次奖励金额(800-1200w)
|
||||||
|
/// </summary>
|
||||||
|
public long? TenthRewardAmount { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 备注信息
|
||||||
|
/// </summary>
|
||||||
|
[SugarColumn(Length = 500, IsNullable = true)]
|
||||||
|
public string? Remark { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 增加翻牌次数
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="flipType">翻牌类型</param>
|
||||||
|
public void IncrementFlip(FlipType flipType)
|
||||||
|
{
|
||||||
|
TotalFlips++;
|
||||||
|
|
||||||
|
switch (flipType)
|
||||||
|
{
|
||||||
|
case FlipType.Free:
|
||||||
|
FreeFlipsUsed++;
|
||||||
|
break;
|
||||||
|
case FlipType.Bonus:
|
||||||
|
BonusFlipsUsed++;
|
||||||
|
break;
|
||||||
|
case FlipType.Invite:
|
||||||
|
InviteFlipsUsed++;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!IsFirstFlipDone)
|
||||||
|
{
|
||||||
|
IsFirstFlipDone = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 记录第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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 翻牌类型枚举
|
||||||
|
/// </summary>
|
||||||
|
public enum FlipType
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 免费翻牌(1-5次)
|
||||||
|
/// </summary>
|
||||||
|
Free = 0,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 赠送翻牌(6-8次)
|
||||||
|
/// </summary>
|
||||||
|
Bonus = 1,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 邀请解锁翻牌(9-10次)
|
||||||
|
/// </summary>
|
||||||
|
Invite = 2
|
||||||
|
}
|
||||||
@@ -0,0 +1,76 @@
|
|||||||
|
using SqlSugar;
|
||||||
|
using Volo.Abp.Domain.Entities.Auditing;
|
||||||
|
|
||||||
|
namespace Yi.Framework.AiHub.Domain.Entities;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 邀请记录
|
||||||
|
/// </summary>
|
||||||
|
[SugarTable("Ai_InvitationRecord")]
|
||||||
|
[SugarIndex($"index_{nameof(InviterId)}_{nameof(InvitedUserId)}",
|
||||||
|
nameof(InviterId), OrderByType.Asc,
|
||||||
|
nameof(InvitedUserId), OrderByType.Asc)]
|
||||||
|
[SugarIndex($"index_{nameof(InvitedUserId)}", nameof(InvitedUserId), OrderByType.Asc)]
|
||||||
|
public class InvitationRecordAggregateRoot : FullAuditedAggregateRoot<Guid>
|
||||||
|
{
|
||||||
|
public InvitationRecordAggregateRoot()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public InvitationRecordAggregateRoot(Guid inviterId, Guid invitedUserId, string inviteCode)
|
||||||
|
{
|
||||||
|
InviterId = inviterId;
|
||||||
|
InvitedUserId = invitedUserId;
|
||||||
|
InviteCode = inviteCode;
|
||||||
|
InvitationTime = DateTime.Now;
|
||||||
|
Status = InvitationStatus.Valid;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 邀请人ID
|
||||||
|
/// </summary>
|
||||||
|
public Guid InviterId { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 被邀请人ID
|
||||||
|
/// </summary>
|
||||||
|
public Guid InvitedUserId { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 使用的邀请码
|
||||||
|
/// </summary>
|
||||||
|
[SugarColumn(Length = 50)]
|
||||||
|
public string InviteCode { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 邀请时间
|
||||||
|
/// </summary>
|
||||||
|
public DateTime InvitationTime { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 邀请状态(0=有效,1=已撤销)
|
||||||
|
/// </summary>
|
||||||
|
public InvitationStatus Status { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 备注信息
|
||||||
|
/// </summary>
|
||||||
|
[SugarColumn(Length = 500, IsNullable = true)]
|
||||||
|
public string? Remark { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 邀请状态枚举
|
||||||
|
/// </summary>
|
||||||
|
public enum InvitationStatus
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 有效
|
||||||
|
/// </summary>
|
||||||
|
Valid = 0,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 已撤销
|
||||||
|
/// </summary>
|
||||||
|
Revoked = 1
|
||||||
|
}
|
||||||
@@ -0,0 +1,88 @@
|
|||||||
|
using SqlSugar;
|
||||||
|
using Volo.Abp.Domain.Entities.Auditing;
|
||||||
|
|
||||||
|
namespace Yi.Framework.AiHub.Domain.Entities;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 用户邀请码
|
||||||
|
/// </summary>
|
||||||
|
[SugarTable("Ai_InviteCode")]
|
||||||
|
[SugarIndex($"index_{nameof(UserId)}", nameof(UserId), OrderByType.Asc, true)]
|
||||||
|
[SugarIndex($"index_{nameof(Code)}", nameof(Code), OrderByType.Asc, true)]
|
||||||
|
public class InviteCodeAggregateRoot : FullAuditedAggregateRoot<Guid>
|
||||||
|
{
|
||||||
|
public InviteCodeAggregateRoot()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public InviteCodeAggregateRoot(Guid userId, string code)
|
||||||
|
{
|
||||||
|
UserId = userId;
|
||||||
|
Code = code;
|
||||||
|
IsUsed = false;
|
||||||
|
IsUserInvited = false;
|
||||||
|
UsedCount = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 用户ID(邀请码拥有者)
|
||||||
|
/// </summary>
|
||||||
|
public Guid UserId { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 邀请码(唯一)
|
||||||
|
/// </summary>
|
||||||
|
[SugarColumn(Length = 50)]
|
||||||
|
public string Code { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 是否已被使用(一个邀请码只能被使用一次)
|
||||||
|
/// </summary>
|
||||||
|
public bool IsUsed { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 邀请码拥有者是否已被他人邀请(被邀请后不可再提供邀请码)
|
||||||
|
/// </summary>
|
||||||
|
public bool IsUserInvited { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 被使用次数(统计用)
|
||||||
|
/// </summary>
|
||||||
|
public int UsedCount { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 使用时间
|
||||||
|
/// </summary>
|
||||||
|
public DateTime? UsedTime { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 使用人ID
|
||||||
|
/// </summary>
|
||||||
|
public Guid? UsedByUserId { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 备注信息
|
||||||
|
/// </summary>
|
||||||
|
[SugarColumn(Length = 500, IsNullable = true)]
|
||||||
|
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>
|
||||||
|
public void MarkUserAsInvited()
|
||||||
|
{
|
||||||
|
IsUserInvited = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -29,6 +29,7 @@ using Volo.Abp.Swashbuckle;
|
|||||||
using Yi.Abp.Application;
|
using Yi.Abp.Application;
|
||||||
using Yi.Abp.SqlsugarCore;
|
using Yi.Abp.SqlsugarCore;
|
||||||
using Yi.Framework.AiHub.Application;
|
using Yi.Framework.AiHub.Application;
|
||||||
|
using Yi.Framework.AiHub.Domain.Entities;
|
||||||
using Yi.Framework.AspNetCore;
|
using Yi.Framework.AspNetCore;
|
||||||
using Yi.Framework.AspNetCore.Authentication.OAuth;
|
using Yi.Framework.AspNetCore.Authentication.OAuth;
|
||||||
using Yi.Framework.AspNetCore.Authentication.OAuth.Gitee;
|
using Yi.Framework.AspNetCore.Authentication.OAuth.Gitee;
|
||||||
@@ -46,6 +47,7 @@ using Yi.Framework.Rbac.Application;
|
|||||||
using Yi.Framework.Rbac.Domain.Authorization;
|
using Yi.Framework.Rbac.Domain.Authorization;
|
||||||
using Yi.Framework.Rbac.Domain.Shared.Consts;
|
using Yi.Framework.Rbac.Domain.Shared.Consts;
|
||||||
using Yi.Framework.Rbac.Domain.Shared.Options;
|
using Yi.Framework.Rbac.Domain.Shared.Options;
|
||||||
|
using Yi.Framework.SqlSugarCore.Abstractions;
|
||||||
using Yi.Framework.Stock.Application;
|
using Yi.Framework.Stock.Application;
|
||||||
using Yi.Framework.TenantManagement.Application;
|
using Yi.Framework.TenantManagement.Application;
|
||||||
|
|
||||||
@@ -350,6 +352,9 @@ namespace Yi.Abp.Web
|
|||||||
var app = context.GetApplicationBuilder();
|
var app = context.GetApplicationBuilder();
|
||||||
app.UseRouting();
|
app.UseRouting();
|
||||||
|
|
||||||
|
// app.ApplicationServices.GetRequiredService<ISqlSugarDbContext>().SqlSugarClient.CodeFirst.InitTables<CardFlipTaskAggregateRoot>();
|
||||||
|
// app.ApplicationServices.GetRequiredService<ISqlSugarDbContext>().SqlSugarClient.CodeFirst.InitTables<InvitationRecordAggregateRoot>();
|
||||||
|
// app.ApplicationServices.GetRequiredService<ISqlSugarDbContext>().SqlSugarClient.CodeFirst.InitTables<InviteCodeAggregateRoot>();
|
||||||
//跨域
|
//跨域
|
||||||
app.UseCors(DefaultCorsPolicyName);
|
app.UseCors(DefaultCorsPolicyName);
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,8 @@
|
|||||||
"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,
|
||||||
|
|||||||
33
Yi.Ai.Vue3/src/api/cardFlip/index.ts
Normal file
33
Yi.Ai.Vue3/src/api/cardFlip/index.ts
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
import { get, post } from '@/utils/request';
|
||||||
|
import type {
|
||||||
|
CardFlipStatusOutput,
|
||||||
|
FlipCardInput,
|
||||||
|
FlipCardOutput,
|
||||||
|
UseInviteCodeInput,
|
||||||
|
InviteCodeOutput
|
||||||
|
} from './types';
|
||||||
|
|
||||||
|
// 获取本周翻牌任务状态
|
||||||
|
export function getWeeklyTaskStatus() {
|
||||||
|
return get<CardFlipStatusOutput>('/card-flip/weekly-task-status').json();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 翻牌
|
||||||
|
export function flipCard(data: FlipCardInput) {
|
||||||
|
return post<FlipCardOutput>('/card-flip/flip-card', data).json();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 使用邀请码解锁翻牌次数
|
||||||
|
export function useInviteCode(data: UseInviteCodeInput) {
|
||||||
|
return post<void>('/card-flip/use-invite-code', data).json();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取我的邀请码信息
|
||||||
|
export function getMyInviteCode() {
|
||||||
|
return get<InviteCodeOutput>('/card-flip/my-invite-code').json();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 生成我的邀请码(如果没有)
|
||||||
|
export function generateMyInviteCode() {
|
||||||
|
return post<string>('/card-flip/generate-my-invite-code').json();
|
||||||
|
}
|
||||||
57
Yi.Ai.Vue3/src/api/cardFlip/types.ts
Normal file
57
Yi.Ai.Vue3/src/api/cardFlip/types.ts
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
// 翻牌任务状态输出
|
||||||
|
export interface CardFlipStatusOutput {
|
||||||
|
totalFlips: number; // 本周总翻牌次数
|
||||||
|
remainingFreeFlips: number; // 剩余免费次数
|
||||||
|
remainingBonusFlips: number; // 剩余赠送次数
|
||||||
|
remainingInviteFlips: number; // 剩余邀请解锁次数
|
||||||
|
canFlip: boolean; // 是否可以翻牌
|
||||||
|
myInviteCode?: string; // 用户的邀请码
|
||||||
|
invitedCount: number; // 本周邀请人数
|
||||||
|
isInvited: boolean; // 是否已被邀请
|
||||||
|
flipRecords: CardFlipRecord[]; // 翻牌记录
|
||||||
|
nextFlipTip?: string; // 下次可翻牌提示
|
||||||
|
}
|
||||||
|
|
||||||
|
// 翻牌记录
|
||||||
|
export interface CardFlipRecord {
|
||||||
|
flipNumber: number; // 翻牌序号(1-10)
|
||||||
|
isFlipped: boolean; // 是否已翻
|
||||||
|
isWin: boolean; // 是否中奖
|
||||||
|
rewardAmount?: number; // 奖励金额(token数)
|
||||||
|
flipTypeDesc?: string; // 翻牌类型描述
|
||||||
|
}
|
||||||
|
|
||||||
|
// 翻牌输入
|
||||||
|
export interface FlipCardInput {
|
||||||
|
flipNumber: number; // 翻牌序号(1-10)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 翻牌输出
|
||||||
|
export interface FlipCardOutput {
|
||||||
|
flipNumber: number; // 翻牌序号(1-10)
|
||||||
|
isWin: boolean; // 是否中奖
|
||||||
|
rewardAmount?: number; // 奖励金额(token数)
|
||||||
|
rewardDesc?: string; // 奖励描述
|
||||||
|
showDoubleRewardTip: boolean; // 是否显示翻倍包提示
|
||||||
|
remainingFlips: number; // 剩余可翻次数
|
||||||
|
}
|
||||||
|
|
||||||
|
// 使用邀请码输入
|
||||||
|
export interface UseInviteCodeInput {
|
||||||
|
inviteCode: string; // 邀请码
|
||||||
|
}
|
||||||
|
|
||||||
|
// 邀请码信息输出
|
||||||
|
export interface InviteCodeOutput {
|
||||||
|
myInviteCode?: string; // 我的邀请码
|
||||||
|
invitedCount: number; // 本周邀请人数
|
||||||
|
isInvited: boolean; // 是否已被邀请
|
||||||
|
invitationHistory: InvitationHistoryItem[]; // 邀请历史记录
|
||||||
|
}
|
||||||
|
|
||||||
|
// 邀请历史记录项
|
||||||
|
export interface InvitationHistoryItem {
|
||||||
|
invitedUserName: string; // 被邀请人昵称(脱敏)
|
||||||
|
invitationTime: string; // 邀请时间
|
||||||
|
weekDescription: string; // 本周所在
|
||||||
|
}
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -69,7 +69,8 @@ const navItems = [
|
|||||||
{ name: 'rechargeLog', label: '充值记录', icon: 'Document' },
|
{ name: 'rechargeLog', label: '充值记录', icon: 'Document' },
|
||||||
{ name: 'usageStatistics', label: '用量统计', icon: 'Histogram' },
|
{ name: 'usageStatistics', label: '用量统计', icon: 'Histogram' },
|
||||||
{ name: 'premiumService', label: '尊享服务', icon: 'ColdDrink' },
|
{ name: 'premiumService', label: '尊享服务', icon: 'ColdDrink' },
|
||||||
{ name: 'dailyTask', label: '每日任务', icon: 'Trophy' }
|
{ name: 'dailyTask', label: '每日任务', icon: 'Trophy' },
|
||||||
|
{ name: 'cardFlip', label: '翻牌活动', icon: 'Present' }
|
||||||
// { name: 'usageStatistics2', label: '用量统计2', icon: 'Histogram' },
|
// { name: 'usageStatistics2', label: '用量统计2', icon: 'Histogram' },
|
||||||
];
|
];
|
||||||
function openDialog() {
|
function openDialog() {
|
||||||
@@ -349,6 +350,9 @@ function onProductPackage() {
|
|||||||
<template #dailyTask>
|
<template #dailyTask>
|
||||||
<daily-task />
|
<daily-task />
|
||||||
</template>
|
</template>
|
||||||
|
<template #cardFlip>
|
||||||
|
<card-flip-activity />
|
||||||
|
</template>
|
||||||
<template #rechargeLog>
|
<template #rechargeLog>
|
||||||
<recharge-log />
|
<recharge-log />
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
2
Yi.Ai.Vue3/types/components.d.ts
vendored
2
Yi.Ai.Vue3/types/components.d.ts
vendored
@@ -10,6 +10,7 @@ declare module 'vue' {
|
|||||||
export interface GlobalComponents {
|
export interface GlobalComponents {
|
||||||
AccountPassword: typeof import('./../src/components/LoginDialog/components/FormLogin/AccountPassword.vue')['default']
|
AccountPassword: typeof import('./../src/components/LoginDialog/components/FormLogin/AccountPassword.vue')['default']
|
||||||
APIKeyManagement: typeof import('./../src/components/userPersonalCenter/components/APIKeyManagement.vue')['default']
|
APIKeyManagement: typeof import('./../src/components/userPersonalCenter/components/APIKeyManagement.vue')['default']
|
||||||
|
CardFlipActivity: typeof import('./../src/components/userPersonalCenter/components/CardFlipActivity.vue')['default']
|
||||||
DailyTask: typeof import('./../src/components/userPersonalCenter/components/DailyTask.vue')['default']
|
DailyTask: typeof import('./../src/components/userPersonalCenter/components/DailyTask.vue')['default']
|
||||||
DeepThinking: typeof import('./../src/components/DeepThinking/index.vue')['default']
|
DeepThinking: typeof import('./../src/components/DeepThinking/index.vue')['default']
|
||||||
ElAlert: typeof import('element-plus/es')['ElAlert']
|
ElAlert: typeof import('element-plus/es')['ElAlert']
|
||||||
@@ -19,6 +20,7 @@ declare module 'vue' {
|
|||||||
ElCard: typeof import('element-plus/es')['ElCard']
|
ElCard: typeof import('element-plus/es')['ElCard']
|
||||||
ElCollapse: typeof import('element-plus/es')['ElCollapse']
|
ElCollapse: typeof import('element-plus/es')['ElCollapse']
|
||||||
ElCollapseItem: typeof import('element-plus/es')['ElCollapseItem']
|
ElCollapseItem: typeof import('element-plus/es')['ElCollapseItem']
|
||||||
|
ElCollapseTransition: typeof import('element-plus/es')['ElCollapseTransition']
|
||||||
ElContainer: typeof import('element-plus/es')['ElContainer']
|
ElContainer: typeof import('element-plus/es')['ElContainer']
|
||||||
ElDialog: typeof import('element-plus/es')['ElDialog']
|
ElDialog: typeof import('element-plus/es')['ElDialog']
|
||||||
ElDivider: typeof import('element-plus/es')['ElDivider']
|
ElDivider: typeof import('element-plus/es')['ElDivider']
|
||||||
|
|||||||
1
Yi.Ai.Vue3/types/import_meta.d.ts
vendored
1
Yi.Ai.Vue3/types/import_meta.d.ts
vendored
@@ -6,7 +6,6 @@ interface ImportMetaEnv {
|
|||||||
readonly VITE_WEB_ENV: string;
|
readonly VITE_WEB_ENV: string;
|
||||||
readonly VITE_WEB_BASE_API: string;
|
readonly VITE_WEB_BASE_API: string;
|
||||||
readonly VITE_API_URL: string;
|
readonly VITE_API_URL: string;
|
||||||
readonly VITE_BUILD_COMPRESS: string;
|
|
||||||
readonly VITE_SSO_SEVER_URL: string;
|
readonly VITE_SSO_SEVER_URL: string;
|
||||||
readonly VITE_APP_VERSION: string;
|
readonly VITE_APP_VERSION: string;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user