Changes: - Remove deprecated Fengling.Activity and YarpGateway.Admin projects - Add points processing services with distributed lock support - Update Vben frontend with gateway management pages - Add gateway config controller and database listener - Update routing to use header-mixed-nav layout - Add comprehensive test suites for Member services - Add YarpGateway integration tests - Update package versions in Directory.Packages.props Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
59 lines
2.0 KiB
C#
59 lines
2.0 KiB
C#
namespace Fengling.Activity.Domain.Strategies.Actions;
|
|
|
|
using Fengling.Activity.Domain.ValueObjects;
|
|
|
|
public class LotteryAction : IActionStrategy
|
|
{
|
|
public string StrategyType => "Lottery";
|
|
|
|
public Task<ActionResult> ExecuteAsync(CampaignContext context, ActionConfig config, CancellationToken cancellationToken = default)
|
|
{
|
|
var lotteryPoolId = config.GetParameter<string>("LotteryPoolId");
|
|
|
|
var random = new Random();
|
|
var prizes = context.AdditionalData.TryGetValue("LotteryPrizes", out var prizesObj)
|
|
? prizesObj is List<Dictionary<string, object>> list ? list : null
|
|
: null;
|
|
|
|
Dictionary<string, object>? selectedPrize = null;
|
|
|
|
if (prizes != null && prizes.Count > 0)
|
|
{
|
|
var totalWeight = prizes.Sum(p => p.TryGetValue("Weight", out var w) && w is int weight ? weight : 1);
|
|
var randomValue = random.Next(totalWeight);
|
|
var currentWeight = 0;
|
|
|
|
foreach (var prize in prizes)
|
|
{
|
|
var weight = prize.TryGetValue("Weight", out var w) && w is int i ? i : 1;
|
|
currentWeight += weight;
|
|
if (randomValue < currentWeight)
|
|
{
|
|
selectedPrize = prize;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
var rewards = new Dictionary<string, object?>
|
|
{
|
|
{ "LotteryPoolId", lotteryPoolId ?? "" },
|
|
{ "CampaignId", context.CampaignId.ToString() },
|
|
{ "GrantedAt", DateTime.UtcNow }
|
|
};
|
|
|
|
if (selectedPrize != null)
|
|
{
|
|
rewards["Prize"] = selectedPrize;
|
|
var name = selectedPrize.TryGetValue("Name", out var n) ? n?.ToString() : null;
|
|
rewards["Message"] = $"Congratulations! You won: {name ?? "a prize"}";
|
|
}
|
|
else
|
|
{
|
|
rewards["Message"] = "Better luck next time!";
|
|
}
|
|
|
|
return Task.FromResult(ActionResult.Success(rewards));
|
|
}
|
|
}
|