using Common; using CommonDomain; using CommonInfrastructure; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using UserDomain.Entity; using UserService; using UserService.GameConfigs; namespace UserApi.Lottery { [ApiController, Route("api/[controller]")] [Authorize] public class LotteryController : BaseController { private readonly ILotteryService _lotteryService; private readonly IActivityConfigService _activityConfigService; private readonly IGameConfigService _gameConfigService; public LotteryController(ILotteryService lotteryService, IActivityConfigService activityConfigService, IGameConfigService gameConfigService) { _lotteryService = lotteryService; _activityConfigService = activityConfigService; _gameConfigService = gameConfigService; } [HttpGet("Config")] public async Task> GetConfig() { var config = await _activityConfigService.Get(); if (config?.LotteryActivityConfig == null) return this.ToFailResult("配置不存在"); LotteryPrizeProductHelper.Enrich(config.LotteryActivityConfig, await _gameConfigService.Get()); var drawnPrizes = await _lotteryService.GetUserDrawnPrizes(loginUser.UserId); return this.ToResult(new LotteryConfigResponse { Config = config.LotteryActivityConfig, DrawnPrizeIds = drawnPrizes ?? new List() }); } [HttpGet("Draw")] public async Task> Draw([FromQuery] int poolType = 0) { var res = await _lotteryService.Draw(loginUser.UserId, poolType); if (!res.success) return this.ToFailResult(res.message); return this.ToResult(new LotteryDrawResponse { PrizeId = res.prize.PrizeId, Name = res.prize.Name, Type = res.prize.Type, Count = res.prize.Count, OtherId = res.prize.OtherId, Cost = res.cost, PoolType = poolType }); } [HttpGet("UserStatus")] public async Task> UserStatus() { var status = await _lotteryService.GetUserStatus(loginUser.UserId); return this.ToResult(status); } [HttpGet("DrawnPrizes")] public async Task>> DrawnPrizes() { var list = await _lotteryService.GetUserDrawnPrizes(loginUser.UserId); return this.ToResult(list); } } public class LotteryDrawResponse { public string PrizeId { get; set; } public string Name { get; set; } public int Type { get; set; } public long Count { get; set; } public string OtherId { get; set; } public long Cost { get; set; } public int PoolType { get; set; } } public class LotteryConfigResponse { public LotteryActivityConfig Config { get; set; } public List DrawnPrizeIds { get; set; } = new(); } }