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("操作失败,请稍后尝试!");
}
}
}