Files
Kg.SeaTime/Service/Application.Web/Controllers/Pub/BadgeController.cs
2026-07-13 14:28:33 +08:00

102 lines
3.2 KiB
C#

using Application.Domain.Services;
using Application.Web.Model.RequestParms.Maxname;
using Microsoft.AspNetCore.Mvc;
namespace Application.Web.Controllers.Pub
{
/// <summary>
/// 徽章接口
/// </summary>
[Route("[controller]/[action]")]
[ApiController]
[Authorize]
public class BadgeController : ControllerBase
{
private readonly IGameBadgeService badgeService;
public BadgeController(IGameBadgeService _badgeService)
{
badgeService = _badgeService;
}
/// <summary>
/// 获取用户徽章列表
/// </summary>
/// <param name="page"></param>
/// <returns></returns>
[HttpGet]
public async Task<IPoAction> GetUserBadgeList(int page)
{
RefAsync<int> total = 0;
string userId = StateHelper.userId;
var list = await badgeService.GetUserBadgeList(userId, page, 10, total);
return PoAction.Ok(new { list, total });
}
/// <summary>
/// 获取徽章详情
/// </summary>
/// <param name="ubId"></param>
/// <returns></returns>
[HttpGet]
public async Task<IPoAction> GetUserBadgeInfo(string ubId)
{
var data = await badgeService.GetUserBadegInfo(ubId);
if (data == null)
{
return PoAction.Message("徽章信息不存在!");
}
string userId = StateHelper.userId;
if (data.userId != userId)
{
return PoAction.Message("徽章信息不存在!");
}
return PoAction.Ok(new { data });
}
/// <summary>
/// 修改徽章展示不展示
/// </summary>
/// <param name="par"></param>
/// <returns></returns>
[HttpPost]
public async Task<IPoAction> UpdateBadgeShow([FromBody] UpdateBadgeParms par)
{
var data = await badgeService.GetUserBadegInfo(par.ubId);
if (data == null)
{
return PoAction.Message("徽章信息不存在!");
}
string userId = StateHelper.userId;
if (data.userId != userId)
{
return PoAction.Message("徽章信息不存在!");
}
//int onCount = await badgeService.GetUserShowBadgeOnCount(userId);
//int showCount = await badgeService.GetUserShowBadgeCount(userId);
//if (onCount == 0)
//{
// if (showCount >= 1)
// {
// return PoAction.Message("您最多可以同时展示1个徽章!");
// }
//}
//else
//{
// if (showCount >= onCount)
// {
// return PoAction.Message(string.Format("您最多可以同时展示{0}个徽章!", onCount));
// }
//}
int show = data.show == 1 ? 0 : 1;
if (await badgeService.UpdateUserBadgeShow(par.ubId, show))
{
return PoAction.Ok("操作成功!");
}
else
{
return PoAction.Message("操作失败!");
}
}
}
}