121212
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
using SqlSugar;
|
||||
using System;
|
||||
|
||||
namespace Application.Domain.Entity
|
||||
{
|
||||
[Tenant("Kg.SeaTime.Game")]
|
||||
public class unit_user_escort
|
||||
{
|
||||
/// <summary>
|
||||
/// userId
|
||||
/// </summary>
|
||||
[SugarColumn(IsPrimaryKey = true, Length = 50)]
|
||||
public string userId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// esId
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = true)]
|
||||
public int? esId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// name
|
||||
/// </summary>
|
||||
[SugarColumn(Length = 50, IsNullable = true)]
|
||||
public string? name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// IsUse
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = true)]
|
||||
public int? isUse { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// state
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = true)]
|
||||
public int? state { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// endTime
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = true)]
|
||||
public long? endTime { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
using SqlSugar;
|
||||
using System;
|
||||
|
||||
namespace Application.Domain.Entity
|
||||
{
|
||||
[Tenant("Kg.SeaTime.Resource")]
|
||||
public class game_escort
|
||||
{
|
||||
/// <summary>
|
||||
/// esId
|
||||
/// </summary>
|
||||
[SugarColumn(IsPrimaryKey = true)]
|
||||
public int esId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// random
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = true)]
|
||||
public int? random { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// name
|
||||
/// </summary>
|
||||
[SugarColumn(Length = 255, IsNullable = true)]
|
||||
public string? name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// award
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = true)]
|
||||
public string? award { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,7 @@ public static class GameEnum
|
||||
single,//1次
|
||||
alway,//永久
|
||||
}
|
||||
|
||||
public enum JobCode
|
||||
{
|
||||
OnHook,//定时任务
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
namespace Application.Domain;
|
||||
|
||||
public interface IGameEscortService
|
||||
{
|
||||
Task<List<game_escort>> GetEscortData();
|
||||
Task<game_escort> GetEscortInfo(int esId);
|
||||
Task<unit_user_escort> GetUserEscort(string userId);
|
||||
Task<bool> ClearUserEscort(string userId);
|
||||
Task<bool> UpdateUserEscort(string userId, int esId, string name);
|
||||
Task<bool> UpdateUserEscort(unit_user_escort data);
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
namespace Application.Domain;
|
||||
|
||||
public class GameEscortService(ISqlSugarClient DbClient, IRedisCache redis) : IGameEscortService, ITransient
|
||||
{
|
||||
public async Task<List<game_escort>> GetEscortData()
|
||||
{
|
||||
string key = string.Format(BaseCache.BaseCacheKeys, "Escort", "Data");
|
||||
if (await redis.ExistsAsync(key))
|
||||
{
|
||||
return await redis.GetAsync<List<game_escort>>(key);
|
||||
}
|
||||
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<game_escort>();
|
||||
var data = await db.Queryable<game_escort>().ToListAsync();
|
||||
await redis.SetAsync(key, data);
|
||||
return data;
|
||||
}
|
||||
|
||||
public async Task<game_escort> GetEscortInfo(int esId)
|
||||
{
|
||||
string key = string.Format(BaseCache.BaseCacheKeys, "Escort", "Info");
|
||||
if (await redis.HExistsHashAsync(key, esId.ToString()))
|
||||
{
|
||||
return await redis.GetHashAsync<game_escort>(key, esId.ToString());
|
||||
}
|
||||
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<game_escort>();
|
||||
var data = await db.Queryable<game_escort>().Where(it => it.esId == esId).SingleAsync();
|
||||
await redis.AddHashAsync(key, esId.ToString(), data);
|
||||
return data;
|
||||
}
|
||||
|
||||
public async Task<unit_user_escort> GetUserEscort(string userId)
|
||||
{
|
||||
string key = string.Format(UserCache.BaseCacheKey, "UserEscort");
|
||||
if (await redis.HExistsHashAsync(key, userId))
|
||||
{
|
||||
return await redis.GetHashAsync<unit_user_escort>(key, userId);
|
||||
}
|
||||
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_escort>();
|
||||
var data = await db.Queryable<unit_user_escort>().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<bool> 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<bool> 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<bool> UpdateUserEscort(unit_user_escort data)
|
||||
{
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_escort>();
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ namespace Application.Domain;
|
||||
|
||||
public class GameTool
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// 单位转换
|
||||
/// </summary>
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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))
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user