321
This commit is contained in:
parent
5137684fbc
commit
50e4a02200
|
|
@ -52,10 +52,10 @@ public class RewardService : IRewardService
|
||||||
query = query.Where(r => r.Description != null && r.Description.Contains(request.Keyword));
|
query = query.Where(r => r.Description != null && r.Description.Contains(request.Keyword));
|
||||||
}
|
}
|
||||||
|
|
||||||
// 按奖励ID筛选
|
// 按奖励ID筛选(模糊搜索)
|
||||||
if (!string.IsNullOrWhiteSpace(request.RewardId))
|
if (!string.IsNullOrWhiteSpace(request.RewardId))
|
||||||
{
|
{
|
||||||
query = query.Where(r => r.RewardId == request.RewardId);
|
query = query.Where(r => r.RewardId.Contains(request.RewardId));
|
||||||
}
|
}
|
||||||
|
|
||||||
var total = await query.CountAsync();
|
var total = await query.CountAsync();
|
||||||
|
|
|
||||||
|
|
@ -271,7 +271,6 @@
|
||||||
<el-input-number
|
<el-input-number
|
||||||
v-model.number="formData.poster_qr_x"
|
v-model.number="formData.poster_qr_x"
|
||||||
:min="0"
|
:min="0"
|
||||||
:max="2000"
|
|
||||||
placeholder="二维码左上角X坐标"
|
placeholder="二维码左上角X坐标"
|
||||||
style="width: 100%"
|
style="width: 100%"
|
||||||
/>
|
/>
|
||||||
|
|
@ -283,7 +282,6 @@
|
||||||
<el-input-number
|
<el-input-number
|
||||||
v-model.number="formData.poster_qr_y"
|
v-model.number="formData.poster_qr_y"
|
||||||
:min="0"
|
:min="0"
|
||||||
:max="3000"
|
|
||||||
placeholder="二维码左上角Y坐标"
|
placeholder="二维码左上角Y坐标"
|
||||||
style="width: 100%"
|
style="width: 100%"
|
||||||
/>
|
/>
|
||||||
|
|
@ -295,7 +293,6 @@
|
||||||
<el-input-number
|
<el-input-number
|
||||||
v-model.number="formData.poster_qr_size"
|
v-model.number="formData.poster_qr_size"
|
||||||
:min="50"
|
:min="50"
|
||||||
:max="500"
|
|
||||||
placeholder="二维码大小"
|
placeholder="二维码大小"
|
||||||
style="width: 100%"
|
style="width: 100%"
|
||||||
/>
|
/>
|
||||||
|
|
|
||||||
|
|
@ -176,22 +176,30 @@ public class WelfareLotteryService : BackgroundService
|
||||||
}
|
}
|
||||||
|
|
||||||
// 发放奖励
|
// 发放奖励
|
||||||
// 1. 如果是货币类型奖品(GoodsType=3),直接发放ScMoney金额
|
// 1. 如果有reward_id(字符串类型奖励码),通过奖励配置发放
|
||||||
if (prize.GoodsType == 3 && prize.ScMoney > 0)
|
if (!string.IsNullOrEmpty(prize.RewardId))
|
||||||
|
{
|
||||||
|
var rewardSent = await SendRewardByCodeAsync(dbContext, participant.UserId, prize.RewardId,
|
||||||
|
$"{goods.Title}开奖-{prize.Title}", stoppingToken);
|
||||||
|
if (rewardSent)
|
||||||
|
{
|
||||||
|
_logger.LogInformation("发放奖励成功: GoodsId={GoodsId}, UserId={UserId}, Prize={Prize}, RewardCode={RewardCode}",
|
||||||
|
goods.Id, participant.UserId, prize.Title, prize.RewardId);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_logger.LogWarning("奖励配置不存在: GoodsId={GoodsId}, UserId={UserId}, Prize={Prize}, RewardCode={RewardCode}",
|
||||||
|
goods.Id, participant.UserId, prize.Title, prize.RewardId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 2. 如果是货币类型奖品(GoodsType=3)且没有reward_id,直接发放ScMoney金额
|
||||||
|
else if (prize.GoodsType == 3 && prize.ScMoney > 0)
|
||||||
{
|
{
|
||||||
await SendCurrencyPrizeAsync(dbContext, participant.UserId, prize.ScMoney,
|
await SendCurrencyPrizeAsync(dbContext, participant.UserId, prize.ScMoney,
|
||||||
$"{goods.Title}开奖-{prize.Title}", stoppingToken);
|
$"{goods.Title}开奖-{prize.Title}", stoppingToken);
|
||||||
_logger.LogInformation("发放货币奖品成功: GoodsId={GoodsId}, UserId={UserId}, Prize={Prize}, Amount={Amount}",
|
_logger.LogInformation("发放货币奖品成功: GoodsId={GoodsId}, UserId={UserId}, Prize={Prize}, Amount={Amount}",
|
||||||
goods.Id, participant.UserId, prize.Title, prize.ScMoney);
|
goods.Id, participant.UserId, prize.Title, prize.ScMoney);
|
||||||
}
|
}
|
||||||
// 2. 如果有reward_id,通过奖励配置发放
|
|
||||||
else if (!string.IsNullOrEmpty(prize.RewardId) && int.TryParse(prize.RewardId, out var rewardId) && rewardId > 0)
|
|
||||||
{
|
|
||||||
await SendRewardAsync(dbContext, participant.UserId, rewardId,
|
|
||||||
$"{goods.Title}开奖", stoppingToken);
|
|
||||||
_logger.LogInformation("发放奖励成功: GoodsId={GoodsId}, UserId={UserId}, Prize={Prize}, RewardId={RewardId}",
|
|
||||||
goods.Id, participant.UserId, prize.Title, rewardId);
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_logger.LogInformation("发放奖品成功: GoodsId={GoodsId}, UserId={UserId}, Prize={Prize}",
|
_logger.LogInformation("发放奖品成功: GoodsId={GoodsId}, UserId={UserId}, Prize={Prize}",
|
||||||
|
|
@ -231,24 +239,30 @@ public class WelfareLotteryService : BackgroundService
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 发放奖励
|
/// 通过奖励码发放奖励
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private async Task SendRewardAsync(
|
/// <param name="dbContext">数据库上下文</param>
|
||||||
|
/// <param name="userId">用户ID</param>
|
||||||
|
/// <param name="rewardCode">奖励码(字符串)</param>
|
||||||
|
/// <param name="remark">备注</param>
|
||||||
|
/// <param name="stoppingToken">取消令牌</param>
|
||||||
|
/// <returns>是否成功发放</returns>
|
||||||
|
private async Task<bool> SendRewardByCodeAsync(
|
||||||
HoneyBoxDbContext dbContext,
|
HoneyBoxDbContext dbContext,
|
||||||
int userId,
|
int userId,
|
||||||
int rewardId,
|
string rewardCode,
|
||||||
string remark,
|
string remark,
|
||||||
CancellationToken stoppingToken)
|
CancellationToken stoppingToken)
|
||||||
{
|
{
|
||||||
// 获取奖励配置
|
// 通过奖励码查询奖励配置
|
||||||
var reward = await dbContext.Rewards
|
var reward = await dbContext.Rewards
|
||||||
.Where(r => r.Id == rewardId)
|
.Where(r => r.RewardId == rewardCode)
|
||||||
.FirstOrDefaultAsync(stoppingToken);
|
.FirstOrDefaultAsync(stoppingToken);
|
||||||
|
|
||||||
if (reward == null)
|
if (reward == null)
|
||||||
{
|
{
|
||||||
_logger.LogWarning("奖励配置不存在: RewardId={RewardId}", rewardId);
|
_logger.LogWarning("奖励配置不存在: RewardCode={RewardCode}", rewardCode);
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
var user = await dbContext.Users
|
var user = await dbContext.Users
|
||||||
|
|
@ -258,33 +272,79 @@ public class WelfareLotteryService : BackgroundService
|
||||||
if (user == null)
|
if (user == null)
|
||||||
{
|
{
|
||||||
_logger.LogWarning("用户不存在: UserId={UserId}", userId);
|
_logger.LogWarning("用户不存在: UserId={UserId}", userId);
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var rewardTypeName = "";
|
||||||
|
|
||||||
// 根据奖励类型发放
|
// 根据奖励类型发放
|
||||||
switch (reward.RewardType)
|
switch (reward.RewardType)
|
||||||
{
|
{
|
||||||
case 1: // 钻石/余额
|
case 1: // 钻石/余额 (HH币)
|
||||||
user.Money += reward.RewardValue;
|
user.Money += reward.RewardValue;
|
||||||
_logger.LogInformation("发放钻石: UserId={UserId}, Amount={Amount}", userId, reward.RewardValue);
|
// 记录流水
|
||||||
|
dbContext.ProfitMoneys.Add(new ProfitMoney
|
||||||
|
{
|
||||||
|
UserId = userId,
|
||||||
|
ChangeMoney = reward.RewardValue,
|
||||||
|
Money = user.Money,
|
||||||
|
Type = 6, // 签到赠送/福利奖励
|
||||||
|
Content = remark,
|
||||||
|
ShareUid = 0,
|
||||||
|
CreatedAt = DateTime.Now
|
||||||
|
});
|
||||||
|
rewardTypeName = "钻石/HH币";
|
||||||
|
_logger.LogInformation("发放钻石: UserId={UserId}, Amount={Amount}, After={After}, Remark={Remark}",
|
||||||
|
userId, reward.RewardValue, user.Money, remark);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 2: // 积分/UU币
|
case 2: // 积分/UU币
|
||||||
user.Integral += reward.RewardValue;
|
user.Integral += reward.RewardValue;
|
||||||
_logger.LogInformation("发放积分: UserId={UserId}, Amount={Amount}", userId, reward.RewardValue);
|
// 记录流水
|
||||||
|
dbContext.ProfitIntegrals.Add(new ProfitIntegral
|
||||||
|
{
|
||||||
|
UserId = userId,
|
||||||
|
ChangeMoney = reward.RewardValue,
|
||||||
|
Money = user.Integral,
|
||||||
|
Type = 4, // 抽赏奖励
|
||||||
|
Content = remark,
|
||||||
|
ShareUid = 0,
|
||||||
|
CreatedAt = DateTime.Now
|
||||||
|
});
|
||||||
|
rewardTypeName = "积分/UU币";
|
||||||
|
_logger.LogInformation("发放积分: UserId={UserId}, Amount={Amount}, After={After}, Remark={Remark}",
|
||||||
|
userId, reward.RewardValue, user.Integral, remark);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 3: // 哈尼券/达达卷
|
case 3: // 哈尼券/达达卷
|
||||||
user.Money2 = (user.Money2 ?? 0) + reward.RewardValue;
|
user.Money2 = (user.Money2 ?? 0) + reward.RewardValue;
|
||||||
_logger.LogInformation("发放哈尼券: UserId={UserId}, Amount={Amount}", userId, reward.RewardValue);
|
// 记录流水
|
||||||
|
dbContext.ProfitMoney2s.Add(new ProfitMoney2
|
||||||
|
{
|
||||||
|
UserId = userId,
|
||||||
|
ChangeMoney = reward.RewardValue,
|
||||||
|
Money = user.Money2 ?? 0,
|
||||||
|
Type = 5, // 推荐奖励/福利奖励
|
||||||
|
Content = remark,
|
||||||
|
ShareUid = 0,
|
||||||
|
CreatedAt = DateTime.Now
|
||||||
|
});
|
||||||
|
rewardTypeName = "哈尼券";
|
||||||
|
_logger.LogInformation("发放哈尼券: UserId={UserId}, Amount={Amount}, After={After}, Remark={Remark}",
|
||||||
|
userId, reward.RewardValue, user.Money2, remark);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
_logger.LogWarning("未知奖励类型: Type={Type}", reward.RewardType);
|
_logger.LogWarning("未知奖励类型: Type={Type}, RewardCode={RewardCode}", reward.RewardType, rewardCode);
|
||||||
break;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
await dbContext.SaveChangesAsync(stoppingToken);
|
await dbContext.SaveChangesAsync(stoppingToken);
|
||||||
|
|
||||||
|
_logger.LogInformation("福利屋奖励发放成功: UserId={UserId}, RewardCode={RewardCode}, Type={Type}, Value={Value}, Remark={Remark}",
|
||||||
|
userId, rewardCode, rewardTypeName, reward.RewardValue, remark);
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user