From e4d39f3f2fe737745649fcdb8cac1bb3d0f5841c Mon Sep 17 00:00:00 2001 From: Putoo <290555932@qq.com> Date: Fri, 17 Jul 2026 18:12:08 +0800 Subject: [PATCH] 121212 --- .../game/user/unit_user_escort.cs | 45 ++++++++ .../resource/game/game_escort.cs | 33 ++++++ Service/Application.Domain/Enum/GameEnum.cs | 1 + .../Interface/Business/IGameEscortService.cs | 11 ++ .../Service/Business/GameEscortService.cs | 101 ++++++++++++++++++ .../Services/Service/Task/GameTaskService.cs | 10 +- .../Application.Domain/Tool/Base/GameTool.cs | 1 + .../Extends/TimeExtend.cs | 28 ++++- .../Controllers/Pub/ExchangeController.cs | 19 +--- 9 files changed, 223 insertions(+), 26 deletions(-) create mode 100644 Service/Application.Domain.Entity/game/user/unit_user_escort.cs create mode 100644 Service/Application.Domain.Entity/resource/game/game_escort.cs create mode 100644 Service/Application.Domain/Services/Interface/Business/IGameEscortService.cs create mode 100644 Service/Application.Domain/Services/Service/Business/GameEscortService.cs diff --git a/Service/Application.Domain.Entity/game/user/unit_user_escort.cs b/Service/Application.Domain.Entity/game/user/unit_user_escort.cs new file mode 100644 index 0000000..435da9e --- /dev/null +++ b/Service/Application.Domain.Entity/game/user/unit_user_escort.cs @@ -0,0 +1,45 @@ +using SqlSugar; +using System; + +namespace Application.Domain.Entity +{ + [Tenant("Kg.SeaTime.Game")] + public class unit_user_escort + { + /// + /// userId + /// + [SugarColumn(IsPrimaryKey = true, Length = 50)] + public string userId { get; set; } + + /// + /// esId + /// + [SugarColumn(IsNullable = true)] + public int? esId { get; set; } + + /// + /// name + /// + [SugarColumn(Length = 50, IsNullable = true)] + public string? name { get; set; } + + /// + /// IsUse + /// + [SugarColumn(IsNullable = true)] + public int? isUse { get; set; } + + /// + /// state + /// + [SugarColumn(IsNullable = true)] + public int? state { get; set; } + + /// + /// endTime + /// + [SugarColumn(IsNullable = true)] + public long? endTime { get; set; } + } +} \ No newline at end of file diff --git a/Service/Application.Domain.Entity/resource/game/game_escort.cs b/Service/Application.Domain.Entity/resource/game/game_escort.cs new file mode 100644 index 0000000..8052c24 --- /dev/null +++ b/Service/Application.Domain.Entity/resource/game/game_escort.cs @@ -0,0 +1,33 @@ +using SqlSugar; +using System; + +namespace Application.Domain.Entity +{ + [Tenant("Kg.SeaTime.Resource")] + public class game_escort + { + /// + /// esId + /// + [SugarColumn(IsPrimaryKey = true)] + public int esId { get; set; } + + /// + /// random + /// + [SugarColumn(IsNullable = true)] + public int? random { get; set; } + + /// + /// name + /// + [SugarColumn(Length = 255, IsNullable = true)] + public string? name { get; set; } + + /// + /// award + /// + [SugarColumn(IsNullable = true)] + public string? award { get; set; } + } +} \ No newline at end of file diff --git a/Service/Application.Domain/Enum/GameEnum.cs b/Service/Application.Domain/Enum/GameEnum.cs index 33562fe..3208b5f 100644 --- a/Service/Application.Domain/Enum/GameEnum.cs +++ b/Service/Application.Domain/Enum/GameEnum.cs @@ -7,6 +7,7 @@ public static class GameEnum single,//1次 alway,//永久 } + public enum JobCode { OnHook,//定时任务 diff --git a/Service/Application.Domain/Services/Interface/Business/IGameEscortService.cs b/Service/Application.Domain/Services/Interface/Business/IGameEscortService.cs new file mode 100644 index 0000000..f41e95f --- /dev/null +++ b/Service/Application.Domain/Services/Interface/Business/IGameEscortService.cs @@ -0,0 +1,11 @@ +namespace Application.Domain; + +public interface IGameEscortService +{ + Task> GetEscortData(); + Task GetEscortInfo(int esId); + Task GetUserEscort(string userId); + Task ClearUserEscort(string userId); + Task UpdateUserEscort(string userId, int esId, string name); + Task UpdateUserEscort(unit_user_escort data); +} \ No newline at end of file diff --git a/Service/Application.Domain/Services/Service/Business/GameEscortService.cs b/Service/Application.Domain/Services/Service/Business/GameEscortService.cs new file mode 100644 index 0000000..6455270 --- /dev/null +++ b/Service/Application.Domain/Services/Service/Business/GameEscortService.cs @@ -0,0 +1,101 @@ +namespace Application.Domain; + +public class GameEscortService(ISqlSugarClient DbClient, IRedisCache redis) : IGameEscortService, ITransient +{ + public async Task> GetEscortData() + { + string key = string.Format(BaseCache.BaseCacheKeys, "Escort", "Data"); + if (await redis.ExistsAsync(key)) + { + return await redis.GetAsync>(key); + } + + var db = DbClient.AsTenant().GetConnectionWithAttr(); + var data = await db.Queryable().ToListAsync(); + await redis.SetAsync(key, data); + return data; + } + + public async Task GetEscortInfo(int esId) + { + string key = string.Format(BaseCache.BaseCacheKeys, "Escort", "Info"); + if (await redis.HExistsHashAsync(key, esId.ToString())) + { + return await redis.GetHashAsync(key, esId.ToString()); + } + + var db = DbClient.AsTenant().GetConnectionWithAttr(); + var data = await db.Queryable().Where(it => it.esId == esId).SingleAsync(); + await redis.AddHashAsync(key, esId.ToString(), data); + return data; + } + + public async Task GetUserEscort(string userId) + { + string key = string.Format(UserCache.BaseCacheKey, "UserEscort"); + if (await redis.HExistsHashAsync(key, userId)) + { + return await redis.GetHashAsync(key, userId); + } + + var db = DbClient.AsTenant().GetConnectionWithAttr(); + var data = await db.Queryable().Where(it => it.userId == userId).SingleAsync(); + if (data == null) + { + data = new unit_user_escort() + { + userId = userId, + esId = 0, + name = "", + state = 0, + endTime = TimeExtend.GetTimeStampSeconds + }; + await db.Insertable(data).ExecuteCommandAsync(); + } + + await redis.AddHashAsync(key, userId, data); + return data; + } + + public async Task ClearUserEscort(string userId) + { + unit_user_escort data = new unit_user_escort() + { + userId = userId, + esId = 0, + name = "", + isUse = 0, + state = 0, + endTime = TimeExtend.GetTimeStampSeconds + }; + return await UpdateUserEscort(data); + } + + public async Task UpdateUserEscort(string userId, int esId, string name) + { + long time = TimeExtend.GetTimeStampSeconds + 300; + unit_user_escort data = data = new unit_user_escort() + { + userId = userId, + esId = esId, + name = name, + state = 1, + isUse = 0, + endTime = time + }; + return await UpdateUserEscort(data); + } + + public async Task UpdateUserEscort(unit_user_escort data) + { + var db = DbClient.AsTenant().GetConnectionWithAttr(); + var result = await db.Insertable(data).ExecuteCommandAsync() > 0; + if (result) + { + string key = string.Format(UserCache.BaseCacheKey, "UserEscort"); + await redis.DelHashAsync(key, data.userId); + } + + return result; + } +} \ No newline at end of file diff --git a/Service/Application.Domain/Services/Service/Task/GameTaskService.cs b/Service/Application.Domain/Services/Service/Task/GameTaskService.cs index 1440a07..687343b 100644 --- a/Service/Application.Domain/Services/Service/Task/GameTaskService.cs +++ b/Service/Application.Domain/Services/Service/Task/GameTaskService.cs @@ -434,16 +434,12 @@ public class GameTaskService(ISqlSugarClient DbClient, IRedisCache redis) : IGam var taskInfo = await GetTaskInfo(taskId); if (taskInfo != null) { - if (taskInfo.time == 0) + result = TimeExtend.GetTimeStampSecondsByCode(taskInfo.timeSpan, DateTime.Now.AddYears(20)); + if (result == 0) { - result += 3650 * 24 * 60 * 60; - } - else - { - result += (int)taskInfo.time * 60; + result = TimeExtend.GetTimeStampBySeconds(DateTime.Now.AddYears(20)); } } - return result; } diff --git a/Service/Application.Domain/Tool/Base/GameTool.cs b/Service/Application.Domain/Tool/Base/GameTool.cs index 42e54f6..4b59553 100644 --- a/Service/Application.Domain/Tool/Base/GameTool.cs +++ b/Service/Application.Domain/Tool/Base/GameTool.cs @@ -4,6 +4,7 @@ namespace Application.Domain; public class GameTool { + /// /// 单位转换 /// diff --git a/Service/Application.Service.Pub/Extends/TimeExtend.cs b/Service/Application.Service.Pub/Extends/TimeExtend.cs index be6027d..fe4f446 100644 --- a/Service/Application.Service.Pub/Extends/TimeExtend.cs +++ b/Service/Application.Service.Pub/Extends/TimeExtend.cs @@ -1,4 +1,6 @@ -namespace Application.Service.Pub; +using Photon.Core.Assist; + +namespace Application.Service.Pub; public class TimeExtend { @@ -21,4 +23,28 @@ public class TimeExtend { return Convert.ToInt64((time - new DateTime(1970, 1, 1, 0, 0, 0, 0)).TotalMilliseconds); } + + public static long GetTimeStampSecondsByCode(string code, DateTime maxTime) + { + long result = 0; + switch (code) + { + case "Long": + result = GetTimeStampBySeconds(maxTime); + break; + case "Day": + result = GetTimeStampBySeconds(TimeAssist.GetDateTimeYMD(1)); + break; + case "Month": + DateTime nt = DateTime.Now.AddMonths(1); + nt = Convert.ToDateTime($"{nt.Year}-{nt.Month}-01"); + result = GetTimeStampBySeconds(nt); + break; + case "Week": + result = GetTimeStampBySeconds(TimeAssist.WeekEndTime); + break; + } + + return result; + } } \ No newline at end of file diff --git a/Service/Application.Web/Controllers/Pub/ExchangeController.cs b/Service/Application.Web/Controllers/Pub/ExchangeController.cs index 0fad800..f5b1850 100644 --- a/Service/Application.Web/Controllers/Pub/ExchangeController.cs +++ b/Service/Application.Web/Controllers/Pub/ExchangeController.cs @@ -127,24 +127,7 @@ public class ExchangeController : ControllerBase { if (await GameBus.UpdateBag(userId, 0, exInfo.needData, "兑换", count)) { - long endTime = 0; - switch (exInfo.exType) - { - case "Long": - endTime = TimeExtend.GetTimeStampBySeconds((DateTime)exInfo.endTime); - break; - case "Day": - endTime = TimeExtend.GetTimeStampBySeconds(TimeAssist.GetDateTimeYMD(1)); - break; - case "Month": - DateTime nt = DateTime.Now.AddMonths(1); - nt = Convert.ToDateTime($"{nt.Year}-{nt.Month}-01"); - endTime = TimeExtend.GetTimeStampBySeconds(nt); - break; - case "Week": - endTime = TimeExtend.GetTimeStampBySeconds(TimeAssist.WeekEndTime); - break; - } + long endTime = TimeExtend.GetTimeStampSecondsByCode(exInfo.exType, (DateTime)exInfo.endTime); if (await _exchangeService.AddUserExchangeLog(userId, exId, count, endTime)) {