This commit is contained in:
Putoo
2026-06-24 18:11:32 +08:00
parent ad49fbb1b1
commit 9cf2c50298
11 changed files with 290 additions and 11 deletions

View File

@@ -0,0 +1,21 @@
using SqlSugar;
using System;
namespace Application.Domain.Entity
{
[Tenant("Kg.SeaTime.Game")]
public class unit_user_drug
{
/// <summary>
/// userId
/// </summary>
[SugarColumn(IsPrimaryKey = true, Length = 50)]
public string userId { get; set; }
/// <summary>
/// drug
/// </summary>
[SugarColumn(IsNullable = true,IsJson = true)]
public List<UserDrugModel> drug { get; set; }
}
}

View File

@@ -0,0 +1,10 @@
namespace Application.Domain.Entity;
public class UserDrugModel
{
public string id { get; set; }
public int goodsId { get; set; }
public string name { get; set; }
public string code { get; set; }
public int count { get; set; }
}

View File

@@ -44,5 +44,12 @@ public interface IUnitUserAttrService
Task<bool> UpdateOnLineTime(string userId, string code, int time);
#endregion
#region
Task<unit_user_drug> GetUserDrug(string userId);
Task<bool> UpdateUserDrug(unit_user_drug data);
#endregion
}

View File

@@ -201,5 +201,12 @@ public class GameGoodsService(ISqlSugarClient DbClient, IRedisCache redis) : IGa
return data;
}
#endregion
#region
#endregion
}

View File

@@ -351,5 +351,48 @@ public class UnitUserAttrService(ISqlSugarClient DbClient, IRedisCache redis) :
}
#endregion
#region
public async Task<unit_user_drug> GetUserDrug(string userId)
{
string key = string.Format(UserCache.BaseCacheKeys, "UserTool", "DrugColumn");
if (await redis.HExistsHashAsync(key, userId))
{
return await redis.GetHashAsync<unit_user_drug>(key, userId);
}
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_drug>();
var data = await db.Queryable<unit_user_drug>().Where(it => it.userId == userId).SingleAsync();
if (data == null)
{
data = new unit_user_drug();
data.userId = userId;
data.drug = new List<UserDrugModel>();
await db.Insertable(data).ExecuteCommandAsync();
}
await redis.AddHashAsync(key, userId, data);
return data;
}
public async Task<bool> UpdateUserDrug(unit_user_drug data)
{
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_drug>();
bool result = await db.Updateable<unit_user_drug>(data).ExecuteCommandAsync() > 0;
if (result)
{
await ClearUserDrug(data. userId);
}
return result;
}
private async Task ClearUserDrug(string userId)
{
string key = string.Format(UserCache.BaseCacheKeys, "UserTool", "DrugColumn");
await redis.DelHashAsync(key, userId);
}
#endregion
}

View File

@@ -686,7 +686,6 @@ public class MapController : ControllerBase
}
var myVigour = await _attrService.GetUserVigourInfo(userId);
Console.WriteLine($"{myVigour.vitality }-{resInfo.needVigour}");
if (myVigour.vitality < resInfo.needVigour)
{
return PoAction.Message("活力不足!");

View File

@@ -39,6 +39,11 @@ namespace Application.Web.Controllers.Pub
account = await _accountService.GetAccInfoByToken(sid);
if (account != null)
{
account.pwd = "";
account.npwd = "";
account.token = "";
account.openId = "";
isOnline = true;
userData = await _userService.GetUserDataByAccId(account.accId);
}

View File

@@ -17,9 +17,11 @@ public class UserController : ControllerBase
private readonly IGameChatService _chatService;
private readonly IGameSkillService _skillService;
private readonly IGameTeamService _teamService;
public UserController(IUnitUserService userService, IUnitUserAttrService attrService,
IUnitUserAccService accService, IGameMapService mapService, IUnitUserRelationService relationService,
IGameGoodsService goodsService, IGameChatService chatService,IGameSkillService skillService,IGameTeamService teamService)
IGameGoodsService goodsService, IGameChatService chatService, IGameSkillService skillService,
IGameTeamService teamService)
{
_userService = userService;
_attrService = attrService;
@@ -87,7 +89,7 @@ public class UserController : ControllerBase
var model = await UserModelTool.GetUserView(userId);
return PoAction.Ok(model);
}
/// <summary>
/// 获取基础属性信息
/// </summary>
@@ -163,7 +165,7 @@ public class UserController : ControllerBase
bool isFriend = await _relationService.CheckIsFriend(userId, userInfo.userId);
bool isEnemy = await _relationService.CheckUserEnemy(userId, userInfo.userId);
var team = await _teamService.GetUserTeamInfo(userInfo.userId);
object result = new { user, attr = new { attrInfo.lev }, acc, isOnline, onMapName, isFriend, isEnemy ,team};
object result = new { user, attr = new { attrInfo.lev }, acc, isOnline, onMapName, isFriend, isEnemy, team };
return PoAction.Ok(result);
}
@@ -284,16 +286,134 @@ public class UserController : ControllerBase
return PoAction.Message("操作失败,请稍后尝试!");
}
}
/// <summary>
/// 获取用户技能
/// </summary>
/// <returns></returns>
[HttpGet]
public async Task<IPoAction>GetUserSkill()
public async Task<IPoAction> GetUserSkill()
{
var userId = StateHelper.userId;
var data = await _skillService.GetUserSkill(userId);
return PoAction.Ok(data);
}
/// <summary>
/// 获取个人药品栏
/// </summary>
/// <returns></returns>
[HttpGet]
public async Task<IPoAction> GetUserDrugColumn()
{
string userId = StateHelper.userId;
var data = await _attrService.GetUserDrug(userId);
return PoAction.Ok(data.drug);
}
/// <summary>
/// 移除药品栏药品
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
[HttpGet]
public async Task<IPoAction> RemoverUserDrug(string id)
{
string userId = StateHelper.userId;
var data = await _attrService.GetUserDrug(userId);
var onDrug = data.drug.Find(it => it.id == id);
if (onDrug == null)
{
return PoAction.Message("药品栏无此药品!");
}
data.drug.Remove(onDrug);
if (await _attrService.UpdateUserDrug(data))
{
if (onDrug.count > 0)
{
await _goodsService.UpdateUserGoods(userId, 1, onDrug.goodsId, onDrug.count, "药品栏移除,退回背包");
}
return PoAction.Ok(true);
}
else
{
return PoAction.Message("移除失败!");
}
}
/// <summary>
/// 添加到药品栏
/// </summary>
/// <param name="goodsId"></param>
/// <returns></returns>
[HttpGet]
public async Task<IPoAction> AddUserDrug(int goodsId, int count)
{
count = count < 1 ? 1 : count;
count = count > 999 ? 999 : count;
string userId = StateHelper.userId;
var myGoods = await _goodsService.GetUserGoodsInfo(userId, goodsId);
if (myGoods == null)
{
return PoAction.Message("暂无该物品!");
}
if (myGoods.count < count)
{
return PoAction.Message("物品数量不足!");
}
if (myGoods.code != nameof(GoodsEnum.Code.Drug))
{
return PoAction.Message("该物品无法置放到药品栏!");
}
bool isAdd = false;
var myDrug = await _attrService.GetUserDrug(userId);
var onDrug = myDrug.drug.Find(it => it.goodsId == goodsId);
if (onDrug == null)
{
if (myDrug.drug.Count >= 5)
{
return PoAction.Message("药品栏最多添加5个药品!");
}
isAdd = true;
}
if (await _goodsService.UpdateUserGoods(userId, 0, goodsId, count, "放置到药品栏"))
{
if (isAdd)
{
UserDrugModel temp = new UserDrugModel();
temp.id = StringAssist.NewGuid;
temp.goodsId = goodsId;
temp.name = myGoods.goodsName;
temp.code = "Blood";
temp.count = count;
myDrug.drug.Add(temp);
}
else
{
myDrug.drug.Remove(onDrug);
onDrug.count += count;
myDrug.drug.Add(onDrug);
}
if (await _attrService.UpdateUserDrug(myDrug))
{
return PoAction.Ok(true);
}
else
{
return PoAction.Message("添加失败,请稍后尝试!");
}
}
else
{
return PoAction.Message("添加失败,请稍后尝试!");
}
}
}