1111
This commit is contained in:
14
Service/Application.Domain/Enum/GameChatEnum.cs
Normal file
14
Service/Application.Domain/Enum/GameChatEnum.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
namespace Application.Domain;
|
||||
|
||||
public class GameChatEnum
|
||||
{
|
||||
public enum Code
|
||||
{
|
||||
Public,//公共
|
||||
Group,//帮派
|
||||
Team,//队伍
|
||||
Region,//全区
|
||||
Dress,//全服
|
||||
System//系统
|
||||
}
|
||||
}
|
||||
@@ -2,4 +2,5 @@
|
||||
global using SqlSugar;
|
||||
global using Application.Domain.Entity;
|
||||
global using Photon.Core.Redis;
|
||||
global using Photon.Core.Assist;
|
||||
global using Photon.Core.Assist;
|
||||
global using Application.Service.Pub;
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
namespace Application.Domain;
|
||||
|
||||
public interface IGameChatService
|
||||
{
|
||||
Task<List<GameChatView>> GetChatTop(int areaId, int top, string teamId, string groupId);
|
||||
|
||||
Task<List<GameChatView>> GetChatData(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> DeleteChat(string chatId);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,153 @@
|
||||
namespace Application.Domain;
|
||||
|
||||
public class GameChatService : IGameChatService, ITransient
|
||||
{
|
||||
private readonly ISqlSugarClient _dbClient;
|
||||
private readonly IRedisCache _redisClient;
|
||||
|
||||
public GameChatService(ISqlSugarClient dbClient, IRedisCache redisClient)
|
||||
{
|
||||
_dbClient = dbClient;
|
||||
_redisClient = redisClient;
|
||||
}
|
||||
|
||||
public async Task<List<GameChatView>> GetChatTop(int areaId, int top, string teamId, string groupId)
|
||||
{
|
||||
var db = _dbClient.AsTenant().GetConnectionWithAttr<game_chat>();
|
||||
List<string> allCode = new List<string>() { "Public", "Region", "System" };
|
||||
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")
|
||||
)
|
||||
).Take(top).OrderByDescending(it => it.sort).ToListAsync();
|
||||
|
||||
var result = new List<GameChatView>();
|
||||
foreach (var item in data)
|
||||
{
|
||||
var userModel = await UserModelTool.GetUserView(item.userId, true);
|
||||
result.Add(new GameChatView() { chat = item, user = userModel });
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public async Task<List<GameChatView>> GetChatData(int type, int areaId, string teamId, string groupId, int page,
|
||||
int limit,
|
||||
RefAsync<int> total)
|
||||
{
|
||||
List<game_chat> data = new List<game_chat>();
|
||||
var db = _dbClient.AsTenant().GetConnectionWithAttr<game_chat>();
|
||||
if (type == 0)
|
||||
{
|
||||
List<string> allCode = new List<string>() { "Public", "Region", "System" };
|
||||
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")
|
||||
)
|
||||
).OrderByDescending(it => it.sort).ToPageListAsync(page, limit, total);
|
||||
}
|
||||
else if (type == 1) //队伍
|
||||
{
|
||||
data = await db.Queryable<game_chat>().Where(it => it.state == 1 && it.code == "Team" && it.par == teamId
|
||||
).OrderByDescending(it => it.sort).ToPageListAsync(page, limit, total);
|
||||
}
|
||||
else if (type == 2) //帮派
|
||||
{
|
||||
data = await db.Queryable<game_chat>().Where(it => it.state == 1 && it.code == "Group" && it.par == groupId
|
||||
).OrderByDescending(it => it.sort).ToPageListAsync(page, limit, total);
|
||||
}
|
||||
else if (type == 3) //全区
|
||||
{
|
||||
data = await db.Queryable<game_chat>()
|
||||
.Where(it => it.state == 1 && it.code == "Region" && it.areaId == areaId
|
||||
).OrderByDescending(it => it.sort).ToPageListAsync(page, limit, total);
|
||||
}
|
||||
else if (type == 4) //全服
|
||||
{
|
||||
data = await db.Queryable<game_chat>().Where(it => it.state == 1 && it.code == "Dress"
|
||||
).OrderByDescending(it => it.sort).ToPageListAsync(page, limit, total);
|
||||
}
|
||||
else if (type == 5) //系统
|
||||
{
|
||||
data = await db.Queryable<game_chat>()
|
||||
.Where(it => it.state == 1 && it.code == "System" && it.areaId == areaId
|
||||
).OrderByDescending(it => it.sort).ToPageListAsync(page, limit, total);
|
||||
}
|
||||
else
|
||||
{
|
||||
data = new List<game_chat>();
|
||||
}
|
||||
var result = new List<GameChatView>();
|
||||
foreach (var item in data)
|
||||
{
|
||||
var userModel = await UserModelTool.GetUserView(item.userId, true);
|
||||
result.Add(new GameChatView() { chat = item, user = userModel });
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加聊天
|
||||
/// </summary>
|
||||
/// <param name="userId"></param>
|
||||
/// <param name="areaId"></param>
|
||||
/// <param name="code"></param>
|
||||
/// <param name="sign"></param>
|
||||
/// <param name="par"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<bool> SendChat(string userId, int areaId, string code, string sign, string par = "")
|
||||
{
|
||||
game_chat chat = new game_chat();
|
||||
chat.chatId = StringAssist.NewGuid;
|
||||
chat.userId = userId;
|
||||
chat.areaId = areaId;
|
||||
chat.code = code;
|
||||
chat.par = par;
|
||||
chat.sign = sign;
|
||||
chat.state = 1;
|
||||
chat.addTime = DateTime.Now;
|
||||
chat.sort = TimeExtend.GetTimeStampSeconds;
|
||||
chat.delTime = TimeExtend.GetTimeStampBySeconds(DateTime.Now.AddDays(3));
|
||||
switch (code)
|
||||
{
|
||||
case "Region":
|
||||
chat.sort += 300; //五分钟
|
||||
break;
|
||||
|
||||
case "Dress":
|
||||
chat.sort += 600; //10分钟
|
||||
break;
|
||||
case "System":
|
||||
chat.delTime = TimeExtend.GetTimeStampBySeconds(DateTime.Now.AddHours(6));
|
||||
break;
|
||||
case "Group":
|
||||
chat.delTime = TimeExtend.GetTimeStampBySeconds(DateTime.Now.AddHours(6));
|
||||
break;
|
||||
case "Team":
|
||||
chat.delTime = TimeExtend.GetTimeStampBySeconds(DateTime.Now.AddHours(6));
|
||||
break;
|
||||
}
|
||||
|
||||
var db = _dbClient.AsTenant().GetConnectionWithAttr<game_chat>();
|
||||
return await db.Insertable(chat).ExecuteCommandAsync() > 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除聊天
|
||||
/// </summary>
|
||||
/// <param name="chatId"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<bool> DeleteChat(string chatId)
|
||||
{
|
||||
var db = _dbClient.AsTenant().GetConnectionWithAttr<game_chat>();
|
||||
return await db.Updateable<game_chat>().SetColumns(it => it.state == 0).Where(it => it.chatId == chatId)
|
||||
.ExecuteCommandAsync() > 0;
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
using Photon.Core.Assist;
|
||||
|
||||
|
||||
namespace Application.Domain;
|
||||
|
||||
public class GameTool
|
||||
@@ -38,4 +37,5 @@ public class GameTool
|
||||
List<string> onArea = new List<string>() {"0",area.ToString() };
|
||||
return onArea.Any(it => areas.Contains(it));
|
||||
}
|
||||
|
||||
}
|
||||
32
Service/Application.Domain/Tool/ModelTool/UserModelTool.cs
Normal file
32
Service/Application.Domain/Tool/ModelTool/UserModelTool.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
namespace Application.Domain;
|
||||
|
||||
public class UserModelTool
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取用户模型
|
||||
/// </summary>
|
||||
/// <param name="userId"></param>
|
||||
/// <param name="addIcon"></param>
|
||||
/// <returns></returns>
|
||||
public static async Task<UserModel> GetUserView(string userId,bool addIcon=false)
|
||||
{
|
||||
UserModel result = new UserModel();
|
||||
var userService = App.GetService<IUnitUserService>();
|
||||
var userInfo = await userService.GetUserInfoByUserId(userId);
|
||||
if (userInfo != null)
|
||||
{
|
||||
result.userNo = userInfo.userNo;
|
||||
result.nick = userInfo.nick;
|
||||
result.sex = userInfo.sex;
|
||||
result.headImg = userInfo.headImg;
|
||||
result.area = (int)userInfo.areaId;
|
||||
result.icon = "";
|
||||
if (addIcon)//获取图标信息
|
||||
{
|
||||
result.icon = "";
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user