From bd1535aee999052c6812f5808d8aea4598db7800 Mon Sep 17 00:00:00 2001 From: Putoo <290555932@qq.com> Date: Fri, 29 May 2026 19:06:51 +0800 Subject: [PATCH] 1111 --- Kx.SeaTime.sln.DotSettings.user | 1 + .../game/user/unit_user_friend.cs | 26 +- .../game/user/unit_user_mail.cs | 63 +++++ .../game/user/unit_user_message_event.cs | 72 ++++++ .../model/MsgEventBtn.cs | 8 + .../model/TowerGet.cs | 36 +++ .../model/UserModel.cs | 1 + .../model/UserOnMap.cs | 10 + .../view/RelationView.cs | 11 + .../Application.Domain/Enum/MessageEnum.cs | 11 + .../Handle/MessageHandle.cs | 55 +++++ .../Interface/Chat/IGameChatService.cs | 7 +- .../Services/Interface/Map/IGameMapService.cs | 1 + .../Services/Interface/Pub/IMessageService.cs | 28 ++- .../Interface/User/IUnitUserAttrService.cs | 2 +- .../User/IUnitUserRelationService.cs | 14 ++ .../Services/Service/Chat/GameChatService.cs | 31 ++- .../Services/Service/Map/GameMapService.cs | 32 ++- .../Services/Service/Pub/MessageService.cs | 230 ++++++++++++++++-- .../Service/User/UnitUserAttrService.cs | 12 + .../Service/User/UnitUserRelationService.cs | 66 +++++ .../Application.Domain/Tool/Base/GameBus.cs | 24 ++ .../Application.Domain/Tool/Base/UbbTool.cs | 9 + .../Tool/ModelTool/UserModelTool.cs | 8 +- .../Extends/PageExtend.cs | 27 ++ .../Controllers/Chat/ChatController.cs | 77 +++--- .../Controllers/Map/MapController.cs | 12 +- .../Controllers/Pub/MessageController.cs | 150 +++++++++++- .../Controllers/User/RelationController.cs | 117 +++++++++ .../Controllers/User/UserController.cs | 36 ++- Web/src/app.vue | 9 +- Web/src/components/Business/GameChat.vue | 10 +- Web/src/components/Business/GameUser.vue | 5 +- Web/src/composables/HtmlEvent.ts | 12 + Web/src/extends/PageExtend.ts | 4 + Web/src/extends/StringExtend.ts | 43 ++++ Web/src/extends/TimeExtend.ts | 1 + Web/src/pages/chat/index.vue | 2 +- Web/src/pages/friend/index.vue | 130 +++++++++- Web/src/pages/friend/search.vue | 50 ++++ Web/src/pages/message/index.vue | 75 +++++- Web/src/pages/message/mail.vue | 77 ++++++ Web/src/pages/message/read.vue | 3 +- Web/src/pages/user/user.vue | 24 +- Web/src/services/Index/MessageService.ts | 24 ++ Web/src/services/user/RelationService.ts | 17 ++ Web/src/services/user/UserService.ts | 8 + Web/src/utility‌/GameTool.ts | 33 ++- 48 files changed, 1571 insertions(+), 133 deletions(-) create mode 100644 Service/Application.Domain.Entity/game/user/unit_user_mail.cs create mode 100644 Service/Application.Domain.Entity/game/user/unit_user_message_event.cs create mode 100644 Service/Application.Domain.Entity/model/MsgEventBtn.cs create mode 100644 Service/Application.Domain.Entity/model/TowerGet.cs create mode 100644 Service/Application.Domain.Entity/model/UserOnMap.cs create mode 100644 Service/Application.Domain.Entity/view/RelationView.cs create mode 100644 Service/Application.Domain/Enum/MessageEnum.cs create mode 100644 Service/Application.Domain/Handle/MessageHandle.cs create mode 100644 Service/Application.Domain/Services/Interface/User/IUnitUserRelationService.cs create mode 100644 Service/Application.Domain/Services/Service/User/UnitUserRelationService.cs create mode 100644 Service/Application.Domain/Tool/Base/UbbTool.cs create mode 100644 Service/Application.Service.Pub/Extends/PageExtend.cs create mode 100644 Service/Application.Web/Controllers/User/RelationController.cs create mode 100644 Web/src/composables/HtmlEvent.ts create mode 100644 Web/src/extends/StringExtend.ts create mode 100644 Web/src/pages/friend/search.vue create mode 100644 Web/src/pages/message/mail.vue create mode 100644 Web/src/services/user/RelationService.ts diff --git a/Kx.SeaTime.sln.DotSettings.user b/Kx.SeaTime.sln.DotSettings.user index d9b405e..c53c730 100644 --- a/Kx.SeaTime.sln.DotSettings.user +++ b/Kx.SeaTime.sln.DotSettings.user @@ -5,6 +5,7 @@ ForceIncluded ForceIncluded ForceIncluded + ForceIncluded ForceIncluded ForceIncluded ForceIncluded diff --git a/Service/Application.Domain.Entity/game/user/unit_user_friend.cs b/Service/Application.Domain.Entity/game/user/unit_user_friend.cs index 963098e..39eb3ef 100644 --- a/Service/Application.Domain.Entity/game/user/unit_user_friend.cs +++ b/Service/Application.Domain.Entity/game/user/unit_user_friend.cs @@ -7,34 +7,28 @@ namespace Application.Domain.Entity public class unit_user_friend { /// - /// fId + /// frId /// - [SugarColumn(IsPrimaryKey = true, Length = 50)] - public string fId { get; set; } + [SugarColumn(IsPrimaryKey = true, Length = 100)] + public string frId { get; set; } /// - /// sId + /// userId /// [SugarColumn(Length = 50, IsNullable = true)] - public string? sId { get; set; } + public string? userId { get; set; } /// - /// mId + /// toId /// [SugarColumn(Length = 50, IsNullable = true)] - public string? mId { get; set; } + public string? toId { get; set; } /// - /// near + /// 亲密度 /// [SugarColumn(IsNullable = true)] - public int? near { get; set; } - - /// - /// status - /// - [SugarColumn(IsNullable = true)] - public int? status { get; set; } + public long? near { get; set; } /// /// addTime @@ -42,4 +36,4 @@ namespace Application.Domain.Entity [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_mail.cs b/Service/Application.Domain.Entity/game/user/unit_user_mail.cs new file mode 100644 index 0000000..49ab93b --- /dev/null +++ b/Service/Application.Domain.Entity/game/user/unit_user_mail.cs @@ -0,0 +1,63 @@ +using SqlSugar; +using System; + +namespace Application.Domain.Entity +{ + [Tenant("Kg.SeaTime.Game")] + public class unit_user_mail + { + /// + /// mailId + /// + [SugarColumn(IsPrimaryKey = true, Length = 50)] + public string mailId { get; set; } + + /// + /// userId + /// + [SugarColumn(Length = 50, IsNullable = true)] + public string? userId { get; set; } + + /// + /// name + /// + [SugarColumn(Length = 50, IsNullable = true)] + public string? name { get; set; } + + /// + /// sign + /// + [SugarColumn(IsNullable = true)] + public string? sign { get; set; } + + /// + /// isRead + /// + [SugarColumn(IsNullable = true)] + public int? isRead { get; set; } + + /// + /// isGet + /// + [SugarColumn(IsNullable = true)] + public int? isGet { get; set; } + + /// + /// award + /// + [SugarColumn(IsNullable = true,IsJson = true)] + public List award { get; set; } + + /// + /// addTime + /// + [SugarColumn(IsNullable = true)] + public DateTime? addTime { get; set; } + + /// + /// endTime + /// + [SugarColumn(IsNullable = true)] + public long? endTime { get; set; } + } +} \ No newline at end of file diff --git a/Service/Application.Domain.Entity/game/user/unit_user_message_event.cs b/Service/Application.Domain.Entity/game/user/unit_user_message_event.cs new file mode 100644 index 0000000..ddfe84c --- /dev/null +++ b/Service/Application.Domain.Entity/game/user/unit_user_message_event.cs @@ -0,0 +1,72 @@ +using SqlSugar; +using System; + +namespace Application.Domain.Entity +{ + [Tenant("Kg.SeaTime.Game")] + public class unit_user_message_event + { + /// + /// eventId + /// + [SugarColumn(IsPrimaryKey = true, Length = 50)] + public string eventId { get; set; } + + /// + /// userId + /// + [SugarColumn(Length = 50, IsNullable = true)] + public string? userId { get; set; } + + /// + /// code + /// + [SugarColumn(Length = 50, IsNullable = true)] + public string? code { get; set; } + + /// + /// name + /// + [SugarColumn(Length = 50, IsNullable = true)] + public string? name { get; set; } + + /// + /// sign + /// + [SugarColumn(Length = 255, IsNullable = true)] + public string? sign { get; set; } + + [SugarColumn(IsNullable = true)] + public string? pars { get; set; } + + /// + /// state + /// + [SugarColumn(IsNullable = true)] + public int? state { get; set; } + + /// + /// btns + /// + [SugarColumn(IsNullable = true, IsJson = true)] + public List btns { get; set; } + + /// + /// addTime + /// + [SugarColumn(IsNullable = true)] + public DateTime? addTime { get; set; } + + /// + /// endTime + /// + [SugarColumn(IsNullable = true)] + public long? endTime { get; set; } + + /// + /// token + /// + [SugarColumn(Length = 255, IsNullable = true)] + public string? token { get; set; } + } +} \ No newline at end of file diff --git a/Service/Application.Domain.Entity/model/MsgEventBtn.cs b/Service/Application.Domain.Entity/model/MsgEventBtn.cs new file mode 100644 index 0000000..57e7b59 --- /dev/null +++ b/Service/Application.Domain.Entity/model/MsgEventBtn.cs @@ -0,0 +1,8 @@ +namespace Application.Domain.Entity; + +public class MsgEventBtn +{ + public int status { get; set; } + public string name { get; set; } + public string tips { get; set; } +} \ No newline at end of file diff --git a/Service/Application.Domain.Entity/model/TowerGet.cs b/Service/Application.Domain.Entity/model/TowerGet.cs new file mode 100644 index 0000000..153178b --- /dev/null +++ b/Service/Application.Domain.Entity/model/TowerGet.cs @@ -0,0 +1,36 @@ +namespace Application.Domain.Entity; + +public class TowerGet +{ + private System.String _code; + + /// + /// + /// + public System.String code + { get { return this._code; } set { this._code = value; } } + + private System.String _name; + + /// + /// + /// + public System.String name + { get { return this._name; } set { this._name = value; } } + + private System.String _parameter; + + /// + /// + /// + public System.String parameter + { get { return this._parameter; } set { this._parameter = value; } } + + private long _count; + + /// + /// + /// + public long count + { get { return this._count; } set { this._count = value; } } +} \ 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 d1c58dc..a62c186 100644 --- a/Service/Application.Domain.Entity/model/UserModel.cs +++ b/Service/Application.Domain.Entity/model/UserModel.cs @@ -8,4 +8,5 @@ public class UserModel public string headImg { get; set; } public int area { get; set; } public string icon { get; set; } + public int lev { get; set; } } \ No newline at end of file diff --git a/Service/Application.Domain.Entity/model/UserOnMap.cs b/Service/Application.Domain.Entity/model/UserOnMap.cs new file mode 100644 index 0000000..bc2ae83 --- /dev/null +++ b/Service/Application.Domain.Entity/model/UserOnMap.cs @@ -0,0 +1,10 @@ +namespace Application.Domain.Entity; + +public class UserOnMap +{ + public string mapId { get; set; } + public string mapName { get; set; } + public int cityId { get; set; } + public string cityName { get; set; } + public int isOnline { get; set; } +} \ No newline at end of file diff --git a/Service/Application.Domain.Entity/view/RelationView.cs b/Service/Application.Domain.Entity/view/RelationView.cs new file mode 100644 index 0000000..4fb251e --- /dev/null +++ b/Service/Application.Domain.Entity/view/RelationView.cs @@ -0,0 +1,11 @@ +namespace Application.Domain.Entity; + +public class RelationView +{ + public UserModel user { get; set; } + public long near { get; set; } + public string mapName { get; set; } + public string cityName { get; set; } + public long sort { get; set; } + public int isOnline { get; set; } +} \ No newline at end of file diff --git a/Service/Application.Domain/Enum/MessageEnum.cs b/Service/Application.Domain/Enum/MessageEnum.cs new file mode 100644 index 0000000..c3a18ac --- /dev/null +++ b/Service/Application.Domain/Enum/MessageEnum.cs @@ -0,0 +1,11 @@ +namespace Application.Domain; + +public static class MessageEnum +{ + public enum EventCode + { + Friend,//交友消息 + Marry,//婚姻消息 + Trade,//交易通知 + } +} \ No newline at end of file diff --git a/Service/Application.Domain/Handle/MessageHandle.cs b/Service/Application.Domain/Handle/MessageHandle.cs new file mode 100644 index 0000000..47924b3 --- /dev/null +++ b/Service/Application.Domain/Handle/MessageHandle.cs @@ -0,0 +1,55 @@ +namespace Application.Domain; + +public class MessageHandle +{ + public async Task HandleMsg(unit_user_message_event events, int state) + { + if (events.code == nameof(MessageEnum.EventCode.Friend)) + { + var relationService = App.GetRequiredService(); + var isFriend = await relationService.CheckIsFriend(events.userId, events.pars); + if (isFriend) + { + return new MessageHandleResult() { success = true, msg = "你们已经是好友啦!" }; + } + + if (state == 1) + { + if (await relationService.AddFriend(events.userId, events.pars)) + { + var chatService = App.GetService(); + var userService = App.GetService(); + var myInfo = await userService.GetUserInfoByUserId(events.userId); + string sign = $"{UbbTool.HomeUbb(myInfo.userNo, myInfo.nick)}已通过了您的好友申请!"; + await chatService.SendChat(events.pars, (int)myInfo.areaId, nameof(GameChatEnum.Code.System), sign); + return new MessageHandleResult() { success = true, msg = "已通过该好友申请!" }; + } + else + { + return new MessageHandleResult() { success = false, msg = "好友添加失败,请稍后尝试!" }; + } + } + else + { + var chatService = App.GetService(); + var userService = App.GetService(); + var myInfo = await userService.GetUserInfoByUserId(events.userId); + string sign = $"{UbbTool.HomeUbb(myInfo.userNo, myInfo.nick)}拒绝了您的好友申请!"; + await chatService.SendChat(events.pars, (int)myInfo.areaId, nameof(GameChatEnum.Code.System), sign); + return new MessageHandleResult() { success = true, msg = "已拒绝该好友申请!" }; + } + } + else if (events.code == nameof(MessageEnum.EventCode.Friend)) + { + return new MessageHandleResult() { success = true, msg = "消息通知已处理!" }; + } + + return new MessageHandleResult() { success = false, msg = "暂不支持该操作处理!" }; + } +} + +public class MessageHandleResult +{ + public bool success { get; set; } + public string msg { get; set; } +} \ No newline at end of file diff --git a/Service/Application.Domain/Services/Interface/Chat/IGameChatService.cs b/Service/Application.Domain/Services/Interface/Chat/IGameChatService.cs index 6d1f618..c9f8fed 100644 --- a/Service/Application.Domain/Services/Interface/Chat/IGameChatService.cs +++ b/Service/Application.Domain/Services/Interface/Chat/IGameChatService.cs @@ -2,12 +2,13 @@ public interface IGameChatService { - Task> GetChatTop(int areaId, int top, string teamId, string groupId); + Task> GetChatTop(string userId,int areaId, int top, string teamId, string groupId); - Task> GetChatData(int type, int areaId, string teamId, string groupId, int page, int limit, + Task> GetChatData(string userId, int type, int areaId, string teamId, string groupId, int page, + int limit, RefAsync total); Task SendChat(string userId, int areaId, string code, string sign, string par = ""); + Task SendChat(string userId, string code, string sign, string par = ""); Task DeleteChat(string chatId); - } \ No newline at end of file diff --git a/Service/Application.Domain/Services/Interface/Map/IGameMapService.cs b/Service/Application.Domain/Services/Interface/Map/IGameMapService.cs index e8c474b..6b14d94 100644 --- a/Service/Application.Domain/Services/Interface/Map/IGameMapService.cs +++ b/Service/Application.Domain/Services/Interface/Map/IGameMapService.cs @@ -20,6 +20,7 @@ public interface IGameMapService Task GetUserOnMap(string userId); Task UpdateUserOnMap(string userId, string ip, string mapId); Task UpdateUserOnMap(unit_user_online data, string mapId); + Task GetUserOnMapInfo(string userId); Task SetUserMapDefult(string userId); Task GetToMapInfo(string userId, string toMap, bool isUpUserMap = true, bool isChangeCity = false); #endregion diff --git a/Service/Application.Domain/Services/Interface/Pub/IMessageService.cs b/Service/Application.Domain/Services/Interface/Pub/IMessageService.cs index 0d99597..bf1ca05 100644 --- a/Service/Application.Domain/Services/Interface/Pub/IMessageService.cs +++ b/Service/Application.Domain/Services/Interface/Pub/IMessageService.cs @@ -2,15 +2,16 @@ public interface IMessageService { - Task GetNoReadCount(string userId); + Task> GetNoReadCount(string userId); - #region 私聊消息 + #region 私聊消息 string GetTalkId(string userId, string otId); Task> GetUserNoReadData(string talkId); Task> GetUserMessageData(string talkId, int page, int limit, RefAsync total); + Task> GetUserMessage(string userId, int type, int page, int limit, RefAsync total); @@ -19,4 +20,27 @@ public interface IMessageService Task DeleteMsgByTalkId(string talkId, string userId); #endregion + + #region 邮件消息 + + Task> GetUserMailData(string userId, int page, int limit, RefAsync total); + Task GetMailInfo(string mailId); + Task SendMaill(string userId, string name, string sign, List award, int days = 10); + Task UpdateMaillInfo(unit_user_mail data); + + #endregion + + #region 通知消息 + + Task> GetUserEventMessage(string userId, int page, int limit, + RefAsync total); + + Task GetEventMessageInfo(string eventId); + Task UpdateEventData(unit_user_message_event data); + Task CheckAtEventMsg(string token); + + Task SendEventMsg(string userId, string code, string name, string sign, string pars, string token, + List btns = null, int days = 10); + + #endregion } \ No newline at end of file diff --git a/Service/Application.Domain/Services/Interface/User/IUnitUserAttrService.cs b/Service/Application.Domain/Services/Interface/User/IUnitUserAttrService.cs index ca16324..3469aa3 100644 --- a/Service/Application.Domain/Services/Interface/User/IUnitUserAttrService.cs +++ b/Service/Application.Domain/Services/Interface/User/IUnitUserAttrService.cs @@ -6,7 +6,7 @@ public interface IUnitUserAttrService Task GetUserAttrModel(string userId); Task GetUserAttr(string userId); - + Task GetUserLev(string userId); #endregion #region 体力操作 diff --git a/Service/Application.Domain/Services/Interface/User/IUnitUserRelationService.cs b/Service/Application.Domain/Services/Interface/User/IUnitUserRelationService.cs new file mode 100644 index 0000000..a1a04ee --- /dev/null +++ b/Service/Application.Domain/Services/Interface/User/IUnitUserRelationService.cs @@ -0,0 +1,14 @@ +namespace Application.Domain; + +public interface IUnitUserRelationService +{ + #region 好友关系 + + Task GetUserFriendCount(string userId); + Task> GetUserFriend(string userId); + Task CheckIsFriend(string userId, string toId); + Task AddFriend(string userId, string toId); + Task DeleteFriend(string userId, string toId); + + #endregion +} \ No newline at end of file diff --git a/Service/Application.Domain/Services/Service/Chat/GameChatService.cs b/Service/Application.Domain/Services/Service/Chat/GameChatService.cs index a6c9a0c..4146701 100644 --- a/Service/Application.Domain/Services/Service/Chat/GameChatService.cs +++ b/Service/Application.Domain/Services/Service/Chat/GameChatService.cs @@ -11,16 +11,18 @@ public class GameChatService : IGameChatService, ITransient _redisClient = redisClient; } - public async Task> GetChatTop(int areaId, int top, string teamId, string groupId) + public async Task> GetChatTop(string userId, int areaId, int top, string teamId, string groupId) { var db = _dbClient.AsTenant().GetConnectionWithAttr(); - List allCode = new List() { "Public", "Region", "System" }; + List allCode = new List() { "Public", "Region" }; var data = await db.Queryable().Where(it => it.state == 1 && ( (allCode.Contains(it.code) && it.areaId == areaId) || (it.code == "Group" && it.par == groupId) || (it.code == "Team" && it.par == teamId) || - (it.code == "Dress") + (it.code == "Dress") || + (it.code == "System" && it.areaId == areaId && + (it.userId == "0" || it.userId == userId)) ) ).Take(top).OrderByDescending(it => it.sort).ToListAsync(); @@ -34,7 +36,8 @@ public class GameChatService : IGameChatService, ITransient return result; } - public async Task> GetChatData(int type, int areaId, string teamId, string groupId, int page, + public async Task> GetChatData(string userId, int type, int areaId, string teamId, + string groupId, int page, int limit, RefAsync total) { @@ -42,13 +45,15 @@ public class GameChatService : IGameChatService, ITransient var db = _dbClient.AsTenant().GetConnectionWithAttr(); if (type == 0) { - List allCode = new List() { "Public", "Region", "System" }; + List allCode = new List() { "Public", "Region" }; data = await db.Queryable().Where(it => it.state == 1 && ( (allCode.Contains(it.code) && it.areaId == areaId) || (it.code == "Group" && it.par == groupId) || (it.code == "Team" && it.par == teamId) || - (it.code == "Dress") + (it.code == "Dress") || + (it.code == "System" && it.areaId == areaId && + (it.userId == "0" || it.userId == userId)) ) ).OrderByDescending(it => it.sort).ToPageListAsync(page, limit, total); } @@ -76,13 +81,16 @@ public class GameChatService : IGameChatService, ITransient else if (type == 5) //系统 { data = await db.Queryable() - .Where(it => it.state == 1 && it.code == "System" && it.areaId == areaId + .Where(it => + it.state == 1 && it.code == "System" && it.areaId == areaId && + (it.userId == "0" || it.userId == userId) ).OrderByDescending(it => it.sort).ToPageListAsync(page, limit, total); } else { data = new List(); } + var result = new List(); foreach (var item in data) { @@ -138,6 +146,15 @@ public class GameChatService : IGameChatService, ITransient var db = _dbClient.AsTenant().GetConnectionWithAttr(); return await db.Insertable(chat).ExecuteCommandAsync() > 0; } + + public async Task SendChat(string userId, string code, string sign, string par = "") + { + var userService = App.GetService(); + var userInfo = await userService.GetUserInfoByUserId(userId); + if (userInfo == null) return false; + + return await SendChat(userId, (int)userInfo.areaId, code, sign, par); + } /// /// 删除聊天 diff --git a/Service/Application.Domain/Services/Service/Map/GameMapService.cs b/Service/Application.Domain/Services/Service/Map/GameMapService.cs index 79ee6b8..692f6d0 100644 --- a/Service/Application.Domain/Services/Service/Map/GameMapService.cs +++ b/Service/Application.Domain/Services/Service/Map/GameMapService.cs @@ -31,8 +31,7 @@ public class GameMapService(ISqlSugarClient DbClient, IRedisCache redis) : IGame return data; } - - + public async Task> GetCityMap(int cityId) { @@ -147,6 +146,22 @@ public class GameMapService(ISqlSugarClient DbClient, IRedisCache redis) : IGame return data; } + public async Task GetUserOnMapInfo(string userId) + { + var onMap = await GetUserOnMap(userId); + var mapInfo = await GetMapInfo(onMap.mapId); + var cityInfo = await GetCityInfo((int)mapInfo.cityId); + int isOnline = + onMap.upTime > (TimeExtend.GetTimeStampBySeconds(DateTime.Now.AddMinutes(0 - GameConfig.OnLineTime))) + ? 1 + : 0; + return new UserOnMap() + { + mapId = mapInfo.mapId, mapName = mapInfo.mapName, cityId = cityInfo.cityId, cityName = cityInfo.cityName, + isOnline = isOnline + }; + } + public async Task UpdateUserOnMap(string userId, string ip, string mapId) { unit_user_online onLine = new unit_user_online(); @@ -320,7 +335,7 @@ public class GameMapService(ISqlSugarClient DbClient, IRedisCache redis) : IGame #endregion #region 自动寻路 - + private async Task> GetCityDataExcludeParent() { string key = string.Format(BaseCache.BaseCacheKeys, "MapPathData", "CityParent"); @@ -332,8 +347,10 @@ public class GameMapService(ISqlSugarClient DbClient, IRedisCache redis) : IGame await redis.SetAsync(key, data); } + return data; } + private async Task> GetAllMaoToData() { string key = string.Format(BaseCache.BaseCacheKeys, "MapPathData", "CityInterCityPortal"); @@ -343,7 +360,7 @@ public class GameMapService(ISqlSugarClient DbClient, IRedisCache redis) : IGame } List result = new List(); - + var cityData = await GetCityDataExcludeParent(); foreach (var item in cityData) { @@ -356,9 +373,11 @@ public class GameMapService(ISqlSugarClient DbClient, IRedisCache redis) : IGame } } } + await redis.SetAsync(key, result); return result; } + /// /// 城市信息 /// @@ -378,7 +397,7 @@ public class GameMapService(ISqlSugarClient DbClient, IRedisCache redis) : IGame { var cityTemp = new CityNode(city.cityId, city.cityName, new Point((int)mdMap.x, (int)mdMap.y), mdMap.mapName, (int)city.x_s, (int)city.x_e, (int)city.y_s, (int)city.y_e); - data.Add(cityTemp); + data.Add(cityTemp); } } @@ -413,8 +432,7 @@ public class GameMapService(ISqlSugarClient DbClient, IRedisCache redis) : IGame return data; } - - + /// /// 传送点信息 /// diff --git a/Service/Application.Domain/Services/Service/Pub/MessageService.cs b/Service/Application.Domain/Services/Service/Pub/MessageService.cs index b4ff8b1..214af37 100644 --- a/Service/Application.Domain/Services/Service/Pub/MessageService.cs +++ b/Service/Application.Domain/Services/Service/Pub/MessageService.cs @@ -1,30 +1,29 @@ -namespace Application.Domain; +using Dm.util; + +namespace Application.Domain; public class MessageService(ISqlSugarClient DbClient, IRedisCache redis) : IMessageService, ITransient { - public async Task GetNoReadCount(string userId) + public async Task> GetNoReadCount(string userId) { - string key = string.Format(UserCache.BaseCacheKeys, "Message", "Count"); - if (await redis.HExistsHashAsync(key, userId)) - { - return await redis.GetHashAsync(key, userId); - } - - int result = 0; + List result = new List(); //普通消息 - int noRead = await GetUserNoReadDataCountByUserId(userId); - result += noRead; - //邮件详细 + int noRead = await GetUserNoReadMsgCount(userId); + result.Add(noRead); + //通知消息 - await redis.AddHashAsync(key, userId, result); + int noEvent = await GetUserNoReadEventMsgCount(userId); + result.Add(noEvent); + + //邮件详细 + int noMail = await GetUserNoReadMailCount(userId); + result.Add(noMail); + + //汇总 + result.Add(result.Sum()); return result; } - private async Task ClearMessageCache(string userId) - { - string key = string.Format(UserCache.BaseCacheKeys, "Message", "Count"); - await redis.DelHashAsync(key, userId); - } #region 私信消息 @@ -38,11 +37,25 @@ public class MessageService(ISqlSugarClient DbClient, IRedisCache redis) : IMess return talkId.Split('_').ToList(); } - private async Task GetUserNoReadDataCountByUserId(string userId) + private async Task GetUserNoReadMsgCount(string userId) { + string key = string.Format(UserCache.BaseCacheKeys, "Message", "MsgCount"); + if (await redis.HExistsHashAsync(key, userId)) + { + return await redis.GetHashAsync(key, userId); + } + var db = DbClient.AsTenant().GetConnectionScopeWithAttr(); - return await db.Queryable() + int count = await db.Queryable() .Where(it => it.status == 1 && it.userId == userId && it.isRead == 0).CountAsync(); + await redis.AddHashAsync(key, userId, count); + return count; + } + + private async Task ClearMsgCountCache(string userId) + { + string key = string.Format(UserCache.BaseCacheKeys, "Message", "MsgCount"); + await redis.DelHashAsync(key, userId); } public async Task> GetUserNoReadData(string talkId) @@ -131,7 +144,7 @@ public class MessageService(ISqlSugarClient DbClient, IRedisCache redis) : IMess bool result = await db.Insertable(adds).ExecuteCommandAsync() > 0; if (result) { - await ClearMessageCache(toUser); + await ClearMsgCountCache(toUser); } return result; @@ -144,7 +157,7 @@ public class MessageService(ISqlSugarClient DbClient, IRedisCache redis) : IMess .Where(it => msgIds.Contains(it.msgId)).ExecuteCommandAsync() > 0; if (result) { - await ClearMessageCache(userId); + await ClearMsgCountCache(userId); } } @@ -156,7 +169,178 @@ public class MessageService(ISqlSugarClient DbClient, IRedisCache redis) : IMess 0; if (result) { - await ClearMessageCache(userId); + await ClearMsgCountCache(userId); + } + + return result; + } + + #endregion + + #region 邮件消息 + + private async Task GetUserNoReadMailCount(string userId) + { + string key = string.Format(UserCache.BaseCacheKeys, "Message", "MailCount"); + if (await redis.HExistsHashAsync(key, userId)) + { + return await redis.GetHashAsync(key, userId); + } + + var db = DbClient.AsTenant().GetConnectionWithAttr(); + int count = await db.Queryable().Where(it => it.userId == userId && it.isRead == 0) + .CountAsync(); + await redis.AddHashAsync(key, userId, count); + return count; + } + + private async Task ClearMailCountCache(string userId) + { + string key = string.Format(UserCache.BaseCacheKeys, "Message", "MailCount"); + await redis.DelHashAsync(key, userId); + } + + public async Task> GetUserMailData(string userId, int page, int limit, RefAsync total) + { + long onTime = TimeExtend.GetTimeStampSeconds; + var db = DbClient.AsTenant().GetConnectionWithAttr(); + return await db.Queryable().Where(it => it.userId == userId && it.endTime > onTime) + .OrderBy(it => it.isGet, OrderByType.Asc) + .OrderBy(it => it.isRead, OrderByType.Asc) + .OrderByDescending(it => it.addTime) + .ToPageListAsync(page, limit, total); + } + + public async Task GetMailInfo(string mailId) + { + var db = DbClient.AsTenant().GetConnectionWithAttr(); + return await db.Queryable().Where(it => it.mailId == mailId) + .SingleAsync(); + } + + public async Task SendMaill(string userId, string name, string sign, List award, int days = 10) + { + unit_user_mail mail = new unit_user_mail(); + mail.mailId = StringAssist.NewGuid; + mail.userId = userId; + mail.name = name; + mail.sign = sign; + mail.isRead = 0; + mail.isGet = award.Count > 0 ? 0 : 1; + mail.award = award; + mail.addTime = DateTime.Now; + mail.endTime = TimeExtend.GetTimeStampBySeconds(DateTime.Now.AddDays(days)); + var db = DbClient.AsTenant().GetConnectionWithAttr(); + bool result = await db.Insertable(mail).ExecuteCommandAsync() > 0; + if (result) + { + await ClearMailCountCache(userId); + } + + return result; + } + + public async Task UpdateMaillInfo(unit_user_mail data) + { + var db = DbClient.AsTenant().GetConnectionWithAttr(); + bool result = await db.Updateable(data).ExecuteCommandAsync() > 0; + if (result) + { + await ClearMailCountCache(data.userId); + } + + return result; + } + + #endregion + + #region 通知消息 + + private async Task GetUserNoReadEventMsgCount(string userId) + { + string key = string.Format(UserCache.BaseCacheKeys, "Message", "EventCount"); + if (await redis.HExistsHashAsync(key, userId)) + { + return await redis.GetHashAsync(key, userId); + } + + var db = DbClient.AsTenant().GetConnectionScopeWithAttr(); + int Count = await db.Queryable().Where(it => it.userId == userId && it.state == 0) + .CountAsync(); + await redis.AddHashAsync(key, userId, Count); + return Count; + } + + private async Task ClearEventCountCache(string userId) + { + string key = string.Format(UserCache.BaseCacheKeys, "Message", "EventCount"); + await redis.DelHashAsync(key, userId); + } + + public async Task> GetUserEventMessage(string userId, int page, int limit, + RefAsync total) + { + var db = DbClient.AsTenant().GetConnectionScopeWithAttr(); + return await db.Queryable().Where(it => it.userId == userId) + .OrderByDescending(it => it.addTime) + .ToPageListAsync(page, limit, total); + } + + public async Task GetEventMessageInfo(string eventId) + { + var db = DbClient.AsTenant().GetConnectionScopeWithAttr(); + return await db.Queryable().Where(it => it.eventId == eventId) + .SingleAsync(); + } + + public async Task UpdateEventData(unit_user_message_event data) + { + var db = DbClient.AsTenant().GetConnectionScopeWithAttr(); + var result = await db.Updateable(data).ExecuteCommandAsync() > 0; + if (result) + { + await ClearEventCountCache(data.userId); + } + + return result; + } + + public async Task CheckAtEventMsg(string token) + { + var db = DbClient.AsTenant().GetConnectionScopeWithAttr(); + return await db.Queryable().Where(it => it.state == 0 && it.token == token).AnyAsync(); + } + + public async Task SendEventMsg(string userId, string code, string name, string sign, string pars,string token, + List btns=null, int days = 10) + { + unit_user_message_event data = new unit_user_message_event(); + data.eventId = StringAssist.NewGuid; + data.userId = userId; + data.code = code; + data.name = name; + data.sign = sign; + data.pars = pars; + data.state = 0; + if (btns == null) + { + data.btns = new List() + { + new MsgEventBtn() { status = 1, name = "我知道啦", tips = "已处理" } + }; + } + else + { + data.btns = btns; + } + data.addTime = DateTime.Now; + data.endTime = TimeExtend.GetTimeStampBySeconds(DateTime.Now.AddDays(days)); + data.token = token; + var db = DbClient.AsTenant().GetConnectionScopeWithAttr(); + var result = await db.Insertable(data).ExecuteCommandAsync() > 0; + if (result) + { + await ClearEventCountCache(data.userId); } return result; diff --git a/Service/Application.Domain/Services/Service/User/UnitUserAttrService.cs b/Service/Application.Domain/Services/Service/User/UnitUserAttrService.cs index 2c6c8de..2a753a7 100644 --- a/Service/Application.Domain/Services/Service/User/UnitUserAttrService.cs +++ b/Service/Application.Domain/Services/Service/User/UnitUserAttrService.cs @@ -44,6 +44,18 @@ public class UnitUserAttrService(ISqlSugarClient DbClient, IRedisCache redis) : return data; } + public async Task GetUserLev(string userId) + { + int lev = 0; + var attrInfo = await GetUserAttr(userId); + if (attrInfo != null) + { + lev = (int)attrInfo.lev; + } + + return lev; + } + private async Task ClearUserAttrCache(string userId) { string key = string.Format(UserCache.BaseCacheKeys, "AttrData", "UserAttr"); diff --git a/Service/Application.Domain/Services/Service/User/UnitUserRelationService.cs b/Service/Application.Domain/Services/Service/User/UnitUserRelationService.cs new file mode 100644 index 0000000..204bdca --- /dev/null +++ b/Service/Application.Domain/Services/Service/User/UnitUserRelationService.cs @@ -0,0 +1,66 @@ +namespace Application.Domain; + +public class UnitUserRelationService(ISqlSugarClient DbClient, IRedisCache redis) : IUnitUserRelationService, ITransient +{ + #region 好友关系 + + public async Task GetUserFriendCount(string userId) + { + var db = DbClient.AsTenant().GetConnectionWithAttr(); + return await db.Queryable().Where(it => it.frId.Contains(userId)).CountAsync(); + } + + public async Task> GetUserFriend(string userId) + { + List result = new List(); + var db = DbClient.AsTenant().GetConnectionWithAttr(); + + var data = await db.Queryable().Where(it => it.frId.Contains(userId)) + .ToListAsync(); + foreach (var item in data) + { + RelationView temp = new RelationView(); + string otUser = item.userId == userId ? item.toId : item.userId; + temp.user = await UserModelTool.GetUserView(otUser); + temp.near = (long)item.near; + + var mapService = App.GetService(); + var onMap = await mapService.GetUserOnMapInfo(otUser); + temp.mapName = onMap.mapName; + temp.cityName = onMap.cityName; + temp.sort = TimeExtend.GetTimeStampBySeconds((DateTime)item.addTime); + temp.isOnline = onMap.isOnline; + result.Add(temp); + } + + return result; + } + + public async Task CheckIsFriend(string userId, string toId) + { + string frId = StringAssist.GetSortKey(userId, toId); + var db = DbClient.AsTenant().GetConnectionWithAttr(); + return await db.Queryable().Where(it => it.frId == frId).AnyAsync(); + } + + public async Task AddFriend(string userId, string toId) + { + unit_user_friend friend = new unit_user_friend(); + friend.frId = StringAssist.GetSortKey(userId, toId); + friend.userId = userId; + friend.toId = toId; + friend.near = 0; + friend.addTime = DateTime.Now; + var db = DbClient.AsTenant().GetConnectionWithAttr(); + return await db.Insertable(friend).ExecuteCommandAsync() > 0; + } + + public async Task DeleteFriend(string userId, string toId) + { + string frId = StringAssist.GetSortKey(userId, toId); + var db = DbClient.AsTenant().GetConnectionWithAttr(); + return await db.Deleteable().Where(it => it.frId == frId).ExecuteCommandAsync()>0; + } + + #endregion +} \ No newline at end of file diff --git a/Service/Application.Domain/Tool/Base/GameBus.cs b/Service/Application.Domain/Tool/Base/GameBus.cs index 619ba47..e8c00fb 100644 --- a/Service/Application.Domain/Tool/Base/GameBus.cs +++ b/Service/Application.Domain/Tool/Base/GameBus.cs @@ -68,5 +68,29 @@ public class GameBus return isok; } + public static async Task UpdateBag(string userId, int operate, dynamic Reward, string remark = "", + long count = 1) + { + try + { + foreach (var item in Reward) + { + long num = Convert.ToInt64(item.count) * count; + if (num <= 0) + { + continue; + } + + await UpdateBag(userId, operate, item.code, item.parameter, num, remark); + } + + return true; + } + catch + { + return false; + } + } + #endregion } \ No newline at end of file diff --git a/Service/Application.Domain/Tool/Base/UbbTool.cs b/Service/Application.Domain/Tool/Base/UbbTool.cs new file mode 100644 index 0000000..9bf7d20 --- /dev/null +++ b/Service/Application.Domain/Tool/Base/UbbTool.cs @@ -0,0 +1,9 @@ +namespace Application.Domain; + +public class UbbTool +{ + public static string HomeUbb(string no, string name) + { + return $"{name}"; + } +} \ 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 c9188b0..59e5fbd 100644 --- a/Service/Application.Domain/Tool/ModelTool/UserModelTool.cs +++ b/Service/Application.Domain/Tool/ModelTool/UserModelTool.cs @@ -8,7 +8,7 @@ public class UserModelTool /// /// /// - public static async Task GetUserView(string userId,bool addIcon=false) + public static async Task GetUserView(string userId, bool addIcon = false) { UserModel result = new UserModel(); if (userId == "0") @@ -19,10 +19,12 @@ public class UserModelTool result.headImg = ""; result.area = 0; result.icon = ""; + result.lev = 999; } else { var userService = App.GetService(); + var attrService = App.GetRequiredService(); var userInfo = await userService.GetUserInfoByUserId(userId); if (userInfo != null) { @@ -32,12 +34,14 @@ public class UserModelTool result.headImg = userInfo.headImg; result.area = (int)userInfo.areaId; result.icon = ""; - if (addIcon)//获取图标信息 + if (addIcon) //获取图标信息 { result.icon = ""; } + result.lev = await attrService.GetUserLev(userId); } } + return result; } } \ No newline at end of file diff --git a/Service/Application.Service.Pub/Extends/PageExtend.cs b/Service/Application.Service.Pub/Extends/PageExtend.cs new file mode 100644 index 0000000..7708c8f --- /dev/null +++ b/Service/Application.Service.Pub/Extends/PageExtend.cs @@ -0,0 +1,27 @@ +namespace Application.Service.Pub; + +public class PageExtend +{ + /// + /// List 通用分页 + /// + /// 数据源 + /// 当前页码(从1开始) + /// 每页条数 + /// 当前页数据 + public static List GetPageList(List list, int pageIndex, int pageSize) + { + // 空值保护 + if (list == null || list.Count == 0) + return new List(); + + // 页码最小为 1 + pageIndex = pageIndex < 1 ? 1 : pageIndex; + + // 分页核心 + return list + .Skip((pageIndex - 1) * pageSize) + .Take(pageSize) + .ToList(); + } +} \ No newline at end of file diff --git a/Service/Application.Web/Controllers/Chat/ChatController.cs b/Service/Application.Web/Controllers/Chat/ChatController.cs index a35073a..a40c024 100644 --- a/Service/Application.Web/Controllers/Chat/ChatController.cs +++ b/Service/Application.Web/Controllers/Chat/ChatController.cs @@ -12,7 +12,8 @@ public class ChatController : ControllerBase { private readonly IGameChatService _chatService; private readonly IGameGoodsService _goodsService; - public ChatController(IGameChatService chatService,IGameGoodsService goodsService) + + public ChatController(IGameChatService chatService, IGameGoodsService goodsService) { _chatService = chatService; _goodsService = goodsService; @@ -32,28 +33,28 @@ public class ChatController : ControllerBase string teamId = ""; string groupId = ""; RefAsync Total = 0; - var data = await _chatService.GetChatData(type, areaId, teamId, groupId, page, 10, Total); - //物品数量 - int sendGoodsCount = 0; - string sendGoodsName = ""; - switch (type) - { - case 0: - sendGoodsCount = await _goodsService.GetUserGoodsCount(userId,GameConfig.SendChatGoodsBase); - sendGoodsName = "小海螺"; + var data = await _chatService.GetChatData(userId, type, areaId, teamId, groupId, page, 10, Total); + //物品数量 + int sendGoodsCount = 0; + string sendGoodsName = ""; + switch (type) + { + case 0: + sendGoodsCount = await _goodsService.GetUserGoodsCount(userId, GameConfig.SendChatGoodsBase); + sendGoodsName = "小海螺"; break; - case 3: - sendGoodsCount = await _goodsService.GetUserGoodsCount(userId,GameConfig.SendChatGoodsArea); - sendGoodsName = "大海螺"; - break; - case 4: - sendGoodsCount = await _goodsService.GetUserGoodsCount(userId,GameConfig.SendChatGoodsService); - sendGoodsName = "金海螺"; - break; - } - - - return PoAction.Ok(new { data, total = Total.Value ,sendGoodsCount,sendGoodsName}); + case 3: + sendGoodsCount = await _goodsService.GetUserGoodsCount(userId, GameConfig.SendChatGoodsArea); + sendGoodsName = "大海螺"; + break; + case 4: + sendGoodsCount = await _goodsService.GetUserGoodsCount(userId, GameConfig.SendChatGoodsService); + sendGoodsName = "金海螺"; + break; + } + + + return PoAction.Ok(new { data, total = Total.Value, sendGoodsCount, sendGoodsName }); } /// @@ -79,7 +80,7 @@ public class ChatController : ControllerBase { case 0: isSend = true; - code =nameof(GameChatEnum.Code.Public); + code = nameof(GameChatEnum.Code.Public); goodsId = GameConfig.SendChatGoodsBase; break; case 1: @@ -90,7 +91,7 @@ public class ChatController : ControllerBase case 2: isSend = true; code = nameof(GameChatEnum.Code.Group); - par=""; + par = ""; break; case 3: isSend = true; @@ -102,8 +103,8 @@ public class ChatController : ControllerBase goodsId = GameConfig.SendChatGoodsService; code = nameof(GameChatEnum.Code.Dress); break; - } + if (isSend == false) { return PoAction.Message("无法发言!"); @@ -119,19 +120,19 @@ public class ChatController : ControllerBase } string sign = StringAssist.NoHTML(pars.sign); - bool result = await _chatService.SendChat(userId, areaId, code, sign, par); - if (result) - { - if (goodsId != 0)//扣除道具 - { - await _goodsService.UpdateUserGoods(userId, 0, goodsId, 1, "发言"); - } + bool result = await _chatService.SendChat(userId, areaId, code, sign, par); + if (result) + { + if (goodsId != 0) //扣除道具 + { + await _goodsService.UpdateUserGoods(userId, 0, goodsId, 1, "发言"); + } - return PoAction.Ok(true); - } - else - { - return PoAction.Message("发送失败,请稍后尝试!"); - } + return PoAction.Ok(true); + } + else + { + return PoAction.Message("发送失败,请稍后尝试!"); + } } } \ No newline at end of file diff --git a/Service/Application.Web/Controllers/Map/MapController.cs b/Service/Application.Web/Controllers/Map/MapController.cs index f08690e..d0d4e26 100644 --- a/Service/Application.Web/Controllers/Map/MapController.cs +++ b/Service/Application.Web/Controllers/Map/MapController.cs @@ -18,7 +18,7 @@ public class MapController : ControllerBase private readonly IMessageService _messageService; public MapController(IUnitUserService userService, IGameMapService mapService, IGameChatService chatService, - IUnitUserAttrService attrService,IMessageService messageService) + IUnitUserAttrService attrService, IMessageService messageService) { _userService = userService; _mapService = mapService; @@ -69,7 +69,7 @@ public class MapController : ControllerBase //公聊信息 string teamId = ""; string groupId = ""; - var chatData = await _chatService.GetChatTop(area, 2, teamId, groupId); + var chatData = await _chatService.GetChatTop(userId, area, 2, teamId, groupId); var npcData = await _mapService.GetMapNpc(mapInfo.mapId); //NPC信息 @@ -81,7 +81,8 @@ public class MapController : ControllerBase var cityInfo = await _mapService.GetCityInfo((int)mapInfo.cityId); //城市信息 var cityShow = await _mapService.GetCityShowMap(cityInfo.cityId); //城内地图 - int noReadMsg = await _messageService.GetNoReadCount(userId); + var noReadMsg = await _messageService.GetNoReadCount(userId); + #region 更新在线 string ip = ComHelper.GetClientUserIp(HttpContext); @@ -89,7 +90,7 @@ public class MapController : ControllerBase #endregion - object ret = new { mapInfo, cityInfo, npcData, chatData, cityShow, nearUser,noReadMsg }; + object ret = new { mapInfo, cityInfo, npcData, chatData, cityShow, nearUser, noReadMsg = noReadMsg[3] }; return PoAction.Ok(ret); } @@ -166,7 +167,7 @@ public class MapController : ControllerBase } } - #region npc相关 + #region npc相关 /// /// 获取NPC相关信息 @@ -197,6 +198,5 @@ public class MapController : ControllerBase return PoAction.Ok(data); } - #endregion } \ No newline at end of file diff --git a/Service/Application.Web/Controllers/Pub/MessageController.cs b/Service/Application.Web/Controllers/Pub/MessageController.cs index fa0afb3..06c420a 100644 --- a/Service/Application.Web/Controllers/Pub/MessageController.cs +++ b/Service/Application.Web/Controllers/Pub/MessageController.cs @@ -1,4 +1,5 @@ -using Microsoft.AspNetCore.Mvc; +using System.Reflection; +using Microsoft.AspNetCore.Mvc; namespace Application.Web.Controllers.Pub; @@ -30,19 +31,30 @@ public class MessageController : ControllerBase { string userId = StateHelper.userId; RefAsync total = 0; + List msgCount = await _messageService.GetNoReadCount(userId); if (type == 0) { var data = await _messageService.GetUserMessage(userId, 0, page, 10, total); - return PoAction.Ok(new { data, total = total.Value }); + return PoAction.Ok(new { data, total = total.Value, msgCount }); } else if (type == 1) { var data = await _messageService.GetUserMessage(userId, 1, page, 10, total); - return PoAction.Ok(new { data, total = total.Value }); + return PoAction.Ok(new { data, total = total.Value, msgCount }); + } + else if (type == 2) + { + var data = await _messageService.GetUserEventMessage(userId, page, 10, total); + return PoAction.Ok(new { data, total = total.Value, msgCount }); + } + else if (type == 3) + { + var data = await _messageService.GetUserMailData(userId, page, 10, total); + return PoAction.Ok(new { data, total = total.Value, msgCount }); } else { - return PoAction.Ok(new { data = new List(), total = total.Value }); + return PoAction.Ok(new { data = new List(), total = total.Value, msgCount }); } } @@ -193,4 +205,134 @@ public class MessageController : ControllerBase return PoAction.Message("删除失败,请稍后尝试!"); } } + + /// + /// 获取邮件详情 + /// + /// + /// + [HttpGet] + public async Task GetMailInfo(string no) + { + string userId = StateHelper.userId; + var data = await _messageService.GetMailInfo(no); + if (data == null) + { + return PoAction.Message("邮件不存在!"); + } + + if (data.userId != userId) + { + return PoAction.Message("邮件不存在!"); + } + + if (data.endTime < TimeExtend.GetTimeStampSeconds) + { + return PoAction.Message("邮件已过期!"); + } + + if (data.isRead == 0) + { + data.isRead = 1; + await _messageService.UpdateMaillInfo(data); + } + + return PoAction.Ok(data); + } + + /// + /// 领取附件 + /// + /// + /// + [HttpGet] + public async Task GetAward(string no) + { + string userId = StateHelper.userId; + var data = await _messageService.GetMailInfo(no); + if (data == null) + { + return PoAction.Message("邮件不存在!"); + } + + if (data.userId != userId) + { + return PoAction.Message("邮件不存在!"); + } + + if (data.endTime < TimeExtend.GetTimeStampSeconds) + { + return PoAction.Message("邮件已过期!"); + } + + if (data.isGet == 1) + { + return PoAction.Message("邮件附件已领取!"); + } + + data.isGet = 1; + data.isRead = 1; + if (await _messageService.UpdateMaillInfo(data)) + { + await GameBus.UpdateBag(userId, 1, data.award, $"邮件领取:{data.name}"); + return PoAction.Ok(true); + } + else + { + return PoAction.Message("领取失败,请稍后尝试!"); + } + } + + /// + /// 处理事件消息 + /// + /// + /// + /// + [HttpGet] + public async Task EventHandle(string eventId, int state) + { + string userId = StateHelper.userId; + var eventInfo = await _messageService.GetEventMessageInfo(eventId); + if (eventInfo == null) + { + return PoAction.Message("通知消息不存在!"); + } + + if (eventInfo.userId != userId) + { + return PoAction.Message("通知消息不存在!"); + } + + if (eventInfo.state != 0) + { + return PoAction.Message("消息已处理!"); + } + + if (eventInfo.btns.All(it => it.status != state)) + { + return PoAction.Message("无法进行当前处理,请重试!"); + } + + eventInfo.state = state; + if (await _messageService.UpdateEventData(eventInfo)) + { + MessageHandle handle = new MessageHandle(); + var result = await handle.HandleMsg(eventInfo, state); + if (result.success) + { + return PoAction.Ok(true, result.msg); + } + else + { + eventInfo.state = 0; + await _messageService.UpdateEventData(eventInfo); + return PoAction.Message(result.msg); + } + } + else + { + return PoAction.Message("处理失败,请稍后尝试!"); + } + } } \ No newline at end of file diff --git a/Service/Application.Web/Controllers/User/RelationController.cs b/Service/Application.Web/Controllers/User/RelationController.cs new file mode 100644 index 0000000..e8fa7d0 --- /dev/null +++ b/Service/Application.Web/Controllers/User/RelationController.cs @@ -0,0 +1,117 @@ +using Microsoft.AspNetCore.Mvc; + +namespace Application.Web.Controllers.User; + +/// +/// 关系接口 +/// +[ApiExplorerSettings(GroupName = "User")] +[Route("User/[controller]/[action]")] +[ApiController] +[Authorize] +public class RelationController : ControllerBase +{ + private readonly IUnitUserRelationService _relationService; + private readonly IUnitUserService _userService; + private readonly IMessageService _messageService; + + public RelationController(IUnitUserRelationService relationService, IUnitUserService userService, + IMessageService messageService) + { + _relationService = relationService; + _userService = userService; + _messageService = messageService; + } + + /// + /// 关系列表数据 + /// + /// + /// + /// + [HttpGet] + public async Task GetRelation(int type, int page) + { + string userId = StateHelper.userId; + RefAsync total = 0; + List result = new List(); + if (type == 0) + { + var data = await _relationService.GetUserFriend(userId); + total = data.Count; + data = data.OrderByDescending(it => it.isOnline).ThenByDescending(it => it.sort).ToList(); + result = PageExtend.GetPageList(data, page, 10); + } + else if (type == 1) + { + var data = await _relationService.GetUserFriend(userId); + data = data.FindAll(it => it.near >= 1000); + total = data.Count; + data = data.OrderByDescending(it => it.isOnline).ThenByDescending(it => it.near) + .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) }); + } + + [HttpGet] + public async Task FriendHandle(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 IsFriend = await _relationService.CheckIsFriend(userId, userInfo.userId); + if (IsFriend == false) + { + string token = $"{nameof(MessageEnum.EventCode.Friend)}_{userId}_{userInfo.userId}"; + if (await _messageService.CheckAtEventMsg(token)) + { + return PoAction.Message("已发送过交友消息,等待对方通过!"); + } + + var myInfo = await _userService.GetUserInfoByUserId(userId); + string sign = $"{UbbTool.HomeUbb(myInfo.userNo, myInfo.nick)} 希望添加您为好友?"; + List btns = new List() + { + new MsgEventBtn() { status = 1, name = "通过", tips = "已通过申请" }, + new MsgEventBtn() { status = 2, name = "拒绝", tips = "已拒绝申请" } + }; + if (await _messageService.SendEventMsg(userInfo.userId, nameof(MessageEnum.EventCode.Friend), "交友消息通知", + sign, userId, token, btns, 3)) + { + return PoAction.Ok(true, "好友申请已发送,请等待对方确认!"); + } + else + { + return PoAction.Message("添加失败,请稍后尝试!"); + } + } + else //删除好友 + { + bool result = await _relationService.DeleteFriend(userId, userInfo.userId); + if (result) + { + return PoAction.Ok(true, "删除好友成功!"); + } + else + { + return PoAction.Message("删除失败,请稍后尝试."); + } + } + } +} \ No newline at end of file diff --git a/Service/Application.Web/Controllers/User/UserController.cs b/Service/Application.Web/Controllers/User/UserController.cs index a621d1b..ae4723c 100644 --- a/Service/Application.Web/Controllers/User/UserController.cs +++ b/Service/Application.Web/Controllers/User/UserController.cs @@ -12,16 +12,19 @@ public class UserController : ControllerBase private readonly IUnitUserAttrService _attrService; private readonly IUnitUserAccService _accService; private readonly IGameMapService _mapService; + private readonly IUnitUserRelationService _relationService; public UserController(IUnitUserService userService, IUnitUserAttrService attrService, - IUnitUserAccService accService, IGameMapService mapService) + IUnitUserAccService accService, IGameMapService mapService,IUnitUserRelationService relationService) { _userService = userService; _attrService = attrService; _accService = accService; _mapService = mapService; + _relationService = relationService; } + /// /// 获取个人资料信息 @@ -44,6 +47,33 @@ public class UserController : ControllerBase return PoAction.Ok(result); } + /// + /// 获取基础资料信息 + /// + /// + /// + [HttpGet] + public async Task GetUserBaseInfo(string no) + { + string userId = StateHelper.userId; + 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); + } + + var model = await UserModelTool.GetUserView(userInfo.userId); + return PoAction.Ok(model); + } /// /// 获取用户资料 /// @@ -81,8 +111,8 @@ public class UserController : ControllerBase var onMapInfo = await _mapService.GetMapInfo(online.mapId); var onCity = await _mapService.GetCityInfo((int)onMapInfo.cityId); string onMapName = $"{onCity.cityName}-{onMapInfo.mapName}"; - - object result = new { user, attr = new { attrInfo.lev }, acc, isOnline, onMapName }; + bool isFriend = await _relationService.CheckIsFriend(userId, userInfo.userId); + object result = new { user, attr = new { attrInfo.lev }, acc, isOnline, onMapName ,isFriend}; return PoAction.Ok(result); } } \ No newline at end of file diff --git a/Web/src/app.vue b/Web/src/app.vue index d10a5c9..1308f2e 100644 --- a/Web/src/app.vue +++ b/Web/src/app.vue @@ -15,7 +15,7 @@ const { on, emit } = useEventBus() //连接signlar const ConnectSignlar = (clientId: string) => { - console.log(`客户端:${clientId}`); + console.log(`客户端:${clientId}`); } @@ -48,14 +48,15 @@ onMounted(() => { ConnectSignlar(payload); }) }) + + diff --git a/Web/src/components/Business/GameChat.vue b/Web/src/components/Business/GameChat.vue index 6b85a50..9607f75 100644 --- a/Web/src/components/Business/GameChat.vue +++ b/Web/src/components/Business/GameChat.vue @@ -3,9 +3,13 @@
[{{ GetChatType(item.chat.code) }}] - : - - {{ item.chat.sign }} + + 海精灵: + + + : + + ({{ TimeExtend.StrToFormat(item.chat.addTime, "dd日HH:mm") }}) diff --git a/Web/src/components/Business/GameUser.vue b/Web/src/components/Business/GameUser.vue index dec3b93..4205d0a 100644 --- a/Web/src/components/Business/GameUser.vue +++ b/Web/src/components/Business/GameUser.vue @@ -1,5 +1,8 @@ \ No newline at end of file diff --git a/Web/src/pages/friend/search.vue b/Web/src/pages/friend/search.vue new file mode 100644 index 0000000..2ffcda7 --- /dev/null +++ b/Web/src/pages/friend/search.vue @@ -0,0 +1,50 @@ + + \ No newline at end of file diff --git a/Web/src/pages/message/index.vue b/Web/src/pages/message/index.vue index ee1d4c1..7eaafca 100644 --- a/Web/src/pages/message/index.vue +++ b/Web/src/pages/message/index.vue @@ -3,12 +3,18 @@ ❀游戏消息❀
- 未读| - 已读| - 通知| + 未读 + ({{ countInfo[0] }}) + | + 已读 + | + 通知 + ({{ countInfo[1] }}) + | 邮件 + ({{ countInfo[2] }})
-
+
{{ PageExtend.GetPageIndex(currentPage, 10, index + 1) }}. @@ -17,6 +23,42 @@
暂无消息.
+
+
+
+ {{ PageExtend.GetPageIndex(currentPage, 10, index + 1) }}. + {{ item.name }} + (未处理) +
+
+ ⏰{{ TimeExtend.Format(item.addTime, "yyyy-MM-dd HH:mm:ss") }} +
+
+
+ + {{ btn.name }} + + +
+
+ ◈{{ + EventTips(item.btns, item.state) }} +
+ +
+ 暂无通知. +
+
+
+ {{ PageExtend.GetPageIndex(currentPage, 10, index + 1) }}. + + {{ item.name }} + (未读) + (未领取) +
+ 暂无邮件. +
+ \ No newline at end of file diff --git a/Web/src/pages/message/mail.vue b/Web/src/pages/message/mail.vue new file mode 100644 index 0000000..58a25db --- /dev/null +++ b/Web/src/pages/message/mail.vue @@ -0,0 +1,77 @@ + + \ No newline at end of file diff --git a/Web/src/pages/message/read.vue b/Web/src/pages/message/read.vue index 7d38b4c..ea9396a 100644 --- a/Web/src/pages/message/read.vue +++ b/Web/src/pages/message/read.vue @@ -68,8 +68,7 @@ const BindData = async (): Promise => { if (result.code == 0) { data.value = result.data.data; user.value = result.data.user; - logs.value = result.data.logs; - console.log(result); + logs.value = result.data.logs; } else { MessageExtend.ShowDialogEvent("提示", result.msg, () => { diff --git a/Web/src/pages/user/user.vue b/Web/src/pages/user/user.vue index 08d8a51..57c62f4 100644 --- a/Web/src/pages/user/user.vue +++ b/Web/src/pages/user/user.vue @@ -2,7 +2,7 @@
私聊. 送礼物. 逗一下
拜师. 山寨. 送道具
- 加好友. 加仇人 + {{ isFriend ? "删除好友" : "加好友" }}. 加仇人
@@ -51,6 +51,7 @@ const attrData = ref({}); const accData = ref({}); const online = ref(0); const onMap = ref(''); +const isFriend = ref(false); onMounted(async () => { try { @@ -72,14 +73,15 @@ const BindData = async (): Promise => { accData.value = result.data.acc; online.value = result.data.isOnline; onMap.value = result.data.onMapName; + isFriend.value = result.data.isFriend; console.log(result); } else if (result.code == 101) { - return PageExtend.Redirect("/user"); + return PageExtend.RedirectTo("/user"); } else if (result.code == 102) { MessageExtend.ShowDialogEvent("提示", "玩家不存在!", () => { - return PageExtend.Redirect("/user"); + return PageExtend.RedirectTo("/user"); }, "确认"); } else { @@ -87,4 +89,20 @@ const BindData = async (): Promise => { } }; +const FriendHandle = async (): Promise => { + MessageExtend.ShowConfirmDialogAsyc("好友操作", `您确定要${isFriend.value ? "删除" : "添加"}好友吗?`, async () => { + let no = PageExtend.QueryString("no"); + let result = await RelationService.FriendHandle(no); + if (result.code == 0) { + await BindData(); + MessageExtend.Notify(result.msg, "success"); + } + else { + MessageExtend.Notify(result.msg, "danger"); + } + + return true; + }); +} + \ No newline at end of file diff --git a/Web/src/services/Index/MessageService.ts b/Web/src/services/Index/MessageService.ts index 7f0ab7d..2a3b63b 100644 --- a/Web/src/services/Index/MessageService.ts +++ b/Web/src/services/Index/MessageService.ts @@ -40,4 +40,28 @@ export class MessageService { static async DeleteMsg(no: number) { return await ApiService.Request("get", "/Message/DeleteMsg", { no }); } + + /** + * 获取邮件详情 + * GET /Message/GetMailInfo + */ + static async GetMailInfo(no: string) { + return await ApiService.Request("get", "/Message/GetMailInfo", { no }); + } + + /** + * 领取附件 + * GET /Message/GetAward + */ + static async GetAward(no: string) { + return await ApiService.Request("get", "/Message/GetAward", { no }); + } + + /** + * 处理事件消息 + * GET /Message/EventHandle + */ + static async EventHandle(eventId: string, state: number) { + return await ApiService.Request("get", "/Message/EventHandle", { eventId, state }); + } } \ No newline at end of file diff --git a/Web/src/services/user/RelationService.ts b/Web/src/services/user/RelationService.ts new file mode 100644 index 0000000..060bb4b --- /dev/null +++ b/Web/src/services/user/RelationService.ts @@ -0,0 +1,17 @@ +export class RelationService { + /** + * 关系列表数据 + * GET /User/Relation/GetRelation + */ + static async GetRelation(type: number, page: number) { + return await ApiService.Request("get", "/User/Relation/GetRelation", { type, page }); + } + + /** + * FriendHandle + * GET /User/Relation/FriendHandle + */ + static async FriendHandle(no: string) { + return await ApiService.Request("get", "/User/Relation/FriendHandle", { no }); + } +} \ No newline at end of file diff --git a/Web/src/services/user/UserService.ts b/Web/src/services/user/UserService.ts index 1966732..15c4d73 100644 --- a/Web/src/services/user/UserService.ts +++ b/Web/src/services/user/UserService.ts @@ -7,6 +7,14 @@ export class UserService { return await ApiService.Request("get", "/User/User/GetUserInfo"); } + /** + * 获取基础资料信息 + * GET /User/User/GetUserBaseInfo + */ + static async GetUserBaseInfo(no: string) { + return await ApiService.Request("get", "/User/User/GetUserBaseInfo", { no }); + } + /** * 获取用户资料 * GET /User/User/GetHomeInfo diff --git a/Web/src/utility‌/GameTool.ts b/Web/src/utility‌/GameTool.ts index 29e8d15..314ce84 100644 --- a/Web/src/utility‌/GameTool.ts +++ b/Web/src/utility‌/GameTool.ts @@ -68,7 +68,7 @@ export class GameTool { result = '金贝'; break; case 'copper': - return this.FormatCopper(num); + return this.FormatCopper(num); break; case 'teach': result = '师德'; @@ -80,4 +80,35 @@ export class GameTool { return `${num}${result}`; } + + /**物品连接处理 */ + public static GetPropHtml(data: Array, count: number, type: number): string { + let result = '' + data.forEach(element => { + let num = Number(element.count) * count; + if (type == 0) { + result += `${element.name}+${num}` + } + else { + result += `
▸${this.GetPropUrl(element.code, element.name, element.parameter)}+${num}
`; + } + }); + result = StringExtend.trimEnd(result, ','); + return result; + } + public static GetPropUrl(code: string, name: string, par: string): string { + let result = name; + switch (code) { + case "Equ": + result = `${name}`; + break; + case "Goods": + result = `${name}`; + break; + } + + return result; + } + + } \ No newline at end of file