111 lines
3.7 KiB
C#
111 lines
3.7 KiB
C#
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
namespace Application.Web.Controllers.Pub
|
|
{
|
|
/// <summary>
|
|
/// 公共接口
|
|
/// </summary>
|
|
[Route("[controller]/[action]")]
|
|
[ApiController]
|
|
public class PubController : ControllerBase
|
|
{
|
|
private readonly IAreaService _areaService;
|
|
private readonly INoticeService _noticeService;
|
|
private readonly IGameAccountService _accountService;
|
|
private readonly IUnitUserService _userService;
|
|
|
|
public PubController(IAreaService areaService, INoticeService noticeService, IGameAccountService accountService,IUnitUserService userService)
|
|
{
|
|
_areaService = areaService;
|
|
_noticeService = noticeService;
|
|
_accountService = accountService;
|
|
_userService = userService;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取首页信息
|
|
/// </summary>
|
|
/// <param name="sid"></param>
|
|
/// <returns></returns>
|
|
[HttpGet]
|
|
public async Task<IPoAction> GetMain(string? sid)
|
|
{
|
|
bool isOnline = false;
|
|
game_account account = new game_account();
|
|
List<unit_user> userData = new List<unit_user>();
|
|
if (!string.IsNullOrEmpty(sid))
|
|
{
|
|
account = await _accountService.GetAccInfoByToken(sid);
|
|
if (account != null)
|
|
{
|
|
isOnline = true;
|
|
userData = await _userService.GetUserDataByAccId(account.accId);
|
|
}
|
|
}
|
|
|
|
var areaData = await _areaService.GetAreaData();
|
|
foreach (var _user in userData)
|
|
{
|
|
areaData.RemoveAll(it => it.areaId == _user.areaId);
|
|
}
|
|
|
|
var notice = await _noticeService.GetNoticeDataByTake(5);
|
|
|
|
int OnCount = await _userService.GetOnlineCount();
|
|
return PoAction.Ok(new { area = areaData, notice, isOnline, onCount = OnCount, account,userData });
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取公告列表
|
|
/// </summary>
|
|
/// <param name="page"></param>
|
|
/// <param name="limit"></param>
|
|
/// <returns></returns>
|
|
[HttpGet]
|
|
public async Task<IPoAction> GetNoticeData(int page, int limit)
|
|
{
|
|
RefAsync<int> total = 0;
|
|
var data = await _noticeService.GetNoticeData(page, limit, total);
|
|
return PoAction.Ok(new { data, total = total.Value });
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取公告详情
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <returns></returns>
|
|
[HttpGet]
|
|
public async Task<IPoAction> GetNoticeInfo(string id)
|
|
{
|
|
var data = await _noticeService.GetNoticeInfo(id);
|
|
if (data == null)
|
|
{
|
|
return PoAction.Message("公告不存在!");
|
|
}
|
|
data.sign = data.sign.Replace("[Br]", "<br />");
|
|
return PoAction.Ok(data);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取用户游戏角色
|
|
/// </summary>
|
|
/// <param name="sid"></param>
|
|
/// <returns></returns>
|
|
[HttpGet]
|
|
public async Task<IPoAction> GetMyGame(string? sid)
|
|
{
|
|
List<unit_user> userData = new List<unit_user>();
|
|
if (!string.IsNullOrEmpty(sid))
|
|
{
|
|
var account = await _accountService.GetAccInfoByToken(sid);
|
|
if (account != null)
|
|
{
|
|
userData = await _userService.GetUserDataByAccId(account.accId);
|
|
}
|
|
}
|
|
return PoAction.Ok(userData);
|
|
}
|
|
|
|
}
|
|
} |