33 lines
1.0 KiB
C#
33 lines
1.0 KiB
C#
using Fengling.RiskControl.Domain.Aggregates.RiskScores;
|
|
using Fengling.RiskControl.Domain.Events;
|
|
using Fengling.RiskControl.Domain.Repositories;
|
|
using MediatR;
|
|
|
|
namespace Fengling.RiskControl.Application.Events;
|
|
|
|
public class LotteryCompletedEventHandler : INotificationHandler<LotteryCompletedEvent>
|
|
{
|
|
private readonly IRiskScoreRepository _scoreRepository;
|
|
|
|
public LotteryCompletedEventHandler(IRiskScoreRepository scoreRepository)
|
|
{
|
|
_scoreRepository = scoreRepository;
|
|
}
|
|
|
|
public async Task Handle(LotteryCompletedEvent notification, CancellationToken cancellationToken)
|
|
{
|
|
var score = RiskScore.Create(
|
|
notification.MemberId,
|
|
"lottery_result",
|
|
notification.ActivityId.ToString(),
|
|
expiresAt: DateTime.UtcNow.AddDays(1));
|
|
|
|
if (notification.IsWin && notification.WinAmount > notification.StakePoints * 5)
|
|
{
|
|
score.AddRiskFactor("big_win", 20, "赢得超过投入5倍");
|
|
}
|
|
|
|
await _scoreRepository.AddAsync(score);
|
|
}
|
|
}
|