222
This commit is contained in:
@@ -0,0 +1,81 @@
|
||||
using SqlSugar;
|
||||
using System;
|
||||
|
||||
namespace Application.Domain.Entity
|
||||
{
|
||||
[Tenant("Kg.SeaTime.Resource")]
|
||||
public class game_goods
|
||||
{
|
||||
/// <summary>
|
||||
/// goodsId
|
||||
/// </summary>
|
||||
[SugarColumn(IsPrimaryKey = true)]
|
||||
public int goodsId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// goodsName
|
||||
/// </summary>
|
||||
[SugarColumn(Length = 50, IsNullable = true)]
|
||||
public string? goodsName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// lev
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = true)]
|
||||
public int? lev { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// code
|
||||
/// </summary>
|
||||
[SugarColumn(Length = 50, IsNullable = true)]
|
||||
public string? code { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// img
|
||||
/// </summary>
|
||||
[SugarColumn(Length = 50, IsNullable = true)]
|
||||
public string? img { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// tips
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = true)]
|
||||
public string? tips { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// source
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = true)]
|
||||
public string? source { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// weight
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = true)]
|
||||
public int? weight { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// sysPrice
|
||||
/// </summary>
|
||||
[SugarColumn(Length = 18, IsNullable = true)]
|
||||
public decimal? sysPrice { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// content
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = true)]
|
||||
public string? content { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 0不可交易1可交易
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = true)]
|
||||
public int? isDeal { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 0不可赠送 1可赠送
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = true)]
|
||||
public int? isGive { get; set; }
|
||||
}
|
||||
}
|
||||
10
Service/Application.Domain/Enum/GameEnum.cs
Normal file
10
Service/Application.Domain/Enum/GameEnum.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
namespace Application.Domain;
|
||||
|
||||
public class GameEnum
|
||||
{
|
||||
public enum LogCode
|
||||
{
|
||||
减少,
|
||||
增加
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace Application.Domain;
|
||||
|
||||
public interface IGameEquService
|
||||
{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
namespace Application.Domain;
|
||||
|
||||
public interface IGameGoodsService
|
||||
{
|
||||
#region 道具资源
|
||||
|
||||
Task<game_goods> GetGoodsInfo(int goodsId);
|
||||
Task<string> GetGoodsContent(int goodsId);
|
||||
|
||||
#endregion
|
||||
|
||||
#region 个人道具
|
||||
|
||||
Task<unit_user_goods> GetUserGoodsInfo(string ugId);
|
||||
Task<unit_user_goods> GetUserGoodsInfo(string userId, int goodsId);
|
||||
Task<int> GetUserGoodsCount(string userId, int goodsId);
|
||||
|
||||
Task<List<unit_user_goods>> GetUserGoodsData(string userId, List<string> code, string search, int page,
|
||||
int limit, RefAsync<int> total);
|
||||
|
||||
Task<bool> UpdateUserGoods(string userId, int op, int goodsId, int count, string remark = "");
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -6,6 +6,7 @@ public interface IGameMapService
|
||||
|
||||
Task<game_city> GetCityInfo(int cityId);
|
||||
Task<game_city_map> GetMapInfo(string mapId);
|
||||
Task<List<game_city_map>> GetMapCity(int cityId);
|
||||
Task<int> GetMapCityByMapId(string mapId);
|
||||
Task<List<game_city_npc>> GetMapNpc(string mapId);
|
||||
Task<game_city_npc> GetNpcInfo(int npcId);
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
namespace Application.Domain;
|
||||
|
||||
public class GameEquService(ISqlSugarClient DbClient, IRedisCache redis) : IGameEquService, ITransient
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,156 @@
|
||||
using System.Reflection.Metadata;
|
||||
|
||||
namespace Application.Domain;
|
||||
|
||||
public class GameGoodsService(ISqlSugarClient DbClient, IRedisCache redis) : IGameEquService, ITransient
|
||||
{
|
||||
#region 道具资源
|
||||
|
||||
public async Task<game_goods> GetGoodsInfo(int goodsId)
|
||||
{
|
||||
string key = string.Format(BaseCache.BaseCacheKey, "GoodsData");
|
||||
var data = await redis.GetHashAsync<game_goods>(key, goodsId.ToString());
|
||||
if (data == null)
|
||||
{
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<game_goods>();
|
||||
data = await db.Queryable<game_goods>().Where(it => it.goodsId == goodsId).SingleAsync();
|
||||
await redis.AddHashAsync(key, goodsId.ToString(), data);
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
public async Task<string> GetGoodsContent(int goodsId)
|
||||
{
|
||||
var goodsInfo = await GetGoodsInfo(goodsId);
|
||||
if (goodsInfo == null)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
else
|
||||
{
|
||||
return goodsInfo.content;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 个人道具
|
||||
|
||||
public async Task<unit_user_goods> GetUserGoodsInfo(string ugId)
|
||||
{
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_goods>();
|
||||
return await db.Queryable<unit_user_goods>().Where(it => it.ugId == ugId).SingleAsync();
|
||||
}
|
||||
|
||||
public async Task<unit_user_goods> GetUserGoodsInfo(string userId, int goodsId)
|
||||
{
|
||||
string ugId = GetUserGoodsKey(userId, goodsId);
|
||||
return await GetUserGoodsInfo(ugId);
|
||||
}
|
||||
|
||||
public async Task<int> GetUserGoodsCount(string userId, int goodsId)
|
||||
{
|
||||
var info = await GetUserGoodsInfo(userId, goodsId);
|
||||
return info == null ? 0 : (int)info.count;
|
||||
}
|
||||
|
||||
public async Task<List<unit_user_goods>> GetUserGoodsData(string userId, List<string> code, string search, int page,
|
||||
int limit, RefAsync<int> total)
|
||||
{
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_goods>();
|
||||
return await db.Queryable<unit_user_goods>().Where(it => it.userId == userId && it.count > 0)
|
||||
.WhereIF(code.Count > 0, it => code.Contains(it.code))
|
||||
.WhereIF(!string.IsNullOrEmpty(search), it => it.goodsName.Contains(search))
|
||||
.OrderBy(it => it.lev, OrderByType.Desc)
|
||||
.OrderBy(it => it.count, OrderByType.Desc)
|
||||
.ToPageListAsync(page, limit, total);
|
||||
}
|
||||
|
||||
|
||||
public async Task<bool> UpdateUserGoods(string userId, int op, int goodsId, int count, string remark = "")
|
||||
{
|
||||
bool isOk = false;
|
||||
unit_user_goods UserGoods = new unit_user_goods();
|
||||
string ugId = GetUserGoodsKey(userId, goodsId);
|
||||
try
|
||||
{
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_goods>();
|
||||
UserGoods = await db.Queryable<unit_user_goods>().Where(it => it.ugId == ugId).SingleAsync();
|
||||
await DbClient.AsTenant().BeginTranAsync();
|
||||
if (op == 1) //增加
|
||||
{
|
||||
if (UserGoods == null)
|
||||
{
|
||||
var goodsInfo = await GetGoodsInfo(goodsId);
|
||||
UserGoods = new unit_user_goods();
|
||||
UserGoods.ugId = ugId;
|
||||
UserGoods.userId = userId;
|
||||
UserGoods.goodsId = goodsId;
|
||||
UserGoods.count = count;
|
||||
UserGoods.lev = goodsInfo.lev;
|
||||
UserGoods.code = goodsInfo.code;
|
||||
UserGoods.goodsName = goodsInfo.goodsName;
|
||||
UserGoods.weight = goodsInfo.weight;
|
||||
UserGoods.sysPrice = goodsInfo.sysPrice;
|
||||
UserGoods.isDeal = goodsInfo.isDeal;
|
||||
UserGoods.isGive = goodsInfo.isGive;
|
||||
isOk = await db.Insertable(UserGoods).ExecuteCommandAsync() > 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
isOk = await db.Updateable<unit_user_goods>().SetColumns(it => it.count == it.count + count)
|
||||
.Where(it => it.ugId == ugId).ExecuteCommandAsync() > 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
isOk = await db.Updateable<unit_user_goods>().SetColumns(it => it.count == it.count - count)
|
||||
.Where(it => it.ugId == ugId).ExecuteCommandAsync() > 0;
|
||||
}
|
||||
|
||||
await DbClient.AsTenant().CommitTranAsync();
|
||||
}
|
||||
catch
|
||||
{
|
||||
await DbClient.AsTenant().RollbackTranAsync();
|
||||
isOk = false;
|
||||
}
|
||||
|
||||
if (isOk)
|
||||
{
|
||||
//更新负重
|
||||
|
||||
//添加日志
|
||||
|
||||
await AddGoodsLog(userId, goodsId, op, count, remark);
|
||||
}
|
||||
|
||||
return isOk;
|
||||
}
|
||||
|
||||
private async Task<bool> AddGoodsLog(string userId, int goodsId, int code, int count, string remark)
|
||||
{
|
||||
unit_user_goods_log bagLog = new unit_user_goods_log();
|
||||
bagLog.logId = StringAssist.NewGuid;
|
||||
bagLog.userId = userId;
|
||||
bagLog.goodsId = goodsId;
|
||||
bagLog.code = code == 0 ? bagLog.code = nameof(GameEnum.LogCode.减少) : bagLog.code = nameof(GameEnum.LogCode.增加);
|
||||
bagLog.count = count;
|
||||
bagLog.addTime = DateTime.Now;
|
||||
bagLog.remark = remark;
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_goods_log>();
|
||||
return await db.Insertable(bagLog).SplitTable().ExecuteCommandAsync() > 0;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 辅助
|
||||
|
||||
private string GetUserGoodsKey(string userId, int goodsId)
|
||||
{
|
||||
return $"{userId}_{goodsId}";
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -1,27 +1,18 @@
|
||||
namespace Application.Domain;
|
||||
|
||||
public class GameMapService : IGameMapService, ITransient
|
||||
public class GameMapService (ISqlSugarClient DbClient, IRedisCache redis): IGameMapService, ITransient
|
||||
{
|
||||
private readonly ISqlSugarClient _dbClient;
|
||||
private readonly IRedisCache _redisClient;
|
||||
|
||||
public GameMapService(ISqlSugarClient dbClient, IRedisCache redisClient)
|
||||
{
|
||||
_dbClient = dbClient;
|
||||
_redisClient = redisClient;
|
||||
}
|
||||
|
||||
#region 城市地图数据
|
||||
|
||||
public async Task<game_city> GetCityInfo(int cityId)
|
||||
{
|
||||
string key = string.Format(BaseCache.BaseCacheKeys, "MapCityData", "CityData");
|
||||
var data = await _redisClient.GetHashAsync<game_city>(key, cityId.ToString());
|
||||
var data = await redis.GetHashAsync<game_city>(key, cityId.ToString());
|
||||
if (data == null)
|
||||
{
|
||||
var db = _dbClient.AsTenant().GetConnectionWithAttr<game_city>();
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<game_city>();
|
||||
data = await db.Queryable<game_city>().Where(it => it.cityId == cityId).SingleAsync();
|
||||
await _redisClient.AddHashAsync(key, cityId.ToString(), data);
|
||||
await redis.AddHashAsync(key, cityId.ToString(), data);
|
||||
}
|
||||
|
||||
return data;
|
||||
@@ -30,17 +21,28 @@ public class GameMapService : IGameMapService, ITransient
|
||||
public async Task<game_city_map> GetMapInfo(string mapId)
|
||||
{
|
||||
string key = string.Format(BaseCache.BaseCacheKeys, "MapCityData", "MapData");
|
||||
var data = await _redisClient.GetHashAsync<game_city_map>(key, mapId);
|
||||
var data = await redis.GetHashAsync<game_city_map>(key, mapId);
|
||||
if (data == null)
|
||||
{
|
||||
var db = _dbClient.AsTenant().GetConnectionWithAttr<game_city_map>();
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<game_city_map>();
|
||||
data = await db.Queryable<game_city_map>().Where(it => it.mapId == mapId).SingleAsync();
|
||||
await _redisClient.AddHashAsync(key, mapId, data);
|
||||
await redis.AddHashAsync(key, mapId, data);
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
public async Task<List<game_city_map>> GetMapCity(int cityId)
|
||||
{
|
||||
string key = string.Format(BaseCache.BaseCacheKeys, "MapCityData", "CityShowMap");
|
||||
var data = await redis.GetHashAsync<List<game_city_map>>(key, cityId.ToString());
|
||||
if (data == null)
|
||||
{
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<game_city_map>();
|
||||
data = await db.Queryable<game_city_map>().Where(it => it.cityId == cityId && it.show == 1).ToListAsync();
|
||||
await redis.AddHashAsync(key, cityId.ToString(), data);
|
||||
}
|
||||
return data;
|
||||
}
|
||||
public async Task<int> GetMapCityByMapId(string mapId)
|
||||
{
|
||||
var data = await GetMapInfo(mapId);
|
||||
@@ -57,12 +59,12 @@ public class GameMapService : IGameMapService, ITransient
|
||||
public async Task<List<game_city_npc>> GetMapNpc(string mapId)
|
||||
{
|
||||
string key = string.Format(BaseCache.BaseCacheKeys, "MapCityData", "NpcData");
|
||||
var data = await _redisClient.GetHashAsync<List<game_city_npc>>(key, mapId);
|
||||
var data = await redis.GetHashAsync<List<game_city_npc>>(key, mapId);
|
||||
if (data == null)
|
||||
{
|
||||
var db = _dbClient.AsTenant().GetConnectionWithAttr<game_city_npc>();
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<game_city_npc>();
|
||||
data = await db.Queryable<game_city_npc>().Where(it => it.mapId == mapId && it.status == 1).ToListAsync();
|
||||
await _redisClient.AddHashAsync(key, mapId, data);
|
||||
await redis.AddHashAsync(key, mapId, data);
|
||||
}
|
||||
|
||||
return data;
|
||||
@@ -70,12 +72,12 @@ public class GameMapService : IGameMapService, ITransient
|
||||
public async Task<game_city_npc> GetNpcInfo(int npcId)
|
||||
{
|
||||
string key = string.Format(BaseCache.BaseCacheKeys, "MapCityData", "NpcInfo");
|
||||
var data = await _redisClient.GetHashAsync<game_city_npc>(key, npcId.ToString());
|
||||
var data = await redis.GetHashAsync<game_city_npc>(key, npcId.ToString());
|
||||
if (data == null)
|
||||
{
|
||||
var db = _dbClient.AsTenant().GetConnectionWithAttr<game_city_npc>();
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<game_city_npc>();
|
||||
data = await db.Queryable<game_city_npc>().Where(it => it.npcId == npcId).SingleAsync();
|
||||
await _redisClient.AddHashAsync(key, npcId.ToString(),data);
|
||||
await redis.AddHashAsync(key, npcId.ToString(),data);
|
||||
}
|
||||
return data;
|
||||
}
|
||||
@@ -98,14 +100,14 @@ public class GameMapService : IGameMapService, ITransient
|
||||
public async Task<unit_user_online> GetUserOnMap(string userId)
|
||||
{
|
||||
string key = string.Format(UserCache.BaseCacheKey, "UserOnline");
|
||||
if (await _redisClient.HExistsHashAsync(key, userId))
|
||||
if (await redis.HExistsHashAsync(key, userId))
|
||||
{
|
||||
return await _redisClient.GetHashAsync<unit_user_online>(key, userId);
|
||||
return await redis.GetHashAsync<unit_user_online>(key, userId);
|
||||
}
|
||||
|
||||
var db = _dbClient.AsTenant().GetConnectionWithAttr<unit_user_online>();
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_online>();
|
||||
var data = await db.Queryable<unit_user_online>().Where(it => it.userId == userId).SingleAsync();
|
||||
await _redisClient.AddHashAsync(key, userId, data);
|
||||
await redis.AddHashAsync(key, userId, data);
|
||||
return data;
|
||||
}
|
||||
|
||||
@@ -117,9 +119,9 @@ public class GameMapService : IGameMapService, ITransient
|
||||
onLine.ip = ip;
|
||||
onLine.upTime = TimeAssist.GetTimeStampNum;
|
||||
string key = string.Format(UserCache.BaseCacheKey, "UserOnline");
|
||||
if (await _redisClient.AddHashAsync(key, userId, onLine))
|
||||
if (await redis.AddHashAsync(key, userId, onLine))
|
||||
{
|
||||
var db = _dbClient.AsTenant().GetConnectionWithAttr<unit_user_online>();
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_online>();
|
||||
await db.Updateable<unit_user_online>(onLine).ExecuteCommandAsync();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ public class MapController : ControllerBase
|
||||
npcData = npcData.FindAll(it => GameTool.AreaVerify(StateHelper.areaId, it.areaId));
|
||||
//城市信息
|
||||
var cityInfo = await _mapService.GetCityInfo((int)mapInfo.cityId);
|
||||
|
||||
var cityShow = await _mapService.GetMapCity(cityInfo.cityId);
|
||||
#region 更新在线
|
||||
|
||||
string ip = ComHelper.GetClientUserIp(HttpContext);
|
||||
@@ -61,7 +61,7 @@ public class MapController : ControllerBase
|
||||
|
||||
#endregion
|
||||
|
||||
object ret = new { mapInfo, cityInfo, npcData, chatData };
|
||||
object ret = new { mapInfo, cityInfo, npcData, chatData,cityShow };
|
||||
|
||||
return PoAction.Ok(ret);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user