123 lines
3.8 KiB
C#
123 lines
3.8 KiB
C#
using AdminService.EmptyRoomRate;
|
|
using Common;
|
|
using CommonDomain;
|
|
using CommonDomain.Enum;
|
|
using CommonInfrastructure;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
namespace AdminApi.EmptyRoomRate
|
|
{
|
|
[ApiController, Route("adminapi/[controller]")]
|
|
[Authorize]
|
|
public class EmptyRoomRateConfigController : BaseController
|
|
{
|
|
private readonly IEmptyRoomRateConfigService _emptyRoomRateConfigService;
|
|
|
|
public EmptyRoomRateConfigController(IEmptyRoomRateConfigService emptyRoomRateConfigService)
|
|
{
|
|
_emptyRoomRateConfigService = emptyRoomRateConfigService;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取空房率配置列表
|
|
/// </summary>
|
|
[HttpGet("list")]
|
|
public async Task<PageResponse<EmptyRoomRateDto>> GetList(
|
|
[FromQuery] int page = 1,
|
|
[FromQuery] int size = 20,
|
|
[FromQuery] GameTypeEnum? gameType = null,
|
|
[FromQuery] int? roomLevel = null)
|
|
{
|
|
page = page > 0 ? page : 1;
|
|
size = size > 0 ? size : 20;
|
|
var result = await _emptyRoomRateConfigService.GetList(page, size, gameType, roomLevel);
|
|
var dtos = result.list.Select(MapToDto).ToList();
|
|
return this.ToPageResult(dtos, (int)result.count);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 新增空房率配置
|
|
/// </summary>
|
|
[HttpPost("add")]
|
|
public async Task<BaseResponse<string>> Add([FromBody] AddEmptyRoomRateParam param)
|
|
{
|
|
var result = await _emptyRoomRateConfigService.Add(param.GameType, param.RoomLevel, param.EmptyRoomRate);
|
|
if (result.isok)
|
|
return this.ToResult<string>(result.msg);
|
|
return this.ToFailResult<string>(result.msg);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 修改空房率配置
|
|
/// </summary>
|
|
[HttpPost("update")]
|
|
public async Task<BaseResponse<string>> Update([FromBody] UpdateEmptyRoomRateParam param)
|
|
{
|
|
var result = await _emptyRoomRateConfigService.Update(param.Id, param.EmptyRoomRate);
|
|
if (result.isok)
|
|
return this.ToResult<string>(result.msg);
|
|
return this.ToFailResult<string>(result.msg);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 删除空房率配置
|
|
/// </summary>
|
|
[HttpPost("delete")]
|
|
public async Task<BaseResponse<string>> Delete([FromBody] DeleteEmptyRoomRateParam param)
|
|
{
|
|
var result = await _emptyRoomRateConfigService.Delete(param.Id);
|
|
if (result.isok)
|
|
return this.ToResult<string>(result.msg);
|
|
return this.ToFailResult<string>(result.msg);
|
|
}
|
|
|
|
private static EmptyRoomRateDto MapToDto(EmptyRoomRateConfig entity)
|
|
{
|
|
if (entity == null) return new EmptyRoomRateDto();
|
|
return new EmptyRoomRateDto
|
|
{
|
|
Id = entity.Id ?? "",
|
|
GameType = (int)entity.GameType,
|
|
GameTypeName = entity.GameType.ToString(),
|
|
RoomLevel = entity.RoomLevel,
|
|
EmptyRoomRate = entity.EmptyRoomRate
|
|
};
|
|
}
|
|
}
|
|
|
|
public class EmptyRoomRateDto
|
|
{
|
|
public string Id { get; set; }
|
|
|
|
public int GameType { get; set; }
|
|
|
|
public string GameTypeName { get; set; }
|
|
|
|
public int RoomLevel { get; set; }
|
|
|
|
public int EmptyRoomRate { get; set; }
|
|
}
|
|
|
|
public class AddEmptyRoomRateParam
|
|
{
|
|
public GameTypeEnum GameType { get; set; }
|
|
|
|
public int RoomLevel { get; set; }
|
|
|
|
public int EmptyRoomRate { get; set; } = 30;
|
|
}
|
|
|
|
public class UpdateEmptyRoomRateParam
|
|
{
|
|
public string Id { get; set; }
|
|
|
|
public int EmptyRoomRate { get; set; }
|
|
}
|
|
|
|
public class DeleteEmptyRoomRateParam
|
|
{
|
|
public string Id { get; set; }
|
|
}
|
|
}
|