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

@@ -0,0 +1,58 @@
using SqlSugar;
using System;
namespace Application.Domain.Entity
{
[Tenant("Kg.SeaTime.Game")]
public class game_team
{
/// <summary>
/// teamId
/// </summary>
[SugarColumn(IsPrimaryKey = true, Length = 50)]
public string teamId { get; set; }
/// <summary>
/// areaId
/// </summary>
[SugarColumn(IsNullable = true)]
public int? areaId { get; set; }
/// <summary>
/// code
/// </summary>
[SugarColumn(Length = 50, IsNullable = true)]
public string? code { get; set; }
/// <summary>
/// par
/// </summary>
[SugarColumn(Length = 255, IsNullable = true)]
public string? par { get; set; }
/// <summary>
/// count
/// </summary>
[SugarColumn(IsNullable = true)]
public int? count { get; set; }
/// <summary>
/// name
/// </summary>
[SugarColumn(Length = 100, IsNullable = true)]
public string? name { get; set; }
/// <summary>
/// masterId
/// </summary>
[SugarColumn(Length = 50, IsNullable = true)]
public string? masterId { get; set; }
/// <summary>
/// addTime
/// </summary>
[SugarColumn(IsNullable = true)]
public DateTime? addTime { get; set; }
}
}

View File

@@ -0,0 +1,21 @@
using SqlSugar;
using System;
namespace Application.Domain.Entity
{
[Tenant("Kg.SeaTime.Game")]
public class unit_user_team
{
/// <summary>
/// userId
/// </summary>
[SugarColumn(IsPrimaryKey = true, Length = 50)]
public string userId { get; set; }
/// <summary>
/// teamId
/// </summary>
[SugarColumn(Length = 50, IsNullable = true)]
public string? teamId { get; set; }
}
}

View File

@@ -0,0 +1,27 @@
namespace Application.Domain.Entity;
public class RandomModel
{
public enum RandomCode
{
Weight,//权重模式
Chance,//概率模式
}
/// <summary>
/// Weight权重模式 Chance概率模式
/// </summary>
public string code { get; set; }
public string name { get; set; }
public int empty { get; set; }
public List<RandomData> 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; }
}

View File

@@ -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<TeamUser> user { get; set; }
}
public class TeamUser
{
public UserModel user { get; set; }
public int isOnline { get; set; }
}

View File

@@ -2,6 +2,7 @@
public class UserModel public class UserModel
{ {
public string userId { get; set; }
public string userNo { get; set; } public string userNo { get; set; }
public string nick { get; set; } public string nick { get; set; }
public string sex { get; set; } public string sex { get; set; }

View File

@@ -1,7 +1,7 @@
namespace Application.Domain; namespace Application.Domain;
public class UserCache public static class UserCache
{ {
public static string BaseCacheKey = "BaseUserCache:{0}"; public const string BaseCacheKey = "BaseUserCache:{0}";
public static string BaseCacheKeys = "BaseUserCache:{0}:{1}"; public const string BaseCacheKeys = "BaseUserCache:{0}:{1}";
} }

View File

@@ -16,4 +16,5 @@ public static class GameConfig
public const int GameAutoBagGoodsId = 10001;//百宝箱物品ID public const int GameAutoBagGoodsId = 10001;//百宝箱物品ID
public const int GameAutoDrugGoodsId = 10001;//急救箱物品ID public const int GameAutoDrugGoodsId = 10001;//急救箱物品ID
public const int GameToMapNeedCopper = 5;//传送每海里费用 public const int GameToMapNeedCopper = 5;//传送每海里费用
public const int TeamCacheTime = 300;//队伍缓存时间
} }

View File

@@ -0,0 +1,11 @@
namespace Application.Domain;
public static class TeamEnum
{
public enum TeamCode
{
Default,
Dup,
Ot
}
}

View File

@@ -0,0 +1,17 @@
namespace Application.Domain;
public interface IGameTeamService
{
Task<List<TeamModel>> GetTeamDataPage(int area, string code, int page, int limit, RefAsync<int> total);
Task<unit_user_team> GetUserTeamData(string userId);
Task<game_team> GetTeamInfo(string teamId);
Task<List<unit_user_team>> GetTeamMember(string teamId);
Task<TeamModel> GetTeamDataByTeamId(string teamId);
Task<TeamModel> GetUserTeamInfo(string userId);
Task<bool> Add(string userId, string teamId, bool isAdd = false, string name = "", int area = 0, string code = "",
string par = "", int count = 0);
Task<bool> Remove(string userId, string teamId);
Task DisTeam(string teamId);
Task<bool> UpdateTeamName(string teamId, string name);
}

View File

@@ -0,0 +1,227 @@
namespace Application.Domain;
public class GameTeamService(ISqlSugarClient DbClient, IRedisCache redis) : IGameTeamService, ITransient
{
public async Task<List<TeamModel>> GetTeamDataPage(int area, string code, int page, int limit, RefAsync<int> total)
{
var db = DbClient.AsTenant().GetConnectionWithAttr<game_team>();
var data = await db.Queryable<game_team>().Where(it => it.areaId == area && it.code == code)
.OrderByDescending(it => it.addTime).ToPageListAsync(page, limit, total);
List<TeamModel> result = new List<TeamModel>();
foreach (var item in data)
{
var temp = await GetTeamDataByTeamId(item.teamId);
if (temp.state == 1)
{
result.Add(temp);
}
}
return result;
}
public async Task<unit_user_team> GetUserTeamData(string userId)
{
string key = string.Format(UserCache.BaseCacheKeys, "TeamData", "UserData");
if (await redis.HExistsHashAsync(key, userId))
{
return await redis.GetHashAsync<unit_user_team>(key, userId);
}
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_team>();
var data = await db.Queryable<unit_user_team>().Where(it => it.userId == userId).SingleAsync();
await redis.AddHashAsync(key, userId, data);
return data;
}
public async Task<game_team> GetTeamInfo(string teamId)
{
string key = string.Format(UserCache.BaseCacheKeys, "TeamData", "TeamData");
if (await redis.HExistsHashAsync(key, teamId))
{
return await redis.GetHashAsync<game_team>(key, teamId);
}
var db = DbClient.AsTenant().GetConnectionWithAttr<game_team>();
var data = await db.Queryable<game_team>().Where(it => it.teamId == teamId).SingleAsync();
await redis.AddHashAsync(key, teamId, data);
return data;
}
public async Task<List<unit_user_team>> GetTeamMember(string teamId)
{
string key = string.Format(UserCache.BaseCacheKeys, "TeamData", "MemberData");
if (await redis.HExistsHashAsync(key, teamId))
{
return await redis.GetHashAsync<List<unit_user_team>>(key, teamId);
}
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_team>();
var data = await db.Queryable<unit_user_team>().Where(it => it.teamId == teamId).ToListAsync();
await redis.AddHashAsync(key, teamId, data);
return data;
}
private async Task<TeamModel> GetTeamData(string userId)
{
TeamModel result = new TeamModel();
var userTeam = await GetUserTeamData(userId);
if (userTeam.teamId == "0")
{
result.state = 0;
result.user = new List<TeamUser>();
result.team = new game_team();
return result;
}
else
{
result = await GetTeamDataByTeamId(userTeam.teamId);
return result;
}
}
public async Task<TeamModel> GetTeamDataByTeamId(string teamId)
{
TeamModel result = new TeamModel();
var teamInfo = await GetTeamInfo(teamId);
if (teamInfo == null)
{
result.state = 0;
result.user = new List<TeamUser>();
result.team = new game_team();
return result;
}
else
{
var mapService = App.GetService<IGameMapService>();
result.state = 1;
result.team = teamInfo;
var members = await GetTeamMember(teamId);
List<TeamUser> user = new List<TeamUser>();
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<TeamModel> GetUserTeamInfo(string userId)
{
string key = string.Format(UserCache.BaseCacheKeys, "TeamData", userId);
if (await redis.ExistsAsync(key))
{
return await redis.GetAsync<TeamModel>(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<string> memberDataKeys = new List<string>();
List<string> userDataKeys = new List<string>();
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<bool> 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<unit_user_team>();
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<unit_user_team>()
.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<bool> Remove(string userId, string teamId)
{
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_team>();
var result = await db.Updateable<unit_user_team>()
.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<game_team>();
await db.Deleteable<game_team>().Where(it => it.teamId == teamId).ExecuteCommandAsync();
await db.Updateable<unit_user_team>()
.SetColumns(it => it.teamId == "0")
.Where(it => it.teamId == teamId).ExecuteCommandAsync();
await ClearTeamCache(teamId);
}
public async Task<bool> UpdateTeamName(string teamId, string name)
{
var db = DbClient.AsTenant().GetConnectionWithAttr<game_team>();
bool result = await db.Updateable<game_team>().SetColumns(it => it.name == name)
.Where(it => it.teamId == teamId).ExecuteCommandAsync() > 0;
if (result)
{
await ClearTeamCache(teamId);
}
return result;
}
}

View File

@@ -256,6 +256,12 @@ public class UnitUserService(ISqlSugarClient DbClient, IRedisCache redis) : IUni
onlineTime.monthTime = 0; onlineTime.monthTime = 0;
onlineTime.totalTime = 0; onlineTime.totalTime = 0;
db.Insertable(onlineTime).AddQueue(); 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); await db.SaveQueuesAsync(false);
} }

View File

@@ -158,7 +158,7 @@ public class GameBus
isok = false; isok = false;
} }
} }
else if (item.code ==nameof( GameEnum.PropCode.vigour)) //活力 else if (item.code == nameof(GameEnum.PropCode.vigour)) //活力
{ {
var attrService = App.GetService<IUnitUserAttrService>(); var attrService = App.GetService<IUnitUserAttrService>();
var MyAcc = await attrService.GetUserVigourInfo(userId); var MyAcc = await attrService.GetUserVigourInfo(userId);
@@ -168,7 +168,7 @@ public class GameBus
isok = false; isok = false;
} }
} }
else if (item.code ==nameof( GameEnum.PropCode.lev)) else if (item.code == nameof(GameEnum.PropCode.lev))
{ {
var attrService = App.GetService<IUnitUserAttrService>(); var attrService = App.GetService<IUnitUserAttrService>();
var MyLev = await attrService.GetUserLev(userId); var MyLev = await attrService.GetUserLev(userId);
@@ -177,6 +177,7 @@ public class GameBus
isok = false; isok = false;
} }
} }
result.result = isok; result.result = isok;
result.isDeal = isDeal; result.isDeal = isDeal;
result.isGive = isGive; result.isGive = isGive;
@@ -218,4 +219,102 @@ public class GameBus
} }
#endregion #endregion
#region
public static List<TowerGet> GetRandomGoods(RandomModel random, int count = 1, int luck = 0)
{
List<TowerGet> result = new List<TowerGet>();
for (int i = 0; i < count; i++)
{
List<RandomData> timeAward = new List<RandomData>();
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<RandomData> RandomHandleByWeight(RandomModel random, int luck = 0)
{
var _randomInstance = new Random();
List<RandomData> result = new List<RandomData>();
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<RandomData> RandomHandleByChance(RandomModel random, int luck = 0)
{
var _randomInstance = new Random();
List<RandomData> result = new List<RandomData>();
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
} }

View File

@@ -13,6 +13,7 @@ public class UserModelTool
UserModel result = new UserModel(); UserModel result = new UserModel();
if (userId == "0") if (userId == "0")
{ {
result.userId = "0";
result.userNo = "0"; result.userNo = "0";
result.nick = "海精灵"; result.nick = "海精灵";
result.sex = "女"; result.sex = "女";
@@ -29,6 +30,7 @@ public class UserModelTool
var userInfo = await userService.GetUserInfoByUserId(userId); var userInfo = await userService.GetUserInfoByUserId(userId);
if (userInfo != null) if (userInfo != null)
{ {
result.userId = userInfo.userId;
result.userNo = userInfo.userNo; result.userNo = userInfo.userNo;
result.nick = userInfo.nick; result.nick = userInfo.nick;
result.sex = userInfo.sex; result.sex = userInfo.sex;

View File

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

View File

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

View File

@@ -0,0 +1,6 @@
namespace Application.Web;
public class UpdateTeamNameParms
{
public string name { get; set; }
}

View File

@@ -1,9 +1,9 @@
<template> <template>
<div class="content"> <div class="content">
<Acheak @click="ChangeBag('0')" :on-value="type" on-cheak="0">好友</Acheak>|<Acheak @click="ChangeBag('1')" <Acheak @click="ChangeData('0')" :on-value="type" on-cheak="0">好友</Acheak>|<Acheak @click="ChangeData('1')"
:on-value="type" on-cheak="1">密友</Acheak>|<Acheak @click="ChangeBag('2')" :on-value="type" on-cheak="2"> :on-value="type" on-cheak="1">密友</Acheak>|<Acheak @click="ChangeData('2')" :on-value="type" on-cheak="2">
师徒</Acheak>|<Acheak @click="ChangeBag('3')" :on-value="type" on-cheak="3">仇人</Acheak> 师徒</Acheak>|<Acheak @click="ChangeData('3')" :on-value="type" on-cheak="3">仇人</Acheak>
</div> </div>
<div class="content"> <div class="content">
@@ -98,8 +98,8 @@ const BindData = async (): Promise<void> => {
} }
}; };
/**切换背包 */ /**切换数据 */
const ChangeBag = async (_type: string): Promise<void> => { const ChangeData = async (_type: string): Promise<void> => {
type.value = _type; type.value = _type;
await BindData(); await BindData();
} }

View File

@@ -1 +1,157 @@
<template></template> <template>
<div v-if="state != 2">
<div class="content">
我的队伍.<Abar href="/user/team/team">队伍列表</Abar>
</div>
<div class="content" v-if="state == 0">
暂无队伍,<Abutton @click="CreateTeam">立即创建</Abutton>?
</div>
<div class="content" v-if="state == 1">
名称{{ team.name }} <span v-if="isMaster">(<Abutton @click="ShowUpdateName">修改</Abutton>)</span><br>
成员({{ user.length }}/{{ team.count }})<br>
分类{{ codeTips }}<br>
队长<GameUser :data="master.user" :show-icon="0"></GameUser>
<span>{{ master.isOnline == 1 ? "(在线)" : "(离线)" }}</span><br>
<div>
<span v-if="member.length == 0">
->暂无队员.
</span>
<div v-for="item in member">
队员<GameUser :data="item.user" :show-icon="0"></GameUser>
<span>{{ item.isOnline == 1 ? "(在线)" : "(离线)" }}</span>
<span v-if="isMaster">
[<Abutton @click="RemoveUser(item.user.userId)">踢出</Abutton>]
</span>
</div>
</div>
<div>
<Abutton @click="ExitTeam">退出队伍</Abutton>
</div>
</div>
</div>
<div v-if="state == 2">
<div class="content">
创建队伍
</div>
<div class="content">
1.<Abutton @click="AddTeam(0, '')">创建普通队伍</Abutton><br>
</div>
</div>
<GamePopup v-model:show="showInfo" title="【修改队名】" style="min-width: 50%;">
<!-- 自定义内容 -->
<div class="content">
<div class="common serch" style="font-size: 16px; margin-top: 10px;">
队名:&nbsp;&nbsp;<input type="text" class="search-ipt" v-model="teamName" max-height="25">
</div>
<div style="text-align: center;">
<button class="ipt-btn" name="serch" @click="UpdateTeamName">修改</button>
</div>
</div>
</GamePopup>
</template>
<script setup lang="ts">
definePageMeta({
layout: layout.default,
middleware: 'page-loading'
})
const state = ref(0);
const codeTips = ref('');
const team = ref<any>({});
const user = ref<Array<any>>([]);
const master = ref<any>({});
const member = ref<Array<any>>([]);
const teamName = ref('');
const isMaster = ref(false);
onMounted(async () => {
try {
await BindData();
}
finally {
PageLoading.Close();
}
})
const BindData = async (): Promise<void> => {
let result = await TeamService.GetMyTeam();
if (result.code == 0) {
state.value = result.data.state;
team.value = result.data.team;
user.value = result.data.user;
codeTips.value = result.data.codeTips;
master.value = user.value.find(it => it.user.userId == team.value.masterId);
member.value = user.value.filter(it => it.user.userId != team.value.masterId);
teamName.value = team.value.name;
isMaster.value = team.value.masterId == StateHelper.userId;
}
else {
MessageExtend.ShowDialog("提示", result.msg);
}
};
const AddTeam = async (type: number, par: string) => {
MessageExtend.LoadingToast("创建中...");
let result = await TeamService.CreateTeam(type, par);
MessageExtend.LoadingClose();
if (result.code == 0) {
await BindData();
MessageExtend.Notify("队伍创建成功!", "success");
}
else {
MessageExtend.ShowDialog("创建队伍", result.msg);
}
}
const CreateTeam = () => {
state.value = 2;
}
const ExitTeam = async () => {
MessageExtend.ShowConfirmDialogAsyc("退出队伍", `您确定要退出队伍吗?(队长退出则队伍解散)`, async () => {
let result = await TeamService.ExitTeam();
if (result.code == 0) {
await BindData();
MessageExtend.Notify("成功退出队伍!", "success");
}
else {
MessageExtend.Notify(result.msg, "danger");
}
return true;
});
}
const showInfo = ref(false);
const UpdateTeamName = async () => {
MessageExtend.LoadingToast("修改中...");
let result = await TeamService.UpdateTeamName(teamName.value);
MessageExtend.LoadingClose();
if (result.code == 0) {
showInfo.value = false;
await BindData();
MessageExtend.Notify("修改成功!", "success");
}
else {
MessageExtend.ShowDialog("修改队名", result.msg);
}
}
const ShowUpdateName = () => {
showInfo.value = true;
}
const RemoveUser = async (user: string) => {
MessageExtend.ShowConfirmDialogAsyc("踢出队员", `您确定要把Ta踢出队伍吗?`, async () => {
let result = await TeamService.RemoveUser(user);
if (result.code == 0) {
await BindData();
MessageExtend.Notify("成功踢出队伍!", "success");
}
else {
MessageExtend.Notify(result.msg, "danger");
}
return true;
});
}
</script>

View File

@@ -0,0 +1 @@
<template></template>

View File

@@ -0,0 +1,102 @@
<template>
<div class="content">
队伍列表 <Abutton @click="Refresh">刷新</Abutton><br>
<Acheak @click="ChangeData('0')" :on-value="type" on-cheak="0">普通</Acheak>|
<Acheak @click="ChangeData('1')" :on-value="type" on-cheak="1">副本</Acheak>|
<Acheak @click="ChangeData('2')" :on-value="type" on-cheak="2">其他</Acheak>
</div>
<div class="content">
<span v-if="data.length == 0">暂无队伍.</span>
<div v-for="(item, index) in data" :key="index">
{{ PageExtend.GetPageIndex(currentPage, 10, index + 1) }}.
<Abar :href='"/user/team/info?id=" + item.team.teamId'>{{ item.team.name
}}({{ item.user.length }}/{{ item.team.count }})</Abar>
[<Abutton @click="JoinTeam(item.team.teamId)">加入</Abutton>]
</div>
</div>
<div class="content">
<Pagination :currentPage="currentPage" :limit="10" :total="total" @pageChange="handlePageChange" />
</div>
</template>
<script setup lang="ts">
interface teamStorage {
type: string
page: number
}
definePageMeta({
layout: layout.default,
middleware: 'page-loading'
})
const currentPage = ref<number>(1);
const total = ref<number>(0);
const data = ref<Array<any>>([]);
const type = ref('0');
onMounted(async () => {
try {
let localData = LocalStorageExtend.Get<teamStorage>("TeamCache");
if (localData != null) {
type.value = localData.type;
currentPage.value = localData.page;
}
await BindData();
}
finally {
PageLoading.Close();
}
})
const BindData = async (): Promise<void> => {
let result = await TeamService.GetTeamData(Number(type.value), currentPage.value);
if (result.code == 0) {
data.value = result.data.data;
total.value = result.data.total;
//存储请求参数
let addLocalData: teamStorage = { type: type.value, page: currentPage.value };
LocalStorageExtend.Set("TeamCache", addLocalData);
}
else {
MessageExtend.ShowDialog("提示", result.msg);
}
};
/**切换数据 */
const ChangeData = async (_type: string): Promise<void> => {
type.value = _type;
await BindData();
}
/**刷新 */
const Refresh = async (): Promise<void> => {
MessageExtend.LoadingToast("刷新中...");
currentPage.value = 1;
await BindData();
MessageExtend.LoadingClose();
PageExtend.ScrollToTop();
}
/**翻页 */
const handlePageChange = async (page: number): Promise<void> => {
currentPage.value = page;
await BindData();
};
const JoinTeam = async (teamId: string) => {
MessageExtend.LoadingToast("加入中...");
let result = await TeamService.JoinTeam(teamId);
MessageExtend.LoadingClose();
if (result.code == 0) {
PageExtend.Redirect("/user/team");
}
else {
MessageExtend.ShowDialog("加入队伍", result.msg);
}
}
</script>

View File

@@ -0,0 +1,66 @@
export class TeamService {
/**
* 获取我的队伍
* GET /Team/GetMyTeam
*/
static async GetMyTeam() {
return await ApiService.Request("get", "/Team/GetMyTeam");
}
/**
* 创建队伍
* GET /Team/CreateTeam
*/
static async CreateTeam(type: number, par: string) {
return await ApiService.Request("get", "/Team/CreateTeam", { type, par });
}
/**
* 加入队伍
* GET /Team/JoinTeam
*/
static async JoinTeam(teamId: string) {
return await ApiService.Request("get", "/Team/JoinTeam", { teamId });
}
/**
* 获取队伍信息
* GET /Team/GetTeamInfo
*/
static async GetTeamInfo(teamId: string) {
return await ApiService.Request("get", "/Team/GetTeamInfo", { teamId });
}
/**
* 退出队伍
* GET /Team/ExitTeam
*/
static async ExitTeam() {
return await ApiService.Request("get", "/Team/ExitTeam");
}
/**
* 修改队名
* POST /Team/UpdateTeamName
* @param name body
*/
static async UpdateTeamName(name: string) {
return await ApiService.Request("post", "/Team/UpdateTeamName", { name });
}
/**
* 踢出成员
* GET /Team/RemoveUser
*/
static async RemoveUser(user: string) {
return await ApiService.Request("get", "/Team/RemoveUser", { user });
}
/**
* 获取队伍列表
* GET /Team/GetTeamData
*/
static async GetTeamData(type: number, page: number) {
return await ApiService.Request("get", "/Team/GetTeamData", { type, page });
}
}