88 lines
3.2 KiB
C#
88 lines
3.2 KiB
C#
using Microsoft.AspNetCore.Mvc;
|
|
|
|
namespace Application.Web.Controllers.User;
|
|
|
|
[ApiExplorerSettings(GroupName = "User")]
|
|
[Route("User/[controller]/[action]")]
|
|
[ApiController]
|
|
[Authorize]
|
|
public class UserController : ControllerBase
|
|
{
|
|
private readonly IUnitUserService _userService;
|
|
private readonly IUnitUserAttrService _attrService;
|
|
private readonly IUnitUserAccService _accService;
|
|
private readonly IGameMapService _mapService;
|
|
|
|
public UserController(IUnitUserService userService, IUnitUserAttrService attrService,
|
|
IUnitUserAccService accService, IGameMapService mapService)
|
|
{
|
|
_userService = userService;
|
|
_attrService = attrService;
|
|
_accService = accService;
|
|
_mapService = mapService;
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 获取个人资料信息
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[HttpGet]
|
|
public async Task<IPoAction> GetUserInfo()
|
|
{
|
|
string userId = StateHelper.userId;
|
|
var userInfo = await _userService.GetUserInfoByUserId(userId); //基础资料
|
|
object user = new { userInfo.userNo, userInfo.nick, userInfo.sex, userInfo.sign };
|
|
|
|
var attrInfo = await _attrService.GetUserAttrModel(userId); //基础属性
|
|
var expInfo = await _attrService.GetUserExp(userId);
|
|
object exp = new { expInfo.exp, expInfo.upExp };
|
|
var vigourInfo = await _attrService.GetUserVigourInfo(userId);
|
|
var accInfo = await _accService.GetUserAccInfo(userId);
|
|
object acc = new { accInfo.gold, accInfo.cowry, accInfo.teach, accInfo.renown };
|
|
object result = new { user, attr = attrInfo, exp, vigourInfo.vitality, acc };
|
|
return PoAction.Ok(result);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取用户资料
|
|
/// </summary>
|
|
/// <param name="no"></param>
|
|
/// <returns></returns>
|
|
[HttpGet]
|
|
public async Task<IPoAction> GetHomeInfo(string? no)
|
|
{
|
|
string userId = StateHelper.userId;
|
|
var userInfo = await _userService.GetUserInfoByUserNo(no); //基础资料
|
|
if (userInfo == null)
|
|
{
|
|
return PoAction.Message("玩家不存在!", 102);
|
|
}
|
|
|
|
if (userInfo.userId == userId)
|
|
{
|
|
return PoAction.Message("用户本身!", 101);
|
|
}
|
|
if (userInfo.areaId != StateHelper.areaId)
|
|
{
|
|
return PoAction.Message("玩家不存在!", 102);
|
|
}
|
|
|
|
object user = new { userInfo.userNo, userInfo.nick, userInfo.sex, userInfo.sign };
|
|
var attrInfo = await _attrService.GetUserAttrModel(userInfo.userId); //基础属性
|
|
var accInfo = await _accService.GetUserAccInfo(userInfo.userId);
|
|
object acc = new { accInfo.teach };
|
|
|
|
var online = await _mapService.GetUserOnMap(userInfo.userId);
|
|
int isOnline = online.upTime >
|
|
TimeExtend.GetTimeStampBySeconds(DateTime.Now.AddMinutes(0 - GameConfig.OnLineTime))
|
|
? 1
|
|
: 0;
|
|
var onMapInfo = await _mapService.GetMapInfo(online.mapId);
|
|
var onCity = await _mapService.GetCityInfo((int)onMapInfo.cityId);
|
|
string onMapName = $"{onCity.cityName}-{onMapInfo.mapName}";
|
|
|
|
object result = new { user, attr = new { attrInfo.lev }, acc, isOnline, onMapName };
|
|
return PoAction.Ok(result);
|
|
}
|
|
} |