This commit is contained in:
Putoo
2026-06-08 18:56:28 +08:00
parent 1927e3f960
commit 9f3e4871a4
23 changed files with 1113 additions and 19 deletions

View File

@@ -13,12 +13,15 @@ public class ChatController : ControllerBase
private readonly IGameChatService _chatService;
private readonly IGameGoodsService _goodsService;
private readonly IUnitUserService _userService;
private readonly IGameTeamService _teamService;
public ChatController(IGameChatService chatService, IGameGoodsService goodsService, IUnitUserService userService)
public ChatController(IGameChatService chatService, IGameGoodsService goodsService, IUnitUserService userService,
IGameTeamService teamService)
{
_chatService = chatService;
_goodsService = goodsService;
_userService = userService;
_teamService = teamService;
}
/// <summary>
@@ -32,7 +35,8 @@ public class ChatController : ControllerBase
{
string userId = StateHelper.userId;
int areaId = StateHelper.areaId;
string teamId = "";
var myTeam = await _teamService.GetUserTeamData(userId);
string teamId = myTeam.teamId;
string groupId = "";
RefAsync<int> Total = 0;
var data = await _chatService.GetChatData(userId, type, areaId, teamId, groupId, page, 10, Total);
@@ -88,9 +92,10 @@ public class ChatController : ControllerBase
goodsId = GameConfig.SendChatGoodsBase;
break;
case 1:
isSend = true;
code = nameof(GameChatEnum.Code.Team);
par = "";
var myTeam = await _teamService.GetUserTeamData(userId);
par = myTeam.teamId;
isSend = par != "0";
break;
case 2:
isSend = true;

View File

@@ -20,9 +20,10 @@ public class MapController : ControllerBase
private readonly IUnitUserAccService _accService;
private readonly IGameSkillService _skillService;
private readonly IGameGoodsService _goodsService;
private readonly IGameTeamService _teamService;
public MapController(IUnitUserService userService, IGameMapService mapService, IGameChatService chatService,
IUnitUserAttrService attrService, IMessageService messageService, IUnitUserWeight weightService,
IUnitUserAccService accService, IGameSkillService skillService,IGameGoodsService goodsService)
IUnitUserAccService accService, IGameSkillService skillService,IGameGoodsService goodsService,IGameTeamService teamService)
{
_userService = userService;
_mapService = mapService;
@@ -33,6 +34,7 @@ public class MapController : ControllerBase
_accService = accService;
_skillService = skillService;
_goodsService = goodsService;
_teamService = teamService;
}
#region
@@ -87,7 +89,8 @@ public class MapController : ControllerBase
#endregion
//公聊信息
string teamId = "";
var myTeam = await _teamService.GetUserTeamData(userId);
string teamId =myTeam.teamId ;
string groupId = "";
var chatData = await _chatService.GetChatTop(userId, area, 2, teamId, groupId);

View File

@@ -0,0 +1,267 @@
using Microsoft.AspNetCore.Mvc;
namespace Application.Web.Controllers.Pub;
/// <summary>
/// 队伍接口
/// </summary>
[Route("[controller]/[action]")]
[ApiController]
[Authorize]
public class TeamController : ControllerBase
{
private readonly IUnitUserService _userService;
private readonly IGameTeamService _teamService;
private readonly IGameChatService _chatService;
public TeamController(IUnitUserService userService, IGameTeamService teamService,IGameChatService chatService)
{
_userService = userService;
_teamService = teamService;
_chatService = chatService;
}
/// <summary>
/// 获取我的队伍
/// </summary>
/// <returns></returns>
[HttpGet]
public async Task<IPoAction> GetMyTeam()
{
string userId = StateHelper.userId;
var teamInfo = await _teamService.GetUserTeamInfo(userId);
return PoAction.Ok(teamInfo);
}
/// <summary>
/// 创建队伍
/// </summary>
/// <returns></returns>
[HttpGet]
public async Task<IPoAction> CreateTeam(int type, string? par)
{
string userId = StateHelper.userId;
var teamId = StringAssist.NewGuid;
var myTeam = await _teamService.GetUserTeamData(userId);
if (myTeam.teamId != "0")
{
return PoAction.Message("退出当前队伍后才可创建!");
}
var userInfo = await _userService.GetUserInfoByUserId(userId);
string name = $"{userInfo.nick}的队伍";
bool result = await _teamService.Add(userId, teamId, true, name, (int)userInfo.areaId,
nameof(TeamEnum.TeamCode.Default), "", 5);
if (result)
{
return PoAction.Ok(true);
}
else
{
return PoAction.Message("创建失败,请稍后尝试!");
}
}
/// <summary>
/// 加入队伍
/// </summary>
/// <param name="teamId"></param>
/// <returns></returns>
[HttpGet]
public async Task<IPoAction> JoinTeam(string teamId)
{
string userId = StateHelper.userId;
var myTeam = await _teamService.GetUserTeamData(userId);
if (myTeam.teamId != "0")
{
return PoAction.Message("退出当前队伍后才可创建!");
}
var onTeam = await _teamService.GetTeamDataByTeamId(teamId);
if (onTeam.state != 1)
{
return PoAction.Message("队伍不存在!");
}
if (onTeam.team.areaId != StateHelper.areaId)
{
return PoAction.Message("队伍不存在!");
}
if (onTeam.user.Count >= onTeam.team.count)
{
return PoAction.Message("队伍已满员!");
}
if (await _teamService.Add(userId, teamId))
{
var myInfo = await _userService.GetUserInfoByUserId(userId);
string msg = $"[{myInfo.nick}]加入了队伍!";
await _chatService.SendChat("0", (int)myInfo.areaId, nameof(GameChatEnum.Code.Team), msg, teamId);
return PoAction.Ok(true);
}
else
{
return PoAction.Message("加入失败,请稍后尝试!");
}
}
/// <summary>
/// 获取队伍信息
/// </summary>
/// <param name="no"></param>
/// <returns></returns>
[HttpGet]
public async Task<IPoAction> GetTeamInfo(string teamId)
{
string userId = StateHelper.userId;
var teamInfo = await _teamService.GetTeamDataByTeamId(teamId);
int isMyTeam = teamInfo.user.Any(it => it.user.userId == userId) ? 1 : 0;
int manger = teamInfo.team.masterId == userId ? 1 : 0;
return PoAction.Ok(new
{
data = teamInfo,
isMyTeam = isMyTeam
});
}
/// <summary>
/// 退出队伍
/// </summary>
/// <returns></returns>
[HttpGet]
public async Task<IPoAction> ExitTeam()
{
string userId = StateHelper.userId;
var myTeam = await _teamService.GetUserTeamInfo(userId);
if (myTeam.state == 0)
{
return PoAction.Message("您未加入队伍,无需退出!");
}
if (myTeam.team.masterId == userId)//如果队长,解散队伍解散
{
await _teamService.DisTeam(myTeam.team.teamId);
return PoAction.Ok(true);
}
else
{
if (await _teamService.Remove(userId, myTeam.team.teamId))
{
var myInfo = await _userService.GetUserInfoByUserId(userId);
string msg = $"[{myInfo.nick}]退出了队伍!";
await _chatService.SendChat("0", (int)myInfo.areaId, nameof(GameChatEnum.Code.Team), msg, myTeam.team.teamId);
return PoAction.Ok(true);
}
else
{
return PoAction.Message("退出失败,请稍后尝试!");
}
}
}
/// <summary>
/// 修改队名
/// </summary>
/// <param name="parms"></param>
/// <returns></returns>
[HttpPost]
public async Task<IPoAction> UpdateTeamName([FromBody] UpdateTeamNameParms parms)
{
string name = StringAssist.NoHTML( parms.name);
if(string.IsNullOrEmpty(name))
{
return PoAction.Message("名称不能为空!");
}
string userId = StateHelper.userId;
var myTeam = await _teamService.GetUserTeamInfo(userId);
if (myTeam.state == 0)
{
return PoAction.Message("暂无队伍!");
}
if (myTeam.team.masterId != userId)
{
return PoAction.Message("队长才可以修改队名哦!");
}
if (await _teamService.UpdateTeamName(myTeam.team.teamId, name))
{
return PoAction.Ok(true);
}
else
{
return PoAction.Message("修改失败,请稍后尝试!");
}
}
/// <summary>
/// 踢出成员
/// </summary>
/// <param name="user"></param>
/// <returns></returns>
[HttpGet]
public async Task<IPoAction> RemoveUser(string user)
{
string userId = StateHelper.userId;
if (userId == user)
{
return PoAction.Message("无权限!");
}
var myTeam = await _teamService.GetUserTeamInfo(userId);
if (myTeam.state == 0)
{
return PoAction.Message("暂无队伍!");
}
if (myTeam.team.masterId != userId)
{
return PoAction.Message("您无权限!");
}
if (myTeam.user.Any(it => it.user.userId == user) == false)
{
return PoAction.Message("您无权限!");
}
if (await _teamService.Remove(user, myTeam.team.teamId))
{
return PoAction.Ok(true);
}
else
{
return PoAction.Message("操作失败,请稍后尝试!");
}
}
/// <summary>
/// 获取队伍列表
/// </summary>
/// <param name="type"></param>
/// <param name="page"></param>
/// <returns></returns>
[HttpGet]
public async Task<IPoAction> GetTeamData(int type, int page)
{
int area = StateHelper.areaId;
string code = nameof(TeamEnum.TeamCode.Default);
switch (type)
{
case 0:
code = nameof(TeamEnum.TeamCode.Default);
break;
case 1:
code = nameof(TeamEnum.TeamCode.Dup);
break;
case 2:
code = nameof(TeamEnum.TeamCode.Ot);
break;
}
RefAsync<int> total = 0;
var data = await _teamService.GetTeamDataPage(area, code, page, 10, total);
return PoAction.Ok(new { data, total = total.Value });
}
}

View File

@@ -1,4 +1,6 @@
namespace Application.Web.Controllers.User;
using Newtonsoft.Json;
namespace Application.Web.Controllers.User;
/// <summary>
/// 用户背包信息
@@ -22,7 +24,7 @@ public class BagController : ControllerBase
_equService = equService;
_accService = accService;
}
/// <summary>
/// 获取背包信息
/// </summary>