feat: 调整翻牌与邀请码逻辑,增加第8次奖励及前端骨架屏
This commit is contained in:
@@ -198,14 +198,25 @@ public class CardFlipService : ApplicationService, ICardFlipService
|
||||
};
|
||||
|
||||
// 设置中奖信息
|
||||
// 判断这张卡是第几次翻的
|
||||
if (task != null && flippedNumbers.Contains(i))
|
||||
{
|
||||
if (i == 9 && task.HasNinthReward)
|
||||
var flipOrderIndex = flippedOrder.IndexOf(i) + 1; // 第几次翻的(1-based)
|
||||
|
||||
// 第8次翻的卡中奖
|
||||
if (flipOrderIndex == 8)
|
||||
{
|
||||
record.IsWin = true;
|
||||
record.RewardAmount = task.EighthRewardAmount;
|
||||
}
|
||||
// 第9次翻的卡中奖
|
||||
else if (flipOrderIndex == 9)
|
||||
{
|
||||
record.IsWin = true;
|
||||
record.RewardAmount = task.NinthRewardAmount;
|
||||
}
|
||||
else if (i == 10 && task.HasTenthReward)
|
||||
// 第10次翻的卡中奖
|
||||
else if (flipOrderIndex == 10)
|
||||
{
|
||||
record.IsWin = true;
|
||||
record.RewardAmount = task.TenthRewardAmount;
|
||||
@@ -232,15 +243,11 @@ public class CardFlipService : ApplicationService, ICardFlipService
|
||||
{
|
||||
return $"还有{status.RemainingFreeFlips}次免费翻牌机会";
|
||||
}
|
||||
else if (status.RemainingBonusFlips > 0)
|
||||
{
|
||||
return $"还有{status.RemainingBonusFlips}次赠送翻牌机会";
|
||||
}
|
||||
else if (status.RemainingInviteFlips > 0)
|
||||
{
|
||||
if (status.TotalFlips == 8)
|
||||
if (status.TotalFlips >= 7)
|
||||
{
|
||||
return "再邀请一个人,马上中奖!";
|
||||
return $"使用邀请码可解锁{status.RemainingInviteFlips}次翻牌,必中大奖!";
|
||||
}
|
||||
|
||||
return $"使用邀请码可解锁{status.RemainingInviteFlips}次翻牌";
|
||||
|
||||
@@ -65,13 +65,23 @@ public class CardFlipTaskAggregateRoot : FullAuditedAggregateRoot<Guid>
|
||||
/// </summary>
|
||||
public bool IsFirstFlipDone { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否已获得第8次奖励
|
||||
/// </summary>
|
||||
public bool HasEighthReward { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 第8次奖励金额(100-300w)
|
||||
/// </summary>
|
||||
public long? EighthRewardAmount { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否已获得第9次奖励
|
||||
/// </summary>
|
||||
public bool HasNinthReward { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 第9次奖励金额(300-700w)
|
||||
/// 第9次奖励金额(100-500w)
|
||||
/// </summary>
|
||||
public long? NinthRewardAmount { get; set; }
|
||||
|
||||
@@ -81,7 +91,7 @@ public class CardFlipTaskAggregateRoot : FullAuditedAggregateRoot<Guid>
|
||||
public bool HasTenthReward { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 第10次奖励金额(800-1200w)
|
||||
/// 第10次奖励金额(100-1000w)
|
||||
/// </summary>
|
||||
public long? TenthRewardAmount { get; set; }
|
||||
|
||||
@@ -124,6 +134,16 @@ public class CardFlipTaskAggregateRoot : FullAuditedAggregateRoot<Guid>
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 记录第8次奖励
|
||||
/// </summary>
|
||||
/// <param name="amount">奖励金额</param>
|
||||
public void SetEighthReward(long amount)
|
||||
{
|
||||
HasEighthReward = true;
|
||||
EighthRewardAmount = amount;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 记录第9次奖励
|
||||
/// </summary>
|
||||
|
||||
@@ -14,18 +14,21 @@ public class CardFlipManager : DomainService
|
||||
private readonly ILogger<CardFlipManager> _logger;
|
||||
|
||||
// 翻牌规则配置
|
||||
public const int MAX_FREE_FLIPS = 5; // 免费翻牌次数
|
||||
public const int MAX_BONUS_FLIPS = 3; // 赠送翻牌次数
|
||||
public const int MAX_INVITE_FLIPS = 2; // 邀请解锁翻牌次数
|
||||
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; // 总最大翻牌次数
|
||||
|
||||
private const int EIGHTH_FLIP = 8; // 第8次翻牌
|
||||
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
|
||||
private const long EIGHTH_MIN_REWARD = 1000000; // 第8次最小奖励 100w
|
||||
private const long EIGHTH_MAX_REWARD = 3000000; // 第8次最大奖励 300w
|
||||
private const long NINTH_MIN_REWARD = 1000000; // 第9次最小奖励 100w
|
||||
private const long NINTH_MAX_REWARD = 5000000; // 第9次最大奖励 500w
|
||||
private const long TENTH_MIN_REWARD = 1000000; // 第10次最小奖励 100w
|
||||
private const long TENTH_MAX_REWARD = 10000000; // 第10次最大奖励 1000w
|
||||
|
||||
public CardFlipManager(
|
||||
ISqlSugarRepository<CardFlipTaskAggregateRoot> cardFlipTaskRepository,
|
||||
@@ -104,23 +107,14 @@ public class CardFlipManager : DomainService
|
||||
throw new UserFriendlyException(GetFlipTypeErrorMessage(flipType));
|
||||
}
|
||||
|
||||
// 计算翻牌结果
|
||||
var result = CalculateFlipResult(flipNumber);
|
||||
// 计算翻牌结果(基于当前是第几次翻牌,而不是卡片序号)
|
||||
var flipCount = task.TotalFlips + 1; // 当前这次翻牌是第几次
|
||||
var result = CalculateFlipResult(flipCount);
|
||||
|
||||
// 记录奖励
|
||||
if (result.IsWin)
|
||||
{
|
||||
if (flipNumber == NINTH_FLIP)
|
||||
{
|
||||
task.SetNinthReward(result.RewardAmount);
|
||||
}
|
||||
else if (flipNumber == TENTH_FLIP)
|
||||
{
|
||||
task.SetTenthReward(result.RewardAmount);
|
||||
}
|
||||
}
|
||||
// 将卡片序号信息也返回
|
||||
result.FlipNumber = flipNumber;
|
||||
|
||||
// 更新翻牌次数
|
||||
// 更新翻牌次数(必须在记录奖励之前,因为需要先确定是第几次)
|
||||
task.IncrementFlip(flipType);
|
||||
|
||||
// 记录翻牌顺序
|
||||
@@ -130,6 +124,23 @@ public class CardFlipManager : DomainService
|
||||
}
|
||||
task.FlippedOrder.Add(flipNumber);
|
||||
|
||||
// 如果中奖,记录奖励金额(用于后续查询显示)
|
||||
if (result.IsWin)
|
||||
{
|
||||
if (flipCount == EIGHTH_FLIP)
|
||||
{
|
||||
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);
|
||||
|
||||
_logger.LogInformation($"用户 {userId} 完成第 {flipNumber} 次翻牌,中奖:{result.IsWin}");
|
||||
@@ -183,37 +194,45 @@ public class CardFlipManager : DomainService
|
||||
/// <summary>
|
||||
/// 计算翻牌结果
|
||||
/// </summary>
|
||||
private FlipResult CalculateFlipResult(int flipNumber)
|
||||
/// <param name="flipCount">第几次翻牌(1-10)</param>
|
||||
private FlipResult CalculateFlipResult(int flipCount)
|
||||
{
|
||||
var result = new FlipResult
|
||||
{
|
||||
FlipNumber = flipNumber,
|
||||
FlipNumber = 0, // 稍后会被设置为实际的卡片序号
|
||||
IsWin = false,
|
||||
ShowDoubleRewardTip = false
|
||||
};
|
||||
|
||||
// 前8次固定失败
|
||||
if (flipNumber <= 8)
|
||||
// 前7次固定失败
|
||||
if (flipCount <= 7)
|
||||
{
|
||||
result.IsWin = false;
|
||||
result.RewardDesc = "很遗憾,未中奖";
|
||||
}
|
||||
// 第9次中奖
|
||||
else if (flipNumber == NINTH_FLIP)
|
||||
// 第8次中奖 (邀请码解锁)
|
||||
else if (flipCount == EIGHTH_FLIP)
|
||||
{
|
||||
var rewardAmount = GenerateRandomReward(EIGHTH_MIN_REWARD, EIGHTH_MAX_REWARD);
|
||||
result.IsWin = true;
|
||||
result.RewardAmount = rewardAmount;
|
||||
result.RewardDesc = $"恭喜获得尊享包 {rewardAmount / 10000}w tokens!";
|
||||
}
|
||||
// 第9次中奖 (邀请码解锁)
|
||||
else if (flipCount == NINTH_FLIP)
|
||||
{
|
||||
var rewardAmount = GenerateRandomReward(NINTH_MIN_REWARD, NINTH_MAX_REWARD);
|
||||
result.IsWin = true;
|
||||
result.RewardAmount = rewardAmount;
|
||||
result.RewardDesc = $"恭喜获得尊享包 {rewardAmount / 10000}w tokens!";
|
||||
result.ShowDoubleRewardTip = true; // 显示翻倍包提示
|
||||
}
|
||||
// 第10次中奖(翻倍)
|
||||
else if (flipNumber == TENTH_FLIP)
|
||||
// 第10次中奖 (邀请码解锁)
|
||||
else if (flipCount == TENTH_FLIP)
|
||||
{
|
||||
var rewardAmount = GenerateRandomReward(TENTH_MIN_REWARD, TENTH_MAX_REWARD);
|
||||
result.IsWin = true;
|
||||
result.RewardAmount = rewardAmount;
|
||||
result.RewardDesc = $"恭喜获得尊享包 {rewardAmount / 10000}w tokens(翻倍奖励)!";
|
||||
result.RewardDesc = $"恭喜获得尊享包 {rewardAmount / 10000}w tokens!";
|
||||
}
|
||||
|
||||
return result;
|
||||
@@ -234,12 +253,22 @@ public class CardFlipManager : DomainService
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 生成随机奖励金额
|
||||
/// 生成随机奖励金额 (最小单位100w)
|
||||
/// </summary>
|
||||
private long GenerateRandomReward(long min, long max)
|
||||
{
|
||||
var random = new Random();
|
||||
return (long)(random.NextDouble() * (max - min) + min);
|
||||
const long unit = 1000000; // 100w的单位
|
||||
|
||||
// 将min和max转换为100w的倍数
|
||||
long minUnits = min / unit;
|
||||
long maxUnits = max / unit;
|
||||
|
||||
// 在倍数范围内随机
|
||||
long randomUnits = random.Next((int)minUnits, (int)maxUnits + 1);
|
||||
|
||||
// 返回100w的倍数
|
||||
return randomUnits * unit;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -265,10 +294,6 @@ public class CardFlipManager : DomainService
|
||||
{
|
||||
return "免费";
|
||||
}
|
||||
else if (flipNumber <= MAX_FREE_FLIPS + MAX_BONUS_FLIPS)
|
||||
{
|
||||
return "赠送";
|
||||
}
|
||||
else
|
||||
{
|
||||
return "邀请解锁";
|
||||
|
||||
@@ -353,6 +353,8 @@ namespace Yi.Abp.Web
|
||||
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);
|
||||
|
||||
@@ -5,7 +5,8 @@ import { onMounted, ref } from 'vue';
|
||||
import { flipCard, generateMyInviteCode, getWeeklyTaskStatus, useInviteCode } from '@/api/cardFlip';
|
||||
|
||||
const taskData = ref<CardFlipStatusOutput | null>(null);
|
||||
const loading = ref(false);
|
||||
const loading = ref(false); // 操作加载状态(使用邀请码等)
|
||||
const initialLoading = ref(true); // 初始加载状态
|
||||
const flipping = ref(false);
|
||||
const inviteCodeDialog = ref(false);
|
||||
const inputInviteCode = ref('');
|
||||
@@ -22,7 +23,15 @@ onMounted(() => {
|
||||
|
||||
// 获取任务状态
|
||||
async function fetchTaskStatus() {
|
||||
// 首次加载时使用 initialLoading,避免白屏闪烁
|
||||
const isInitialLoad = taskData.value === null;
|
||||
if (isInitialLoad) {
|
||||
initialLoading.value = true;
|
||||
}
|
||||
else {
|
||||
loading.value = true;
|
||||
}
|
||||
|
||||
try {
|
||||
const res = await getWeeklyTaskStatus();
|
||||
taskData.value = res.data;
|
||||
@@ -31,9 +40,14 @@ async function fetchTaskStatus() {
|
||||
ElMessage.error(error?.message || '获取任务状态失败');
|
||||
}
|
||||
finally {
|
||||
if (isInitialLoad) {
|
||||
initialLoading.value = false;
|
||||
}
|
||||
else {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 翻牌
|
||||
async function handleFlipCard(record: CardFlipRecord) {
|
||||
@@ -42,11 +56,17 @@ async function handleFlipCard(record: CardFlipRecord) {
|
||||
|
||||
if (canFlip) {
|
||||
// 检查是否需要使用邀请码
|
||||
if (record.flipNumber > 8 && (taskData.value?.remainingInviteFlips || 0) > 0) {
|
||||
const usedInviteFlips = 2 - (taskData.value?.remainingInviteFlips || 2);
|
||||
if (usedInviteFlips < (record.flipNumber - 8)) {
|
||||
// 当前已翻次数
|
||||
const currentFlips = taskData.value?.totalFlips || 0;
|
||||
|
||||
// 如果已经翻了7次或以上,需要检查邀请码
|
||||
if (currentFlips >= 7) {
|
||||
const remainingInviteFlips = taskData.value?.remainingInviteFlips || 0;
|
||||
|
||||
// 如果没有剩余邀请次数,提示需要使用邀请码
|
||||
if (remainingInviteFlips === 0) {
|
||||
ElMessageBox.confirm(
|
||||
'🎁 需要先使用邀请码解锁此次翻牌机会哦~',
|
||||
'🎁 需要先使用邀请码解锁更多翻牌机会哦~',
|
||||
'温馨提示',
|
||||
{
|
||||
confirmButtonText: '去使用',
|
||||
@@ -62,13 +82,17 @@ async function handleFlipCard(record: CardFlipRecord) {
|
||||
}
|
||||
}
|
||||
|
||||
// 标记为正在翻牌(显示加载状态,但不播放动画)
|
||||
flipping.value = true;
|
||||
flippingCards.value.add(record.flipNumber);
|
||||
|
||||
try {
|
||||
// 先请求后端接口
|
||||
const res = await flipCard({ flipNumber: record.flipNumber });
|
||||
lastFlipResult.value = res.data;
|
||||
|
||||
// 请求成功后,开始播放翻牌动画
|
||||
flippingCards.value.add(record.flipNumber);
|
||||
|
||||
// 等待翻牌动画完成
|
||||
await new Promise(resolve => setTimeout(resolve, 800));
|
||||
|
||||
@@ -105,6 +129,8 @@ async function handleFlipCard(record: CardFlipRecord) {
|
||||
}
|
||||
catch (error: any) {
|
||||
ElMessage.error(error?.message || '翻牌失败');
|
||||
// 如果请求失败,移除翻牌动画
|
||||
flippingCards.value.delete(record.flipNumber);
|
||||
}
|
||||
finally {
|
||||
flipping.value = false;
|
||||
@@ -236,6 +262,18 @@ function toggleInviteSection() {
|
||||
|
||||
<template>
|
||||
<div v-loading="loading" class="card-flip-container">
|
||||
<!-- 初始加载骨架屏 -->
|
||||
<div v-if="initialLoading" class="loading-skeleton">
|
||||
<div class="skeleton-stats">
|
||||
<div v-for="i in 3" :key="i" class="skeleton-stat-item" />
|
||||
</div>
|
||||
<div class="skeleton-cards">
|
||||
<div v-for="i in 10" :key="i" class="skeleton-card" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 主内容 -->
|
||||
<template v-else>
|
||||
<!-- 邀请码操作区 -->
|
||||
<div class="bottom-actions">
|
||||
<el-button
|
||||
@@ -287,7 +325,7 @@ function toggleInviteSection() {
|
||||
</div>
|
||||
|
||||
<div class="invite-tip">
|
||||
💌 分享给好友,好友使用后可解锁最后2次翻牌机会
|
||||
💌 分享给好友,好友使用后可解锁最后3次翻牌机会
|
||||
</div>
|
||||
</div>
|
||||
</el-collapse-transition>
|
||||
@@ -402,11 +440,6 @@ function toggleInviteSection() {
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 锁定遮罩 -->
|
||||
<div v-if="!record.isFlipped && record.flipNumber > (taskData?.totalFlips || 0) + 1" class="card-lock">
|
||||
<span class="lock-icon">🔒</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -422,7 +455,7 @@ function toggleInviteSection() {
|
||||
>
|
||||
<div class="invite-dialog-content">
|
||||
<p class="dialog-tip">
|
||||
请输入好友的邀请码,解锁最后2次翻牌机会
|
||||
请输入好友的邀请码,解锁最后3次翻牌机会
|
||||
</p>
|
||||
<el-input
|
||||
v-model="inputInviteCode"
|
||||
@@ -477,6 +510,7 @@ function toggleInviteSection() {
|
||||
</el-button>
|
||||
</div>
|
||||
</el-dialog>
|
||||
</template>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -1139,4 +1173,52 @@ function toggleInviteSection() {
|
||||
opacity: 1;
|
||||
}
|
||||
}
|
||||
|
||||
/* 骨架屏样式 */
|
||||
.loading-skeleton {
|
||||
padding: 16px 0;
|
||||
|
||||
.skeleton-stats {
|
||||
display: flex;
|
||||
gap: 12px;
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
|
||||
.skeleton-stat-item {
|
||||
flex: 1;
|
||||
height: 64px;
|
||||
background: linear-gradient(90deg, rgba(255, 255, 255, 0.1) 25%, rgba(255, 255, 255, 0.2) 50%, rgba(255, 255, 255, 0.1) 75%);
|
||||
background-size: 200% 100%;
|
||||
border-radius: 12px;
|
||||
animation: skeleton-loading 1.5s ease-in-out infinite;
|
||||
}
|
||||
|
||||
.skeleton-cards {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(5, 1fr);
|
||||
gap: 10px;
|
||||
|
||||
@media (max-width: 768px) {
|
||||
grid-template-columns: repeat(5, 1fr);
|
||||
gap: 8px;
|
||||
}
|
||||
}
|
||||
|
||||
.skeleton-card {
|
||||
aspect-ratio: 3/4;
|
||||
background: linear-gradient(90deg, rgba(255, 255, 255, 0.1) 25%, rgba(255, 255, 255, 0.2) 50%, rgba(255, 255, 255, 0.1) 75%);
|
||||
background-size: 200% 100%;
|
||||
border-radius: 10px;
|
||||
animation: skeleton-loading 1.5s ease-in-out infinite;
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes skeleton-loading {
|
||||
0% {
|
||||
background-position: 200% 0;
|
||||
}
|
||||
100% {
|
||||
background-position: -200% 0;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
Reference in New Issue
Block a user