diff --git a/Service/Application.Domain.Entity/game/game/game_team.cs b/Service/Application.Domain.Entity/game/game/game_team.cs new file mode 100644 index 0000000..f4461f8 --- /dev/null +++ b/Service/Application.Domain.Entity/game/game/game_team.cs @@ -0,0 +1,58 @@ +using SqlSugar; +using System; + +namespace Application.Domain.Entity +{ + [Tenant("Kg.SeaTime.Game")] + public class game_team + { + /// + /// teamId + /// + [SugarColumn(IsPrimaryKey = true, Length = 50)] + public string teamId { get; set; } + + /// + /// areaId + /// + [SugarColumn(IsNullable = true)] + public int? areaId { get; set; } + + /// + /// code + /// + [SugarColumn(Length = 50, IsNullable = true)] + public string? code { get; set; } + + /// + /// par + /// + [SugarColumn(Length = 255, IsNullable = true)] + public string? par { get; set; } + + /// + /// count + /// + [SugarColumn(IsNullable = true)] + public int? count { get; set; } + + /// + /// name + /// + [SugarColumn(Length = 100, IsNullable = true)] + public string? name { get; set; } + + /// + /// masterId + /// + [SugarColumn(Length = 50, IsNullable = true)] + public string? masterId { get; set; } + + + /// + /// addTime + /// + [SugarColumn(IsNullable = true)] + public DateTime? addTime { get; set; } + } +} \ No newline at end of file diff --git a/Service/Application.Domain.Entity/game/user/unit_user_team.cs b/Service/Application.Domain.Entity/game/user/unit_user_team.cs new file mode 100644 index 0000000..3f2905a --- /dev/null +++ b/Service/Application.Domain.Entity/game/user/unit_user_team.cs @@ -0,0 +1,21 @@ +using SqlSugar; +using System; + +namespace Application.Domain.Entity +{ + [Tenant("Kg.SeaTime.Game")] + public class unit_user_team + { + /// + /// userId + /// + [SugarColumn(IsPrimaryKey = true, Length = 50)] + public string userId { get; set; } + + /// + /// teamId + /// + [SugarColumn(Length = 50, IsNullable = true)] + public string? teamId { get; set; } + } +} \ No newline at end of file diff --git a/Service/Application.Domain.Entity/model/RandomModel.cs b/Service/Application.Domain.Entity/model/RandomModel.cs new file mode 100644 index 0000000..28f1277 --- /dev/null +++ b/Service/Application.Domain.Entity/model/RandomModel.cs @@ -0,0 +1,27 @@ +namespace Application.Domain.Entity; + +public class RandomModel +{ + public enum RandomCode + { + Weight,//权重模式 + Chance,//概率模式 + } + + /// + /// Weight权重模式 Chance概率模式 + /// + public string code { get; set; } + public string name { get; set; } + public int empty { get; set; } + public List data { get; set; } +} + +public class RandomData +{ + public string code { get; set; } + public string name { get; set; } + public string par { get; set; } + public long count { get; set; } + public double chance { get; set; } +} \ No newline at end of file diff --git a/Service/Application.Domain.Entity/model/TeamModel.cs b/Service/Application.Domain.Entity/model/TeamModel.cs new file mode 100644 index 0000000..d9f207d --- /dev/null +++ b/Service/Application.Domain.Entity/model/TeamModel.cs @@ -0,0 +1,16 @@ +namespace Application.Domain.Entity; + +public class TeamModel +{ + public int state { get; set; } + public string codeTips { get; set; } + public game_team team { get; set; } + public List user { get; set; } +} + +public class TeamUser +{ + public UserModel user { get; set; } + public int isOnline { get; set; } + +} \ No newline at end of file diff --git a/Service/Application.Domain.Entity/model/UserModel.cs b/Service/Application.Domain.Entity/model/UserModel.cs index 0a76783..d5a6596 100644 --- a/Service/Application.Domain.Entity/model/UserModel.cs +++ b/Service/Application.Domain.Entity/model/UserModel.cs @@ -2,6 +2,7 @@ public class UserModel { + public string userId { get; set; } public string userNo { get; set; } public string nick { get; set; } public string sex { get; set; } diff --git a/Service/Application.Domain/Cache/UserCache.cs b/Service/Application.Domain/Cache/UserCache.cs index 58d54fd..7913ac5 100644 --- a/Service/Application.Domain/Cache/UserCache.cs +++ b/Service/Application.Domain/Cache/UserCache.cs @@ -1,7 +1,7 @@ namespace Application.Domain; -public class UserCache +public static class UserCache { - public static string BaseCacheKey = "BaseUserCache:{0}"; - public static string BaseCacheKeys = "BaseUserCache:{0}:{1}"; + public const string BaseCacheKey = "BaseUserCache:{0}"; + public const string BaseCacheKeys = "BaseUserCache:{0}:{1}"; } \ No newline at end of file diff --git a/Service/Application.Domain/Config/GameConfig.cs b/Service/Application.Domain/Config/GameConfig.cs index afc29d8..9b0ba43 100644 --- a/Service/Application.Domain/Config/GameConfig.cs +++ b/Service/Application.Domain/Config/GameConfig.cs @@ -16,4 +16,5 @@ public static class GameConfig public const int GameAutoBagGoodsId = 10001;//百宝箱物品ID public const int GameAutoDrugGoodsId = 10001;//急救箱物品ID public const int GameToMapNeedCopper = 5;//传送每海里费用 + public const int TeamCacheTime = 300;//队伍缓存时间 } \ No newline at end of file diff --git a/Service/Application.Domain/Enum/TeamEnum.cs b/Service/Application.Domain/Enum/TeamEnum.cs new file mode 100644 index 0000000..7446fa2 --- /dev/null +++ b/Service/Application.Domain/Enum/TeamEnum.cs @@ -0,0 +1,11 @@ +namespace Application.Domain; + +public static class TeamEnum +{ + public enum TeamCode + { + Default, + Dup, + Ot + } +} \ No newline at end of file diff --git a/Service/Application.Domain/Services/Interface/Pub/IGameTeamService.cs b/Service/Application.Domain/Services/Interface/Pub/IGameTeamService.cs new file mode 100644 index 0000000..23a1336 --- /dev/null +++ b/Service/Application.Domain/Services/Interface/Pub/IGameTeamService.cs @@ -0,0 +1,17 @@ +namespace Application.Domain; + +public interface IGameTeamService +{ + Task> GetTeamDataPage(int area, string code, int page, int limit, RefAsync total); + Task GetUserTeamData(string userId); + Task GetTeamInfo(string teamId); + Task> GetTeamMember(string teamId); + Task GetTeamDataByTeamId(string teamId); + Task GetUserTeamInfo(string userId); + + Task Add(string userId, string teamId, bool isAdd = false, string name = "", int area = 0, string code = "", + string par = "", int count = 0); + Task Remove(string userId, string teamId); + Task DisTeam(string teamId); + Task UpdateTeamName(string teamId, string name); +} \ No newline at end of file diff --git a/Service/Application.Domain/Services/Service/Pub/GameTeamService.cs b/Service/Application.Domain/Services/Service/Pub/GameTeamService.cs new file mode 100644 index 0000000..6ee35b2 --- /dev/null +++ b/Service/Application.Domain/Services/Service/Pub/GameTeamService.cs @@ -0,0 +1,227 @@ +namespace Application.Domain; + +public class GameTeamService(ISqlSugarClient DbClient, IRedisCache redis) : IGameTeamService, ITransient +{ + public async Task> GetTeamDataPage(int area, string code, int page, int limit, RefAsync total) + { + var db = DbClient.AsTenant().GetConnectionWithAttr(); + var data = await db.Queryable().Where(it => it.areaId == area && it.code == code) + .OrderByDescending(it => it.addTime).ToPageListAsync(page, limit, total); + List result = new List(); + foreach (var item in data) + { + var temp = await GetTeamDataByTeamId(item.teamId); + if (temp.state == 1) + { + result.Add(temp); + } + } + + return result; + } + + public async Task GetUserTeamData(string userId) + { + string key = string.Format(UserCache.BaseCacheKeys, "TeamData", "UserData"); + if (await redis.HExistsHashAsync(key, userId)) + { + return await redis.GetHashAsync(key, userId); + } + + var db = DbClient.AsTenant().GetConnectionWithAttr(); + var data = await db.Queryable().Where(it => it.userId == userId).SingleAsync(); + await redis.AddHashAsync(key, userId, data); + return data; + } + + public async Task GetTeamInfo(string teamId) + { + string key = string.Format(UserCache.BaseCacheKeys, "TeamData", "TeamData"); + if (await redis.HExistsHashAsync(key, teamId)) + { + return await redis.GetHashAsync(key, teamId); + } + + var db = DbClient.AsTenant().GetConnectionWithAttr(); + var data = await db.Queryable().Where(it => it.teamId == teamId).SingleAsync(); + await redis.AddHashAsync(key, teamId, data); + return data; + } + + public async Task> GetTeamMember(string teamId) + { + string key = string.Format(UserCache.BaseCacheKeys, "TeamData", "MemberData"); + if (await redis.HExistsHashAsync(key, teamId)) + { + return await redis.GetHashAsync>(key, teamId); + } + + var db = DbClient.AsTenant().GetConnectionWithAttr(); + var data = await db.Queryable().Where(it => it.teamId == teamId).ToListAsync(); + await redis.AddHashAsync(key, teamId, data); + return data; + } + + private async Task GetTeamData(string userId) + { + TeamModel result = new TeamModel(); + var userTeam = await GetUserTeamData(userId); + if (userTeam.teamId == "0") + { + result.state = 0; + result.user = new List(); + result.team = new game_team(); + return result; + } + else + { + result = await GetTeamDataByTeamId(userTeam.teamId); + return result; + } + } + + public async Task GetTeamDataByTeamId(string teamId) + { + TeamModel result = new TeamModel(); + var teamInfo = await GetTeamInfo(teamId); + if (teamInfo == null) + { + result.state = 0; + result.user = new List(); + result.team = new game_team(); + return result; + } + else + { + var mapService = App.GetService(); + result.state = 1; + result.team = teamInfo; + var members = await GetTeamMember(teamId); + List user = new List(); + foreach (var member in members) + { + TeamUser temp = new TeamUser(); + temp.user = await UserModelTool.GetUserView(member.userId); + var onMap = await mapService.GetUserOnMapInfo(member.userId); + temp.isOnline = onMap.isOnline; + user.Add(temp); + } + + result.codeTips = "普通"; + result.user = user; + return result; + } + } + + public async Task GetUserTeamInfo(string userId) + { + string key = string.Format(UserCache.BaseCacheKeys, "TeamData", userId); + if (await redis.ExistsAsync(key)) + { + return await redis.GetAsync(key); + } + + var data = await GetTeamData(userId); + await redis.SetAsync(key, data, GameConfig.TeamCacheTime); + return data; + } + + + private async Task ClearTeamCache(string teamId) + { + var members = await GetTeamMember(teamId); + string key = string.Format(UserCache.BaseCacheKeys, "TeamData", "TeamData"); + await redis.DelHashAsync(key, teamId); + key = string.Format(UserCache.BaseCacheKeys, "TeamData", "MemberData"); + await redis.DelHashAsync(key, teamId); + List memberDataKeys = new List(); + List userDataKeys = new List(); + foreach (var member in members) + { + string mk = string.Format(UserCache.BaseCacheKeys, "TeamData", member.userId); + memberDataKeys.Add(mk); + userDataKeys.Add(member.userId); + } + + await redis.DelAsync(memberDataKeys.ToArray()); + string uk = string.Format(UserCache.BaseCacheKeys, "TeamData", "UserData"); + await redis.DelHashAsync(uk, userDataKeys.ToArray()); + } + + public async Task Add(string userId, string teamId, bool isAdd = false, string name = "", int area = 0, + string code = "", + string par = "", int count = 0) + { + var db = DbClient.AsTenant().GetConnectionWithAttr(); + if (isAdd) + { + game_team team = new game_team() + { + teamId = teamId, + areaId = area, + name = name, + code = code, + par = par, + count = count, + masterId = userId, + addTime = DateTime.Now + }; + await db.Insertable(team).ExecuteCommandAsync(); + } + + var result = await db.Updateable() + .SetColumns(it => it.teamId == teamId) + .Where(it => it.userId == userId).ExecuteCommandAsync() > 0; + if (result) + { + if (isAdd == false) + { + await ClearTeamCache(teamId); + } + + string key = string.Format(UserCache.BaseCacheKeys, "TeamData", "UserData"); + await redis.DelHashAsync(key, userId); + key = string.Format(UserCache.BaseCacheKeys, "TeamData", userId); + await redis.DelAsync(key); + } + + return result; + } + + public async Task Remove(string userId, string teamId) + { + var db = DbClient.AsTenant().GetConnectionWithAttr(); + var result = await db.Updateable() + .SetColumns(it => it.teamId == "0") + .Where(it => it.userId == userId).ExecuteCommandAsync() > 0; + if (result) + { + await ClearTeamCache(teamId); + } + + return result; + } + + public async Task DisTeam(string teamId) + { + var db = DbClient.AsTenant().GetConnectionWithAttr(); + await db.Deleteable().Where(it => it.teamId == teamId).ExecuteCommandAsync(); + await db.Updateable() + .SetColumns(it => it.teamId == "0") + .Where(it => it.teamId == teamId).ExecuteCommandAsync(); + await ClearTeamCache(teamId); + } + + public async Task UpdateTeamName(string teamId, string name) + { + var db = DbClient.AsTenant().GetConnectionWithAttr(); + bool result = await db.Updateable().SetColumns(it => it.name == name) + .Where(it => it.teamId == teamId).ExecuteCommandAsync() > 0; + if (result) + { + await ClearTeamCache(teamId); + } + + return result; + } +} \ No newline at end of file diff --git a/Service/Application.Domain/Services/Service/User/UnitUserService.cs b/Service/Application.Domain/Services/Service/User/UnitUserService.cs index 4673c37..af10ad3 100644 --- a/Service/Application.Domain/Services/Service/User/UnitUserService.cs +++ b/Service/Application.Domain/Services/Service/User/UnitUserService.cs @@ -256,6 +256,12 @@ public class UnitUserService(ISqlSugarClient DbClient, IRedisCache redis) : IUni onlineTime.monthTime = 0; onlineTime.totalTime = 0; db.Insertable(onlineTime).AddQueue(); + + //注册队伍 + unit_user_team team = new unit_user_team(); + team.userId = userId; + team.teamId = "0"; + db.Insertable(team).AddQueue(); await db.SaveQueuesAsync(false); } diff --git a/Service/Application.Domain/Tool/Base/GameBus.cs b/Service/Application.Domain/Tool/Base/GameBus.cs index 34d745a..c1e295a 100644 --- a/Service/Application.Domain/Tool/Base/GameBus.cs +++ b/Service/Application.Domain/Tool/Base/GameBus.cs @@ -158,7 +158,7 @@ public class GameBus isok = false; } } - else if (item.code ==nameof( GameEnum.PropCode.vigour)) //活力 + else if (item.code == nameof(GameEnum.PropCode.vigour)) //活力 { var attrService = App.GetService(); var MyAcc = await attrService.GetUserVigourInfo(userId); @@ -168,7 +168,7 @@ public class GameBus isok = false; } } - else if (item.code ==nameof( GameEnum.PropCode.lev)) + else if (item.code == nameof(GameEnum.PropCode.lev)) { var attrService = App.GetService(); var MyLev = await attrService.GetUserLev(userId); @@ -177,6 +177,7 @@ public class GameBus isok = false; } } + result.result = isok; result.isDeal = isDeal; result.isGive = isGive; @@ -218,4 +219,102 @@ public class GameBus } #endregion + + #region 概率 + + public static List GetRandomGoods(RandomModel random, int count = 1, int luck = 0) + { + List result = new List(); + for (int i = 0; i < count; i++) + { + List timeAward = new List(); + if (random.code == nameof(RandomModel.RandomCode.Weight)) + { + timeAward = RandomHandleByWeight(random, luck); + } + else + { + timeAward = RandomHandleByChance(random, luck); + } + + foreach (var item in timeAward) + { + var onAward = result.FindIndex(it => it.code == item.code && it.parameter == item.par); + if(onAward>-1) + { + result[onAward].count += item.count; + } + else + { + TowerGet add = new TowerGet() + { + code = item.code, + name = item.name, + parameter = item.par, + count = item.count + }; + result.Add(add); + } + } + + } + + return result; + } + + private static List RandomHandleByWeight(RandomModel random, int luck = 0) + { + var _randomInstance = new Random(); + List result = new List(); + int empty = random.empty - luck; + if (_randomInstance.Next(0, 100) < empty) + { + return result; + } + if (random.data.Count == 0) + { + return result; + } + double totalWeight = random.data.Sum(it => it.chance); + int rnd = _randomInstance.Next(Convert.ToInt32(totalWeight) + 1); + double current = 0; + foreach (var item in random.data) + { + current += item.chance; + if (rnd < current) + { + result.Add(item); + return result; + } + } + + return result; + } + private static List RandomHandleByChance(RandomModel random, int luck = 0) + { + var _randomInstance = new Random(); + List result = new List(); + int empty = random.empty - luck; + if (_randomInstance.Next(0, 100) < empty) + { + return result; + } + if (random.data.Count == 0) + { + return result; + } + + foreach (var item in random.data) + { + double rnd = _randomInstance.NextDouble(); + double okChance = item.chance / 100; + if (rnd < okChance) + { + result.Add(item); + } + } + return result; + } + + #endregion } \ No newline at end of file diff --git a/Service/Application.Domain/Tool/ModelTool/UserModelTool.cs b/Service/Application.Domain/Tool/ModelTool/UserModelTool.cs index bcb9cbb..a1c6c51 100644 --- a/Service/Application.Domain/Tool/ModelTool/UserModelTool.cs +++ b/Service/Application.Domain/Tool/ModelTool/UserModelTool.cs @@ -13,6 +13,7 @@ public class UserModelTool UserModel result = new UserModel(); if (userId == "0") { + result.userId = "0"; result.userNo = "0"; result.nick = "海精灵"; result.sex = "女"; @@ -29,6 +30,7 @@ public class UserModelTool var userInfo = await userService.GetUserInfoByUserId(userId); if (userInfo != null) { + result.userId = userInfo.userId; result.userNo = userInfo.userNo; result.nick = userInfo.nick; result.sex = userInfo.sex; diff --git a/Service/Application.Web/Controllers/Chat/ChatController.cs b/Service/Application.Web/Controllers/Chat/ChatController.cs index c13ff71..1baab72 100644 --- a/Service/Application.Web/Controllers/Chat/ChatController.cs +++ b/Service/Application.Web/Controllers/Chat/ChatController.cs @@ -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; } /// @@ -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 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; diff --git a/Service/Application.Web/Controllers/Map/MapController.cs b/Service/Application.Web/Controllers/Map/MapController.cs index 5bdfe45..62b717e 100644 --- a/Service/Application.Web/Controllers/Map/MapController.cs +++ b/Service/Application.Web/Controllers/Map/MapController.cs @@ -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); diff --git a/Service/Application.Web/Controllers/Pub/TeamController.cs b/Service/Application.Web/Controllers/Pub/TeamController.cs new file mode 100644 index 0000000..ac66b0c --- /dev/null +++ b/Service/Application.Web/Controllers/Pub/TeamController.cs @@ -0,0 +1,267 @@ +using Microsoft.AspNetCore.Mvc; + +namespace Application.Web.Controllers.Pub; + +/// +/// 队伍接口 +/// +[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; + } + + /// + /// 获取我的队伍 + /// + /// + [HttpGet] + public async Task GetMyTeam() + { + string userId = StateHelper.userId; + + var teamInfo = await _teamService.GetUserTeamInfo(userId); + return PoAction.Ok(teamInfo); + } + + /// + /// 创建队伍 + /// + /// + [HttpGet] + public async Task 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("创建失败,请稍后尝试!"); + } + } + + /// + /// 加入队伍 + /// + /// + /// + [HttpGet] + public async Task 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("加入失败,请稍后尝试!"); + } + } + /// + /// 获取队伍信息 + /// + /// + /// + [HttpGet] + public async Task 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 + }); + } + + /// + /// 退出队伍 + /// + /// + [HttpGet] + public async Task 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("退出失败,请稍后尝试!"); + } + } + + } + + /// + /// 修改队名 + /// + /// + /// + [HttpPost] + public async Task 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("修改失败,请稍后尝试!"); + } + + } + + /// + /// 踢出成员 + /// + /// + /// + [HttpGet] + public async Task 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("操作失败,请稍后尝试!"); + } + } + + /// + /// 获取队伍列表 + /// + /// + /// + /// + [HttpGet] + public async Task 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 total = 0; + var data = await _teamService.GetTeamDataPage(area, code, page, 10, total); + return PoAction.Ok(new { data, total = total.Value }); + } +} \ No newline at end of file diff --git a/Service/Application.Web/Controllers/User/BagController.cs b/Service/Application.Web/Controllers/User/BagController.cs index 109c9a4..6b150b5 100644 --- a/Service/Application.Web/Controllers/User/BagController.cs +++ b/Service/Application.Web/Controllers/User/BagController.cs @@ -1,4 +1,6 @@ -namespace Application.Web.Controllers.User; +using Newtonsoft.Json; + +namespace Application.Web.Controllers.User; /// /// 用户背包信息 @@ -22,7 +24,7 @@ public class BagController : ControllerBase _equService = equService; _accService = accService; } - + /// /// 获取背包信息 /// diff --git a/Service/Application.Web/Model/RequestParms/Team/UpdateTeamNameParms.cs b/Service/Application.Web/Model/RequestParms/Team/UpdateTeamNameParms.cs new file mode 100644 index 0000000..8c23366 --- /dev/null +++ b/Service/Application.Web/Model/RequestParms/Team/UpdateTeamNameParms.cs @@ -0,0 +1,6 @@ +namespace Application.Web; + +public class UpdateTeamNameParms +{ + public string name { get; set; } +} \ No newline at end of file diff --git a/Web/src/pages/user/friend/index.vue b/Web/src/pages/user/friend/index.vue index 4981a21..4242522 100644 --- a/Web/src/pages/user/friend/index.vue +++ b/Web/src/pages/user/friend/index.vue @@ -1,9 +1,9 @@