1111
This commit is contained in:
11
Service/Application.Domain/Enum/MessageEnum.cs
Normal file
11
Service/Application.Domain/Enum/MessageEnum.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
namespace Application.Domain;
|
||||
|
||||
public static class MessageEnum
|
||||
{
|
||||
public enum EventCode
|
||||
{
|
||||
Friend,//交友消息
|
||||
Marry,//婚姻消息
|
||||
Trade,//交易通知
|
||||
}
|
||||
}
|
||||
55
Service/Application.Domain/Handle/MessageHandle.cs
Normal file
55
Service/Application.Domain/Handle/MessageHandle.cs
Normal file
@@ -0,0 +1,55 @@
|
||||
namespace Application.Domain;
|
||||
|
||||
public class MessageHandle
|
||||
{
|
||||
public async Task<MessageHandleResult> HandleMsg(unit_user_message_event events, int state)
|
||||
{
|
||||
if (events.code == nameof(MessageEnum.EventCode.Friend))
|
||||
{
|
||||
var relationService = App.GetRequiredService<IUnitUserRelationService>();
|
||||
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<IGameChatService>();
|
||||
var userService = App.GetService<IUnitUserService>();
|
||||
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<IGameChatService>();
|
||||
var userService = App.GetService<IUnitUserService>();
|
||||
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; }
|
||||
}
|
||||
@@ -2,12 +2,13 @@
|
||||
|
||||
public interface IGameChatService
|
||||
{
|
||||
Task<List<GameChatView>> GetChatTop(int areaId, int top, string teamId, string groupId);
|
||||
Task<List<GameChatView>> GetChatTop(string userId,int areaId, int top, string teamId, string groupId);
|
||||
|
||||
Task<List<GameChatView>> GetChatData(int type, int areaId, string teamId, string groupId, int page, int limit,
|
||||
Task<List<GameChatView>> GetChatData(string userId, int type, int areaId, string teamId, string groupId, int page,
|
||||
int limit,
|
||||
RefAsync<int> total);
|
||||
|
||||
Task<bool> SendChat(string userId, int areaId, string code, string sign, string par = "");
|
||||
Task<bool> SendChat(string userId, string code, string sign, string par = "");
|
||||
Task<bool> DeleteChat(string chatId);
|
||||
|
||||
}
|
||||
@@ -20,6 +20,7 @@ public interface IGameMapService
|
||||
Task<unit_user_online> GetUserOnMap(string userId);
|
||||
Task UpdateUserOnMap(string userId, string ip, string mapId);
|
||||
Task<bool> UpdateUserOnMap(unit_user_online data, string mapId);
|
||||
Task<UserOnMap> GetUserOnMapInfo(string userId);
|
||||
Task SetUserMapDefult(string userId);
|
||||
Task<game_city_map> GetToMapInfo(string userId, string toMap, bool isUpUserMap = true, bool isChangeCity = false);
|
||||
#endregion
|
||||
|
||||
@@ -2,15 +2,16 @@
|
||||
|
||||
public interface IMessageService
|
||||
{
|
||||
Task<int> GetNoReadCount(string userId);
|
||||
Task<List<int>> GetNoReadCount(string userId);
|
||||
|
||||
#region 私聊消息
|
||||
#region 私聊消息
|
||||
|
||||
string GetTalkId(string userId, string otId);
|
||||
Task<List<unit_user_message>> GetUserNoReadData(string talkId);
|
||||
|
||||
Task<List<unit_user_message>> GetUserMessageData(string talkId, int page, int limit,
|
||||
RefAsync<int> total);
|
||||
|
||||
Task<List<MessageView>> GetUserMessage(string userId, int type, int page, int limit,
|
||||
RefAsync<int> total);
|
||||
|
||||
@@ -19,4 +20,27 @@ public interface IMessageService
|
||||
Task<bool> DeleteMsgByTalkId(string talkId, string userId);
|
||||
|
||||
#endregion
|
||||
|
||||
#region 邮件消息
|
||||
|
||||
Task<List<unit_user_mail>> GetUserMailData(string userId, int page, int limit, RefAsync<int> total);
|
||||
Task<unit_user_mail> GetMailInfo(string mailId);
|
||||
Task<bool> SendMaill(string userId, string name, string sign, List<TowerGet> award, int days = 10);
|
||||
Task<bool> UpdateMaillInfo(unit_user_mail data);
|
||||
|
||||
#endregion
|
||||
|
||||
#region 通知消息
|
||||
|
||||
Task<List<unit_user_message_event>> GetUserEventMessage(string userId, int page, int limit,
|
||||
RefAsync<int> total);
|
||||
|
||||
Task<unit_user_message_event> GetEventMessageInfo(string eventId);
|
||||
Task<bool> UpdateEventData(unit_user_message_event data);
|
||||
Task<bool> CheckAtEventMsg(string token);
|
||||
|
||||
Task<bool> SendEventMsg(string userId, string code, string name, string sign, string pars, string token,
|
||||
List<MsgEventBtn> btns = null, int days = 10);
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -6,7 +6,7 @@ public interface IUnitUserAttrService
|
||||
|
||||
Task<UserAttrModel> GetUserAttrModel(string userId);
|
||||
Task<unit_user_attr> GetUserAttr(string userId);
|
||||
|
||||
Task<int> GetUserLev(string userId);
|
||||
#endregion
|
||||
|
||||
#region 体力操作
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
namespace Application.Domain;
|
||||
|
||||
public interface IUnitUserRelationService
|
||||
{
|
||||
#region 好友关系
|
||||
|
||||
Task<int> GetUserFriendCount(string userId);
|
||||
Task<List<RelationView>> GetUserFriend(string userId);
|
||||
Task<bool> CheckIsFriend(string userId, string toId);
|
||||
Task<bool> AddFriend(string userId, string toId);
|
||||
Task<bool> DeleteFriend(string userId, string toId);
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -11,16 +11,18 @@ public class GameChatService : IGameChatService, ITransient
|
||||
_redisClient = redisClient;
|
||||
}
|
||||
|
||||
public async Task<List<GameChatView>> GetChatTop(int areaId, int top, string teamId, string groupId)
|
||||
public async Task<List<GameChatView>> GetChatTop(string userId, int areaId, int top, string teamId, string groupId)
|
||||
{
|
||||
var db = _dbClient.AsTenant().GetConnectionWithAttr<game_chat>();
|
||||
List<string> allCode = new List<string>() { "Public", "Region", "System" };
|
||||
List<string> allCode = new List<string>() { "Public", "Region" };
|
||||
var data = await db.Queryable<game_chat>().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<List<GameChatView>> GetChatData(int type, int areaId, string teamId, string groupId, int page,
|
||||
public async Task<List<GameChatView>> GetChatData(string userId, int type, int areaId, string teamId,
|
||||
string groupId, int page,
|
||||
int limit,
|
||||
RefAsync<int> total)
|
||||
{
|
||||
@@ -42,13 +45,15 @@ public class GameChatService : IGameChatService, ITransient
|
||||
var db = _dbClient.AsTenant().GetConnectionWithAttr<game_chat>();
|
||||
if (type == 0)
|
||||
{
|
||||
List<string> allCode = new List<string>() { "Public", "Region", "System" };
|
||||
List<string> allCode = new List<string>() { "Public", "Region" };
|
||||
data = await db.Queryable<game_chat>().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<game_chat>()
|
||||
.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<game_chat>();
|
||||
}
|
||||
|
||||
var result = new List<GameChatView>();
|
||||
foreach (var item in data)
|
||||
{
|
||||
@@ -138,6 +146,15 @@ public class GameChatService : IGameChatService, ITransient
|
||||
var db = _dbClient.AsTenant().GetConnectionWithAttr<game_chat>();
|
||||
return await db.Insertable(chat).ExecuteCommandAsync() > 0;
|
||||
}
|
||||
|
||||
public async Task<bool> SendChat(string userId, string code, string sign, string par = "")
|
||||
{
|
||||
var userService = App.GetService<IUnitUserService>();
|
||||
var userInfo = await userService.GetUserInfoByUserId(userId);
|
||||
if (userInfo == null) return false;
|
||||
|
||||
return await SendChat(userId, (int)userInfo.areaId, code, sign, par);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除聊天
|
||||
|
||||
@@ -31,8 +31,7 @@ public class GameMapService(ISqlSugarClient DbClient, IRedisCache redis) : IGame
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public async Task<List<game_city_map>> GetCityMap(int cityId)
|
||||
{
|
||||
@@ -147,6 +146,22 @@ public class GameMapService(ISqlSugarClient DbClient, IRedisCache redis) : IGame
|
||||
return data;
|
||||
}
|
||||
|
||||
public async Task<UserOnMap> 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<List<game_city>> 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<List<game_city_map>> GetAllMaoToData()
|
||||
{
|
||||
string key = string.Format(BaseCache.BaseCacheKeys, "MapPathData", "CityInterCityPortal");
|
||||
@@ -343,7 +360,7 @@ public class GameMapService(ISqlSugarClient DbClient, IRedisCache redis) : IGame
|
||||
}
|
||||
|
||||
List<game_city_map> result = new List<game_city_map>();
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 城市信息
|
||||
/// </summary>
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 传送点信息
|
||||
/// </summary>
|
||||
|
||||
@@ -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<int> GetNoReadCount(string userId)
|
||||
public async Task<List<int>> GetNoReadCount(string userId)
|
||||
{
|
||||
string key = string.Format(UserCache.BaseCacheKeys, "Message", "Count");
|
||||
if (await redis.HExistsHashAsync(key, userId))
|
||||
{
|
||||
return await redis.GetHashAsync<int>(key, userId);
|
||||
}
|
||||
|
||||
int result = 0;
|
||||
List<int> result = new List<int>();
|
||||
//普通消息
|
||||
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<int> GetUserNoReadDataCountByUserId(string userId)
|
||||
private async Task<int> GetUserNoReadMsgCount(string userId)
|
||||
{
|
||||
string key = string.Format(UserCache.BaseCacheKeys, "Message", "MsgCount");
|
||||
if (await redis.HExistsHashAsync(key, userId))
|
||||
{
|
||||
return await redis.GetHashAsync<int>(key, userId);
|
||||
}
|
||||
|
||||
var db = DbClient.AsTenant().GetConnectionScopeWithAttr<unit_user_message>();
|
||||
return await db.Queryable<unit_user_message>()
|
||||
int count = await db.Queryable<unit_user_message>()
|
||||
.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<List<unit_user_message>> 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<int> GetUserNoReadMailCount(string userId)
|
||||
{
|
||||
string key = string.Format(UserCache.BaseCacheKeys, "Message", "MailCount");
|
||||
if (await redis.HExistsHashAsync(key, userId))
|
||||
{
|
||||
return await redis.GetHashAsync<int>(key, userId);
|
||||
}
|
||||
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_mail>();
|
||||
int count = await db.Queryable<unit_user_mail>().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<List<unit_user_mail>> GetUserMailData(string userId, int page, int limit, RefAsync<int> total)
|
||||
{
|
||||
long onTime = TimeExtend.GetTimeStampSeconds;
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_mail>();
|
||||
return await db.Queryable<unit_user_mail>().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<unit_user_mail> GetMailInfo(string mailId)
|
||||
{
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_mail>();
|
||||
return await db.Queryable<unit_user_mail>().Where(it => it.mailId == mailId)
|
||||
.SingleAsync();
|
||||
}
|
||||
|
||||
public async Task<bool> SendMaill(string userId, string name, string sign, List<TowerGet> 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<unit_user_mail>();
|
||||
bool result = await db.Insertable(mail).ExecuteCommandAsync() > 0;
|
||||
if (result)
|
||||
{
|
||||
await ClearMailCountCache(userId);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public async Task<bool> UpdateMaillInfo(unit_user_mail data)
|
||||
{
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_mail>();
|
||||
bool result = await db.Updateable<unit_user_mail>(data).ExecuteCommandAsync() > 0;
|
||||
if (result)
|
||||
{
|
||||
await ClearMailCountCache(data.userId);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 通知消息
|
||||
|
||||
private async Task<int> GetUserNoReadEventMsgCount(string userId)
|
||||
{
|
||||
string key = string.Format(UserCache.BaseCacheKeys, "Message", "EventCount");
|
||||
if (await redis.HExistsHashAsync(key, userId))
|
||||
{
|
||||
return await redis.GetHashAsync<int>(key, userId);
|
||||
}
|
||||
|
||||
var db = DbClient.AsTenant().GetConnectionScopeWithAttr<unit_user_message_event>();
|
||||
int Count = await db.Queryable<unit_user_message_event>().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<List<unit_user_message_event>> GetUserEventMessage(string userId, int page, int limit,
|
||||
RefAsync<int> total)
|
||||
{
|
||||
var db = DbClient.AsTenant().GetConnectionScopeWithAttr<unit_user_message_event>();
|
||||
return await db.Queryable<unit_user_message_event>().Where(it => it.userId == userId)
|
||||
.OrderByDescending(it => it.addTime)
|
||||
.ToPageListAsync(page, limit, total);
|
||||
}
|
||||
|
||||
public async Task<unit_user_message_event> GetEventMessageInfo(string eventId)
|
||||
{
|
||||
var db = DbClient.AsTenant().GetConnectionScopeWithAttr<unit_user_message_event>();
|
||||
return await db.Queryable<unit_user_message_event>().Where(it => it.eventId == eventId)
|
||||
.SingleAsync();
|
||||
}
|
||||
|
||||
public async Task<bool> UpdateEventData(unit_user_message_event data)
|
||||
{
|
||||
var db = DbClient.AsTenant().GetConnectionScopeWithAttr<unit_user_message_event>();
|
||||
var result = await db.Updateable(data).ExecuteCommandAsync() > 0;
|
||||
if (result)
|
||||
{
|
||||
await ClearEventCountCache(data.userId);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public async Task<bool> CheckAtEventMsg(string token)
|
||||
{
|
||||
var db = DbClient.AsTenant().GetConnectionScopeWithAttr<unit_user_message_event>();
|
||||
return await db.Queryable<unit_user_message_event>().Where(it => it.state == 0 && it.token == token).AnyAsync();
|
||||
}
|
||||
|
||||
public async Task<bool> SendEventMsg(string userId, string code, string name, string sign, string pars,string token,
|
||||
List<MsgEventBtn> 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<MsgEventBtn>()
|
||||
{
|
||||
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<unit_user_message_event>();
|
||||
var result = await db.Insertable(data).ExecuteCommandAsync() > 0;
|
||||
if (result)
|
||||
{
|
||||
await ClearEventCountCache(data.userId);
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
@@ -44,6 +44,18 @@ public class UnitUserAttrService(ISqlSugarClient DbClient, IRedisCache redis) :
|
||||
return data;
|
||||
}
|
||||
|
||||
public async Task<int> 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");
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
namespace Application.Domain;
|
||||
|
||||
public class UnitUserRelationService(ISqlSugarClient DbClient, IRedisCache redis) : IUnitUserRelationService, ITransient
|
||||
{
|
||||
#region 好友关系
|
||||
|
||||
public async Task<int> GetUserFriendCount(string userId)
|
||||
{
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_friend>();
|
||||
return await db.Queryable<unit_user_friend>().Where(it => it.frId.Contains(userId)).CountAsync();
|
||||
}
|
||||
|
||||
public async Task<List<RelationView>> GetUserFriend(string userId)
|
||||
{
|
||||
List<RelationView> result = new List<RelationView>();
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_friend>();
|
||||
|
||||
var data = await db.Queryable<unit_user_friend>().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<IGameMapService>();
|
||||
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<bool> CheckIsFriend(string userId, string toId)
|
||||
{
|
||||
string frId = StringAssist.GetSortKey(userId, toId);
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_friend>();
|
||||
return await db.Queryable<unit_user_friend>().Where(it => it.frId == frId).AnyAsync();
|
||||
}
|
||||
|
||||
public async Task<bool> 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<unit_user_friend>();
|
||||
return await db.Insertable(friend).ExecuteCommandAsync() > 0;
|
||||
}
|
||||
|
||||
public async Task<bool> DeleteFriend(string userId, string toId)
|
||||
{
|
||||
string frId = StringAssist.GetSortKey(userId, toId);
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_friend>();
|
||||
return await db.Deleteable<unit_user_friend>().Where(it => it.frId == frId).ExecuteCommandAsync()>0;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -68,5 +68,29 @@ public class GameBus
|
||||
return isok;
|
||||
}
|
||||
|
||||
public static async Task<bool> 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
|
||||
}
|
||||
9
Service/Application.Domain/Tool/Base/UbbTool.cs
Normal file
9
Service/Application.Domain/Tool/Base/UbbTool.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
namespace Application.Domain;
|
||||
|
||||
public class UbbTool
|
||||
{
|
||||
public static string HomeUbb(string no, string name)
|
||||
{
|
||||
return $"<a data-type='go' data-parms='/user/user?no={no}' href='javascript:void'>{name}</a>";
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,7 @@ public class UserModelTool
|
||||
/// <param name="userId"></param>
|
||||
/// <param name="addIcon"></param>
|
||||
/// <returns></returns>
|
||||
public static async Task<UserModel> GetUserView(string userId,bool addIcon=false)
|
||||
public static async Task<UserModel> 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<IUnitUserService>();
|
||||
var attrService = App.GetRequiredService<IUnitUserAttrService>();
|
||||
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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user