This commit is contained in:
Putoo
2026-05-30 17:32:27 +08:00
parent bd1535aee9
commit f8d4a28d53
79 changed files with 1369 additions and 134 deletions

View File

@@ -12,11 +12,13 @@ public class ChatController : ControllerBase
{
private readonly IGameChatService _chatService;
private readonly IGameGoodsService _goodsService;
private readonly IUnitUserService _userService;
public ChatController(IGameChatService chatService, IGameGoodsService goodsService)
public ChatController(IGameChatService chatService, IGameGoodsService goodsService, IUnitUserService userService)
{
_chatService = chatService;
_goodsService = goodsService;
_userService = userService;
}
/// <summary>
@@ -53,8 +55,10 @@ public class ChatController : ControllerBase
break;
}
int chatRole = await _userService.GetUserConfigInfo(userId, nameof(UserEnum.ConfigCode.ChatRole)); //获取聊天权限
return PoAction.Ok(new { data, total = Total.Value, sendGoodsCount, sendGoodsName });
return PoAction.Ok(new { data, total = Total.Value, sendGoodsCount, sendGoodsName, chatRole });
}
/// <summary>
@@ -73,7 +77,7 @@ public class ChatController : ControllerBase
string userId = StateHelper.userId;
int areaId = StateHelper.areaId;
string par = string.Empty;
string code = GameChatEnum.Code.Public.ToString();
string code = nameof(GameChatEnum.Code.Public);
int goodsId = 0;
bool isSend = false;
switch (pars.type)
@@ -110,12 +114,35 @@ public class ChatController : ControllerBase
return PoAction.Message("无法发言!");
}
int chatRole = await _userService.GetUserConfigInfo(userId, nameof(UserEnum.ConfigCode.ChatRole));
if (chatRole < 0)
{
return PoAction.Message("发言权限已被系统限制!");
}
bool upGoods = true;
if (goodsId != 0)
{
var myCount = await _goodsService.GetUserGoodsCount(userId, goodsId);
if (myCount < 1)
bool checkGoods = true;
if ((nameof(GameChatEnum.Code.Region) == code || nameof(GameChatEnum.Code.Public) == code) && chatRole > 0)
{
return PoAction.Message("暂无发言道具,去商城购买海螺才可以发言哦!");
checkGoods = false;
upGoods = false;
}
else if (nameof(GameChatEnum.Code.Dress) == code && chatRole > 1)
{
checkGoods = false;
upGoods = false;
}
if (checkGoods)
{
var myCount = await _goodsService.GetUserGoodsCount(userId, goodsId);
if (myCount < 1)
{
return PoAction.Message("暂无发言道具,去商城购买海螺才可以发言哦!");
}
}
}
@@ -123,7 +150,7 @@ public class ChatController : ControllerBase
bool result = await _chatService.SendChat(userId, areaId, code, sign, par);
if (result)
{
if (goodsId != 0) //扣除道具
if (goodsId != 0 && upGoods) //扣除道具
{
await _goodsService.UpdateUserGoods(userId, 0, goodsId, 1, "发言");
}
@@ -135,4 +162,56 @@ public class ChatController : ControllerBase
return PoAction.Message("发送失败,请稍后尝试!");
}
}
/// <summary>
/// 删除聊天记录
/// </summary>
/// <param name="chatId"></param>
/// <returns></returns>
[HttpGet]
public async Task<IPoAction> DeleteChat(string chatId)
{
var chatInfo = await _chatService.GetChatInfo(chatId);
if (chatInfo == null)
{
return PoAction.Message("发言不存在!");
}
if (chatInfo.state != 1)
{
return PoAction.Message("发言不存在!");
}
if (chatInfo.areaId != StateHelper.areaId)
{
return PoAction.Message("发言不存在!");
}
bool IsOp = false;
string userId = StateHelper.userId;
int chatRole = await _userService.GetUserConfigInfo(userId, nameof(UserEnum.ConfigCode.ChatRole));
if ((chatInfo.code == nameof(GameChatEnum.Code.Public) || chatInfo.code == nameof(GameChatEnum.Code.Region)) &&
chatRole > 0)
{
IsOp = true;
}
else if (chatRole > 1 && chatInfo.code == nameof(GameChatEnum.Code.Dress))
{
IsOp = true;
}
if (IsOp == false)
{
return PoAction.Message("无权限!");
}
if (await _chatService.DeleteChat(chatId, userId))
{
return PoAction.Ok(true);
}
else
{
return PoAction.Message("操作失败,请稍后尝试!");
}
}
}

View File

@@ -158,7 +158,7 @@ namespace Application.Web.Controllers.Login
{
return PoAction.Message("暂未开放本区服!");
}
//判断是否已经注册
var userData = await _userService.GetUserDataByAccId(accInfo.accId);
if (userData.Any(it => it.areaId == area))
@@ -247,7 +247,7 @@ namespace Application.Web.Controllers.Login
string Key = App.Configuration["JwtTokenOptions:SecurityKey"].ToString();
string Issuer = App.Configuration["JwtTokenOptions:Issuer"].ToString();
string Audience = App.Configuration["JwtTokenOptions:Audience"].ToString();
string accId = string.Empty;
var tokenData = await JwtTool.GetJwtData(parms.token, Key, "accId");
if (tokenData != null)
@@ -297,13 +297,53 @@ namespace Application.Web.Controllers.Login
string sex = parms.sex == 0 ? "女" : "男";
string userId = StateHelper.userId;
var userInfo = await _userService.GetUserInfoByUserId(userId);
if (userInfo == null)
{
return PoAction.Message("角色不存在!");
}
if (userInfo.regOk == 1)
{
return PoAction.Ok(true);
}
var areaInfo = await _areaService.GetAreaInfo((int)userInfo.areaId);
if (areaInfo.isNeedCode == 1) //需要激活码
{
if (string.IsNullOrEmpty(parms.code))
{
return PoAction.Message("请输入激活码!");
}
var ackInfo = await _areaService.GetAckInfo(parms.code);
if (ackInfo == null)
{
return PoAction.Message("激活码过期!");
}
if (ackInfo.status != 0)
{
return PoAction.Message("激活码过期!");
}
if (ackInfo.areaId != 0 && ackInfo.areaId != areaInfo.areaId)
{
return PoAction.Message($"当前激活码可用于{ackInfo.areaId}区激活!");
}
}
if (await _userService.CheckUserNickIsAt(parms.nick))
{
return PoAction.Message("昵称已存在!");
}
if (await _userService.RegisterUserInfo(userId, parms.nick, sex))
{
if (areaInfo.isNeedCode == 1)
{
await _areaService.UseAck(parms.code, userId);
}
return PoAction.Ok(true);
}
else

View File

@@ -119,7 +119,7 @@ public class MapController : ControllerBase
page,
10, Total);
return PoAction.Ok(new { data, total = Total.Value });
return PoAction.Ok(new { data, total = Total.Value, map = mapInfo });
}
/// <summary>

View File

@@ -106,6 +106,28 @@ namespace Application.Web.Controllers.Pub
}
return PoAction.Ok(userData);
}
/// <summary>
/// 获取区服信息
/// </summary>
/// <returns></returns>
[HttpGet]
public async Task<IPoAction> GetOnAreaInfo()
{
int areaId = StateHelper.areaId;
var areaInfo = await _areaService.GetAreaInfo(areaId);
if (areaInfo == null)
{
return PoAction.Message("区服不存在!");
}
if (areaInfo.status != 1)
{
return PoAction.Message("当前区服繁忙!");
}
return PoAction.Ok(areaInfo);
}
}
}

View File

@@ -14,13 +14,15 @@ public class RelationController : ControllerBase
private readonly IUnitUserRelationService _relationService;
private readonly IUnitUserService _userService;
private readonly IMessageService _messageService;
private readonly IUnitUserAccService _accService;
public RelationController(IUnitUserRelationService relationService, IUnitUserService userService,
IMessageService messageService)
IMessageService messageService, IUnitUserAccService accService)
{
_relationService = relationService;
_userService = userService;
_messageService = messageService;
_accService = accService;
}
/// <summary>
@@ -51,10 +53,23 @@ public class RelationController : ControllerBase
.ThenByDescending(it => it.sort).ToList();
result = PageExtend.GetPageList(data, page, 10);
}
else if (type == 3)
{
var data = await _relationService.GetUserEnemyData(userId);
total = data.Count;
data = data.OrderByDescending(it => it.isOnline)
.ThenByDescending(it => it.sort).ToList();
result = PageExtend.GetPageList(data, page, 10);
}
return PoAction.Ok(new { data = result, total = total.Value, online = result.Count(it => it.isOnline == 1) });
}
/// <summary>
/// 好友处理
/// </summary>
/// <param name="no"></param>
/// <returns></returns>
[HttpGet]
public async Task<IPoAction> FriendHandle(string no)
{
@@ -76,8 +91,33 @@ public class RelationController : ControllerBase
}
bool IsFriend = await _relationService.CheckIsFriend(userId, userInfo.userId);
if (IsFriend == false)
if (IsFriend == false) //添加好友
{
var friendRole =
await _userService.GetUserConfigInfo(userInfo.userId, nameof(UserEnum.ConfigCode.FriendRole));
if (friendRole == 0)
{
return PoAction.Message("该玩家拒绝任何人添加好友!");
}
var friendCount = await _relationService.GetUserFriendCount(userId);
if (friendCount >= GameConfig.GameUserFriendMaxCount)
{
return PoAction.Message("好友人数已达上限!");
}
if (friendRole == 2)//不限制加好友
{
if (await _relationService.AddFriend(userId, userInfo.userId))
{
return PoAction.Ok(true, "添加好友成功!");
}
else
{
return PoAction.Ok(true, "添加好友失败,请稍后尝试!");
}
}
string token = $"{nameof(MessageEnum.EventCode.Friend)}_{userId}_{userInfo.userId}";
if (await _messageService.CheckAtEventMsg(token))
{
@@ -114,4 +154,91 @@ public class RelationController : ControllerBase
}
}
}
/// <summary>
/// 删除仇人
/// </summary>
/// <param name="no"></param>
/// <returns></returns>
[HttpGet]
public async Task<IPoAction> DeleteEnemy(string no)
{
string userId = StateHelper.userId;
var userInfo = await _userService.GetUserInfoByUserNo(no); //基础资料
if (userInfo == null)
{
return PoAction.Message("玩家不存在!");
}
bool IsEnemy = await _relationService.CheckUserEnemy(userId, userInfo.userId);
if (IsEnemy == false)
{
return PoAction.Message("不是仇人,无需删除哦");
}
bool result = await _relationService.DeleteUserEnemy(userId, userInfo.userId);
if (result)
{
return PoAction.Ok(true, "删除成功!");
}
else
{
return PoAction.Message("删除失败,请稍后尝试.");
}
}
/// <summary>
/// 添加仇人
/// </summary>
/// <param name="no"></param>
/// <returns></returns>
[HttpGet]
public async Task<IPoAction> AddEnemy(string no)
{
string userId = StateHelper.userId;
var userInfo = await _userService.GetUserInfoByUserNo(no); //基础资料
if (userInfo == null)
{
return PoAction.Message("玩家不存在!");
}
if (userInfo.userId == userId)
{
return PoAction.Message("不能加自己为仇人!");
}
if (userInfo.areaId != StateHelper.areaId)
{
return PoAction.Message("玩家不存在!");
}
bool IsEnemy = await _relationService.CheckUserEnemy(userId, userInfo.userId);
if (IsEnemy == true)
{
return PoAction.Message("已经是仇人啦,无需重复添加!");
}
var myAcc = await _accService.GetUserAccInfo(userId, nameof(AccEnum.AccType.gold));
if (myAcc < GameConfig.GameRelationEnemyNeedGold)
{
return PoAction.Message("您的金元不足!");
}
if (await _accService.UpdateUserAcc(userId, 0, nameof(AccEnum.AccType.gold),
GameConfig.GameRelationEnemyNeedGold, nameof(AccEnum.Name.), "添加仇人"))
{
if (await _relationService.AddUserEnemy(userId, userInfo.userId))
{
return PoAction.Ok(true, "仇人添加成功!");
}
else
{
return PoAction.Message("添加失败,请稍后尝试.");
}
}
else
{
return PoAction.Message("添加失败,请稍后尝试.");
}
}
}

View File

@@ -13,18 +13,22 @@ public class UserController : ControllerBase
private readonly IUnitUserAccService _accService;
private readonly IGameMapService _mapService;
private readonly IUnitUserRelationService _relationService;
private readonly IGameGoodsService _goodsService;
private readonly IGameChatService _chatService;
public UserController(IUnitUserService userService, IUnitUserAttrService attrService,
IUnitUserAccService accService, IGameMapService mapService,IUnitUserRelationService relationService)
IUnitUserAccService accService, IGameMapService mapService, IUnitUserRelationService relationService,
IGameGoodsService goodsService, IGameChatService chatService)
{
_userService = userService;
_attrService = attrService;
_accService = accService;
_mapService = mapService;
_relationService = relationService;
_goodsService = goodsService;
_chatService = chatService;
}
/// <summary>
/// 获取个人资料信息
@@ -53,27 +57,34 @@ public class UserController : ControllerBase
/// <param name="no"></param>
/// <returns></returns>
[HttpGet]
public async Task<IPoAction> GetUserBaseInfo(string no)
public async Task<IPoAction> GetUserBaseInfo(string? no)
{
string userId = StateHelper.userId;
var userInfo = await _userService.GetUserInfoByUserNo(no); //基础资料
if (userInfo == null)
if (!string.IsNullOrEmpty(no))
{
return PoAction.Message("玩家不存在!", 102);
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;
}
if (userInfo.userId == userId)
{
return PoAction.Message("用户本身!", 101);
}
if (userInfo.areaId != StateHelper.areaId)
{
return PoAction.Message("玩家不存在!", 102);
}
var model = await UserModelTool.GetUserView(userInfo.userId);
var model = await UserModelTool.GetUserView(userId);
return PoAction.Ok(model);
}
/// <summary>
/// 获取用户资料
/// </summary>
@@ -93,6 +104,7 @@ public class UserController : ControllerBase
{
return PoAction.Message("用户本身!", 101);
}
if (userInfo.areaId != StateHelper.areaId)
{
return PoAction.Message("玩家不存在!", 102);
@@ -112,7 +124,126 @@ public class UserController : ControllerBase
var onCity = await _mapService.GetCityInfo((int)onMapInfo.cityId);
string onMapName = $"{onCity.cityName}-{onMapInfo.mapName}";
bool isFriend = await _relationService.CheckIsFriend(userId, userInfo.userId);
object result = new { user, attr = new { attrInfo.lev }, acc, isOnline, onMapName ,isFriend};
bool isEnemy = await _relationService.CheckUserEnemy(userId, userInfo.userId);
object result = new { user, attr = new { attrInfo.lev }, acc, isOnline, onMapName, isFriend, isEnemy };
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("操作失败,请稍后尝试!");
}
}
}