1111
This commit is contained in:
@@ -10,8 +10,4 @@
|
||||
<ProjectReference Include="..\Application.Service.Pub\Application.Service.Pub.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="game\" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
69
Service/Application.Domain.Entity/game/game/game_chat.cs
Normal file
69
Service/Application.Domain.Entity/game/game/game_chat.cs
Normal file
@@ -0,0 +1,69 @@
|
||||
using SqlSugar;
|
||||
using System;
|
||||
|
||||
namespace Application.Domain.Entity
|
||||
{
|
||||
[Tenant("Kg.SeaTime.Game")]
|
||||
public class game_chat
|
||||
{
|
||||
/// <summary>
|
||||
/// chatId
|
||||
/// </summary>
|
||||
[SugarColumn(IsPrimaryKey = true, Length = 50)]
|
||||
public string chatId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// code
|
||||
/// </summary>
|
||||
[SugarColumn(Length = 50, IsNullable = true)]
|
||||
public string? code { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// areaId
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = true)]
|
||||
public int? areaId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// userId
|
||||
/// </summary>
|
||||
[SugarColumn(Length = 50, IsNullable = true)]
|
||||
public string? userId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// par
|
||||
/// </summary>
|
||||
[SugarColumn(Length = 50, IsNullable = true)]
|
||||
public string? par { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// sign
|
||||
/// </summary>
|
||||
[SugarColumn(Length = 255, IsNullable = true)]
|
||||
public string? sign { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// addTime
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = true)]
|
||||
public DateTime? addTime { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// sort
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = true)]
|
||||
public long? sort { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// delTime
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = true)]
|
||||
public long? delTime { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// state
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = true)]
|
||||
public int? state { get; set; }
|
||||
}
|
||||
}
|
||||
11
Service/Application.Domain.Entity/model/UserModel.cs
Normal file
11
Service/Application.Domain.Entity/model/UserModel.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
namespace Application.Domain.Entity;
|
||||
|
||||
public class UserModel
|
||||
{
|
||||
public string userNo { get; set; }
|
||||
public string nick { get; set; }
|
||||
public string sex { get; set; }
|
||||
public string headImg { get; set; }
|
||||
public int area { get; set; }
|
||||
public string icon { get; set; }
|
||||
}
|
||||
8
Service/Application.Domain.Entity/view/GameChatView.cs
Normal file
8
Service/Application.Domain.Entity/view/GameChatView.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
namespace Application.Domain.Entity;
|
||||
|
||||
public class GameChatView
|
||||
{
|
||||
public game_chat chat { get; set; }
|
||||
public UserModel user { get; set; }
|
||||
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
24
Service/Application.Service.Pub/Extends/TimeExtend.cs
Normal file
24
Service/Application.Service.Pub/Extends/TimeExtend.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
namespace Application.Service.Pub;
|
||||
|
||||
public class TimeExtend
|
||||
{
|
||||
public static long GetTimeStampSeconds
|
||||
{
|
||||
get => Convert.ToInt64((DateTime.Now - new DateTime(1970, 1, 1, 0, 0, 0, 0)).TotalSeconds);
|
||||
}
|
||||
|
||||
public static long GetTimeStampMilliseconds
|
||||
{
|
||||
get => Convert.ToInt64((DateTime.Now - new DateTime(1970, 1, 1, 0, 0, 0, 0)).TotalMilliseconds);
|
||||
}
|
||||
|
||||
public static long GetTimeStampBySeconds(DateTime time)
|
||||
{
|
||||
return Convert.ToInt64((time - new DateTime(1970, 1, 1, 0, 0, 0, 0)).TotalSeconds);
|
||||
}
|
||||
|
||||
public static long GetTimeStampByMilliseconds(DateTime time)
|
||||
{
|
||||
return Convert.ToInt64((time - new DateTime(1970, 1, 1, 0, 0, 0, 0)).TotalMilliseconds);
|
||||
}
|
||||
}
|
||||
117
Service/Application.Web/Controllers/Chat/ChatController.cs
Normal file
117
Service/Application.Web/Controllers/Chat/ChatController.cs
Normal file
@@ -0,0 +1,117 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace Application.Web.Controllers.Chat;
|
||||
|
||||
/// <summary>
|
||||
/// 公聊接口
|
||||
/// </summary>
|
||||
[Route("Chat/[controller]/[action]")]
|
||||
[ApiController]
|
||||
[Authorize]
|
||||
public class ChatController : ControllerBase
|
||||
{
|
||||
private readonly IGameChatService _chatService;
|
||||
|
||||
public ChatController(IGameChatService chatService)
|
||||
{
|
||||
_chatService = chatService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取公聊信息
|
||||
/// </summary>
|
||||
/// <param name="type"></param>
|
||||
/// <param name="page"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public async Task<IPoAction> GetChatData(int type, int page)
|
||||
{
|
||||
int areaId = StateHelper.areaId;
|
||||
string teamId = "";
|
||||
string groupId = "";
|
||||
RefAsync<int> Total = 0;
|
||||
var data = await _chatService.GetChatData(type, areaId, teamId, groupId, page, 10, Total);
|
||||
//物品数量
|
||||
int sendGoodsCount = 0;
|
||||
string sendGoodsName = "";
|
||||
switch (type)
|
||||
{
|
||||
case 0:
|
||||
sendGoodsCount = 199;
|
||||
sendGoodsName = "小海螺";
|
||||
break;
|
||||
case 3:
|
||||
sendGoodsCount = 15;
|
||||
sendGoodsName = "大海螺";
|
||||
break;
|
||||
case 4:
|
||||
sendGoodsCount = 9;
|
||||
sendGoodsName = "金海螺";
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
return PoAction.Ok(new { data, total = Total.Value ,sendGoodsCount,sendGoodsName});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 发言
|
||||
/// </summary>
|
||||
/// <param name="pars"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<IPoAction> SendChat([FromBody] SendChatParms pars)
|
||||
{
|
||||
if (string.IsNullOrEmpty(pars.sign))
|
||||
{
|
||||
return PoAction.Message("发言内容不能为空!");
|
||||
}
|
||||
|
||||
string userId = StateHelper.userId;
|
||||
int areaId = StateHelper.areaId;
|
||||
string par = string.Empty;
|
||||
string code = GameChatEnum.Code.Public.ToString();
|
||||
bool isSend = false;
|
||||
switch (pars.type)
|
||||
{
|
||||
case 0:
|
||||
isSend = true;
|
||||
code =nameof(GameChatEnum.Code.Public);
|
||||
break;
|
||||
case 1:
|
||||
isSend = true;
|
||||
code = nameof(GameChatEnum.Code.Team);
|
||||
par = "";
|
||||
break;
|
||||
case 2:
|
||||
isSend = true;
|
||||
code = nameof(GameChatEnum.Code.Group);
|
||||
par="";
|
||||
break;
|
||||
case 3:
|
||||
isSend = true;
|
||||
code = nameof(GameChatEnum.Code.Region);
|
||||
break;
|
||||
case 4:
|
||||
isSend = true;
|
||||
code = nameof(GameChatEnum.Code.Dress);
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
if (isSend == false)
|
||||
{
|
||||
return PoAction.Message("无法发言!");
|
||||
}
|
||||
string sign = StringAssist.NoHTML(pars.sign);
|
||||
bool result = await _chatService.SendChat(userId, areaId, code, sign, par);
|
||||
if (result)
|
||||
{
|
||||
return PoAction.Ok(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
return PoAction.Message("发送失败,请稍后尝试!");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -13,11 +13,13 @@ public class MapController : ControllerBase
|
||||
{
|
||||
private readonly IUnitUserService _userService;
|
||||
private readonly IGameMapService _mapService;
|
||||
private readonly IGameChatService _chatService;
|
||||
|
||||
public MapController(IUnitUserService userService, IGameMapService mapService)
|
||||
public MapController(IUnitUserService userService, IGameMapService mapService, IGameChatService chatService)
|
||||
{
|
||||
_userService = userService;
|
||||
_mapService = mapService;
|
||||
_chatService = chatService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -29,6 +31,7 @@ public class MapController : ControllerBase
|
||||
public async Task<IPoAction> GetMapData(string? map)
|
||||
{
|
||||
string userId = StateHelper.userId;
|
||||
int area = StateHelper.areaId;
|
||||
var onMap = await _mapService.GetUserOnMap(userId);
|
||||
game_city_map mapInfo = new game_city_map();
|
||||
if (string.IsNullOrEmpty(map))
|
||||
@@ -40,10 +43,14 @@ public class MapController : ControllerBase
|
||||
mapInfo = await _mapService.GetMapInfo(map);
|
||||
}
|
||||
|
||||
//公聊信息
|
||||
string teamId = "";
|
||||
string groupId = "";
|
||||
var chatData = await _chatService.GetChatTop(area, 2, teamId, groupId);
|
||||
//NPC信息
|
||||
|
||||
|
||||
var npcData = await _mapService.GetMapNpc(mapInfo.mapId);
|
||||
npcData = npcData.FindAll(it => GameTool.AreaVerify(StateHelper.areaId,it.areaId));
|
||||
npcData = npcData.FindAll(it => GameTool.AreaVerify(StateHelper.areaId, it.areaId));
|
||||
//城市信息
|
||||
var cityInfo = await _mapService.GetCityInfo((int)mapInfo.cityId);
|
||||
|
||||
@@ -54,7 +61,7 @@ public class MapController : ControllerBase
|
||||
|
||||
#endregion
|
||||
|
||||
object ret = new { mapInfo, cityInfo, npcData };
|
||||
object ret = new { mapInfo, cityInfo, npcData, chatData };
|
||||
|
||||
return PoAction.Ok(ret);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace Application.Web;
|
||||
|
||||
public class SendChatParms
|
||||
{
|
||||
public int type { get; set; }
|
||||
public string sign { get; set; }
|
||||
}
|
||||
Reference in New Issue
Block a user