添加项目文件。
This commit is contained in:
@@ -0,0 +1,94 @@
|
||||
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<BaseResponse<LotteryConfigResponse>> GetConfig()
|
||||
{
|
||||
var config = await _activityConfigService.Get();
|
||||
if (config?.LotteryActivityConfig == null)
|
||||
return this.ToFailResult<LotteryConfigResponse>("配置不存在");
|
||||
|
||||
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<string>()
|
||||
});
|
||||
}
|
||||
|
||||
[HttpGet("Draw")]
|
||||
public async Task<BaseResponse<LotteryDrawResponse>> Draw([FromQuery] int poolType = 0)
|
||||
{
|
||||
var res = await _lotteryService.Draw(loginUser.UserId, poolType);
|
||||
if (!res.success)
|
||||
return this.ToFailResult<LotteryDrawResponse>(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<BaseResponse<LotteryUserStatus>> UserStatus()
|
||||
{
|
||||
var status = await _lotteryService.GetUserStatus(loginUser.UserId);
|
||||
return this.ToResult(status);
|
||||
}
|
||||
|
||||
[HttpGet("DrawnPrizes")]
|
||||
public async Task<BaseResponse<List<string>>> 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<string> DrawnPrizeIds { get; set; } = new();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user