419 lines
13 KiB
C#
419 lines
13 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;
|
|
private readonly IUnitUserRelationService _relationService;
|
|
private readonly IGameGoodsService _goodsService;
|
|
private readonly IGameChatService _chatService;
|
|
private readonly IGameSkillService _skillService;
|
|
private readonly IGameTeamService _teamService;
|
|
|
|
public UserController(IUnitUserService userService, IUnitUserAttrService attrService,
|
|
IUnitUserAccService accService, IGameMapService mapService, IUnitUserRelationService relationService,
|
|
IGameGoodsService goodsService, IGameChatService chatService, IGameSkillService skillService,
|
|
IGameTeamService teamService)
|
|
{
|
|
_userService = userService;
|
|
_attrService = attrService;
|
|
_accService = accService;
|
|
_mapService = mapService;
|
|
_relationService = relationService;
|
|
_goodsService = goodsService;
|
|
_chatService = chatService;
|
|
_skillService = skillService;
|
|
_teamService = teamService;
|
|
}
|
|
|
|
|
|
/// <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> GetUserBaseInfo(string? no)
|
|
{
|
|
string userId = StateHelper.userId;
|
|
if (!string.IsNullOrEmpty(no))
|
|
{
|
|
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);
|
|
}
|
|
|
|
userId = userInfo.userId;
|
|
}
|
|
|
|
var model = await UserModelTool.GetUserView(userId);
|
|
return PoAction.Ok(model);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取基础属性信息
|
|
/// </summary>
|
|
/// <param name="no"></param>
|
|
/// <returns></returns>
|
|
[HttpGet]
|
|
public async Task<IPoAction> GetUserBaseAttrInfo(string? no)
|
|
{
|
|
string userId = StateHelper.userId;
|
|
if (!string.IsNullOrEmpty(no))
|
|
{
|
|
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);
|
|
}
|
|
|
|
userId = userInfo.userId;
|
|
}
|
|
|
|
var model = await _attrService.GetUserAttrModel(userId);
|
|
return PoAction.Ok(model);
|
|
}
|
|
|
|
/// <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}";
|
|
bool isFriend = await _relationService.CheckIsFriend(userId, userInfo.userId);
|
|
bool isEnemy = await _relationService.CheckUserEnemy(userId, userInfo.userId);
|
|
var team = await _teamService.GetUserTeamInfo(userInfo.userId);
|
|
object result = new { user, attr = new { attrInfo.lev }, acc, isOnline, onMapName, isFriend, isEnemy, team };
|
|
return PoAction.Ok(result);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 更新昵称
|
|
/// </summary>
|
|
/// <param name="parms"></param>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
public async Task<IPoAction> UpdateUserNick([FromBody] UpdateNickParms parms)
|
|
{
|
|
parms.nick = StringAssist.NoHTML(parms.nick);
|
|
if (string.IsNullOrEmpty(parms.nick))
|
|
{
|
|
return PoAction.Message("昵称不能为空!");
|
|
}
|
|
|
|
string userId = StateHelper.userId;
|
|
var userInfo = await _userService.GetUserInfoByUserId(userId);
|
|
if (userInfo.nick == parms.nick)
|
|
{
|
|
return PoAction.Message("昵称无变化,无需修改!");
|
|
}
|
|
|
|
if (await _userService.CheckUserNickIsAt(parms.nick))
|
|
{
|
|
return PoAction.Message("昵称已存在!");
|
|
}
|
|
|
|
|
|
var myGoods = await _goodsService.GetUserGoodsCount(userId, GameConfig.GameUpdateNickNeedGoods);
|
|
if (myGoods < 1)
|
|
{
|
|
return PoAction.Message("暂无改名道具!");
|
|
}
|
|
|
|
if (await _goodsService.UpdateUserGoods(userId, 0, GameConfig.GameUpdateNickNeedGoods, 1, "改名使用"))
|
|
{
|
|
if (await _userService.UpdateUserNick(userId, parms.nick))
|
|
{
|
|
string sign = $"玩家注意:【{UbbTool.HomeUbb(userInfo.userNo, userInfo.nick)}】已将昵称修改为【{parms.nick}】";
|
|
await _chatService.SendChat("0", StateHelper.areaId, nameof(GameChatEnum.Code.Region), sign);
|
|
return PoAction.Ok(true);
|
|
}
|
|
else
|
|
{
|
|
return PoAction.Message("操作失败,请稍后尝试!");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
return PoAction.Message("操作失败,请稍后尝试!");
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 变更性别
|
|
/// </summary>
|
|
/// <param name="parms"></param>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
public async Task<IPoAction> UpdateUserSex([FromBody] UpdateSexParms parms)
|
|
{
|
|
parms.sex = parms.sex == "男" ? "男" : "女";
|
|
|
|
string userId = StateHelper.userId;
|
|
var userInfo = await _userService.GetUserInfoByUserId(userId);
|
|
if (userInfo.sex == parms.sex)
|
|
{
|
|
return PoAction.Message("已是当前性别,无需修改!");
|
|
}
|
|
|
|
var myGoods = await _goodsService.GetUserGoodsCount(userId, GameConfig.GameUpdateSexNeedGoods);
|
|
if (myGoods < 1)
|
|
{
|
|
return PoAction.Message("暂无性别变更道具!");
|
|
}
|
|
|
|
if (await _goodsService.UpdateUserGoods(userId, 0, GameConfig.GameUpdateSexNeedGoods, 1, "变更性别使用"))
|
|
{
|
|
if (await _userService.UpdateUserSex(userId, parms.sex))
|
|
{
|
|
return PoAction.Ok(true);
|
|
}
|
|
else
|
|
{
|
|
return PoAction.Message("操作失败,请稍后尝试!");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
return PoAction.Message("操作失败,请稍后尝试!");
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 更新签名
|
|
/// </summary>
|
|
/// <param name="parms"></param>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
public async Task<IPoAction> UpdateUserSign([FromBody] UpdateSignParms parms)
|
|
{
|
|
if (parms.sign.Length > 80)
|
|
{
|
|
return PoAction.Message("签名不能超过80个字符!");
|
|
}
|
|
|
|
parms.sign = StringAssist.NoHTML(parms.sign);
|
|
string userId = StateHelper.userId;
|
|
|
|
if (await _userService.UpdateUserSign(userId, parms.sign))
|
|
{
|
|
return PoAction.Ok(true);
|
|
}
|
|
else
|
|
{
|
|
return PoAction.Message("操作失败,请稍后尝试!");
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取用户技能
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[HttpGet]
|
|
public async Task<IPoAction> GetUserSkill()
|
|
{
|
|
var userId = StateHelper.userId;
|
|
var data = await _skillService.GetUserSkill(userId);
|
|
return PoAction.Ok(data);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取个人药品栏
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[HttpGet]
|
|
public async Task<IPoAction> GetUserDrugColumn()
|
|
{
|
|
string userId = StateHelper.userId;
|
|
var data = await _attrService.GetUserDrug(userId);
|
|
return PoAction.Ok(data.drug);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 移除药品栏药品
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <returns></returns>
|
|
[HttpGet]
|
|
public async Task<IPoAction> RemoverUserDrug(string id)
|
|
{
|
|
string userId = StateHelper.userId;
|
|
var data = await _attrService.GetUserDrug(userId);
|
|
var onDrug = data.drug.Find(it => it.id == id);
|
|
if (onDrug == null)
|
|
{
|
|
return PoAction.Message("药品栏无此药品!");
|
|
}
|
|
|
|
data.drug.Remove(onDrug);
|
|
if (await _attrService.UpdateUserDrug(data))
|
|
{
|
|
if (onDrug.count > 0)
|
|
{
|
|
await _goodsService.UpdateUserGoods(userId, 1, onDrug.goodsId, onDrug.count, "药品栏移除,退回背包");
|
|
}
|
|
|
|
return PoAction.Ok(true);
|
|
}
|
|
else
|
|
{
|
|
return PoAction.Message("移除失败!");
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 添加到药品栏
|
|
/// </summary>
|
|
/// <param name="goodsId"></param>
|
|
/// <returns></returns>
|
|
[HttpGet]
|
|
public async Task<IPoAction> AddUserDrug(int goodsId, int count)
|
|
{
|
|
count = count < 1 ? 1 : count;
|
|
count = count > 999 ? 999 : count;
|
|
string userId = StateHelper.userId;
|
|
var myGoods = await _goodsService.GetUserGoodsInfo(userId, goodsId);
|
|
if (myGoods == null)
|
|
{
|
|
return PoAction.Message("暂无该物品!");
|
|
}
|
|
|
|
if (myGoods.count < count)
|
|
{
|
|
return PoAction.Message("物品数量不足!");
|
|
}
|
|
|
|
if (myGoods.code != nameof(GoodsEnum.Code.Drug))
|
|
{
|
|
return PoAction.Message("该物品无法置放到药品栏!");
|
|
}
|
|
|
|
bool isAdd = false;
|
|
var myDrug = await _attrService.GetUserDrug(userId);
|
|
var onDrug = myDrug.drug.Find(it => it.goodsId == goodsId);
|
|
if (onDrug == null)
|
|
{
|
|
if (myDrug.drug.Count >= 5)
|
|
{
|
|
return PoAction.Message("药品栏最多添加5个药品!");
|
|
}
|
|
|
|
isAdd = true;
|
|
}
|
|
|
|
if (await _goodsService.UpdateUserGoods(userId, 0, goodsId, count, "放置到药品栏"))
|
|
{
|
|
if (isAdd)
|
|
{
|
|
UserDrugModel temp = new UserDrugModel();
|
|
temp.id = StringAssist.NewGuid;
|
|
temp.goodsId = goodsId;
|
|
temp.name = myGoods.goodsName;
|
|
temp.code = "Blood";
|
|
temp.count = count;
|
|
myDrug.drug.Add(temp);
|
|
}
|
|
else
|
|
{
|
|
myDrug.drug.Remove(onDrug);
|
|
onDrug.count += count;
|
|
myDrug.drug.Add(onDrug);
|
|
}
|
|
|
|
if (await _attrService.UpdateUserDrug(myDrug))
|
|
{
|
|
return PoAction.Ok(true);
|
|
}
|
|
else
|
|
{
|
|
return PoAction.Message("添加失败,请稍后尝试!");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
return PoAction.Message("添加失败,请稍后尝试!");
|
|
}
|
|
}
|
|
} |