diff --git a/Service/Application.Domain.Entity/game/user/unit_user_drug.cs b/Service/Application.Domain.Entity/game/user/unit_user_drug.cs new file mode 100644 index 0000000..49dd28d --- /dev/null +++ b/Service/Application.Domain.Entity/game/user/unit_user_drug.cs @@ -0,0 +1,21 @@ +using SqlSugar; +using System; + +namespace Application.Domain.Entity +{ + [Tenant("Kg.SeaTime.Game")] + public class unit_user_drug + { + /// + /// userId + /// + [SugarColumn(IsPrimaryKey = true, Length = 50)] + public string userId { get; set; } + + /// + /// drug + /// + [SugarColumn(IsNullable = true,IsJson = true)] + public List drug { get; set; } + } +} \ No newline at end of file diff --git a/Service/Application.Domain.Entity/model/UserDrugModel.cs b/Service/Application.Domain.Entity/model/UserDrugModel.cs new file mode 100644 index 0000000..8c045a1 --- /dev/null +++ b/Service/Application.Domain.Entity/model/UserDrugModel.cs @@ -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; } +} \ No newline at end of file diff --git a/Service/Application.Domain/Services/Interface/User/IUnitUserAttrService.cs b/Service/Application.Domain/Services/Interface/User/IUnitUserAttrService.cs index 09aebd7..3a5456e 100644 --- a/Service/Application.Domain/Services/Interface/User/IUnitUserAttrService.cs +++ b/Service/Application.Domain/Services/Interface/User/IUnitUserAttrService.cs @@ -44,5 +44,12 @@ public interface IUnitUserAttrService Task UpdateOnLineTime(string userId, string code, int time); + #endregion + + #region 药品栏 + + Task GetUserDrug(string userId); + Task UpdateUserDrug(unit_user_drug data); + #endregion } \ No newline at end of file diff --git a/Service/Application.Domain/Services/Service/Goods/GameGoodsService.cs b/Service/Application.Domain/Services/Service/Goods/GameGoodsService.cs index 25bd294..0df52e9 100644 --- a/Service/Application.Domain/Services/Service/Goods/GameGoodsService.cs +++ b/Service/Application.Domain/Services/Service/Goods/GameGoodsService.cs @@ -201,5 +201,12 @@ public class GameGoodsService(ISqlSugarClient DbClient, IRedisCache redis) : IGa return data; } + #endregion + + #region 药品 + + + + #endregion } \ No newline at end of file diff --git a/Service/Application.Domain/Services/Service/User/UnitUserAttrService.cs b/Service/Application.Domain/Services/Service/User/UnitUserAttrService.cs index 4ab8a72..cb287c2 100644 --- a/Service/Application.Domain/Services/Service/User/UnitUserAttrService.cs +++ b/Service/Application.Domain/Services/Service/User/UnitUserAttrService.cs @@ -351,5 +351,48 @@ public class UnitUserAttrService(ISqlSugarClient DbClient, IRedisCache redis) : } + #endregion + + #region 药品栏 + + public async Task GetUserDrug(string userId) + { + string key = string.Format(UserCache.BaseCacheKeys, "UserTool", "DrugColumn"); + 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_drug(); + data.userId = userId; + data.drug = new List(); + await db.Insertable(data).ExecuteCommandAsync(); + } + + await redis.AddHashAsync(key, userId, data); + return data; + } + + public async Task UpdateUserDrug(unit_user_drug data) + { + var db = DbClient.AsTenant().GetConnectionWithAttr(); + bool result = await db.Updateable(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 } \ No newline at end of file diff --git a/Service/Application.Web/Controllers/Map/MapController.cs b/Service/Application.Web/Controllers/Map/MapController.cs index 53667f0..bbf8a73 100644 --- a/Service/Application.Web/Controllers/Map/MapController.cs +++ b/Service/Application.Web/Controllers/Map/MapController.cs @@ -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("活力不足!"); diff --git a/Service/Application.Web/Controllers/Pub/PubController.cs b/Service/Application.Web/Controllers/Pub/PubController.cs index fb0fcaa..c16b58d 100644 --- a/Service/Application.Web/Controllers/Pub/PubController.cs +++ b/Service/Application.Web/Controllers/Pub/PubController.cs @@ -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); } diff --git a/Service/Application.Web/Controllers/User/UserController.cs b/Service/Application.Web/Controllers/User/UserController.cs index c9d4ed1..ee8d9bf 100644 --- a/Service/Application.Web/Controllers/User/UserController.cs +++ b/Service/Application.Web/Controllers/User/UserController.cs @@ -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); } - + /// /// 获取基础属性信息 /// @@ -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("操作失败,请稍后尝试!"); } } - + /// /// 获取用户技能 /// /// [HttpGet] - public async TaskGetUserSkill() + public async Task GetUserSkill() { var userId = StateHelper.userId; var data = await _skillService.GetUserSkill(userId); return PoAction.Ok(data); } + + /// + /// 获取个人药品栏 + /// + /// + [HttpGet] + public async Task GetUserDrugColumn() + { + string userId = StateHelper.userId; + var data = await _attrService.GetUserDrug(userId); + return PoAction.Ok(data.drug); + } + + /// + /// 移除药品栏药品 + /// + /// + /// + [HttpGet] + public async Task 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("移除失败!"); + } + } + + /// + /// 添加到药品栏 + /// + /// + /// + [HttpGet] + public async Task 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("添加失败,请稍后尝试!"); + } + } } \ No newline at end of file diff --git a/Web/src/pages/prop/goods.vue b/Web/src/pages/prop/goods.vue index 1ff4e96..3312244 100644 --- a/Web/src/pages/prop/goods.vue +++ b/Web/src/pages/prop/goods.vue @@ -17,8 +17,25 @@
数量:{{ count }}
+
+ 添加药品栏 +
+ + + +
+ 药品名称:{{ data.goodsName }}
+ 说明:{{ data.tips }}
+
+
+ 添加数量:
+
+
+ +
+
\ No newline at end of file diff --git a/Web/src/pages/user/equ/index.vue b/Web/src/pages/user/equ/index.vue index a0feec4..7349756 100644 --- a/Web/src/pages/user/equ/index.vue +++ b/Web/src/pages/user/equ/index.vue @@ -73,10 +73,12 @@ 套装:{{ item.suitName }} -
+
我的九宫牌
我的圣痕
+ 我的药品栏
装备物品 +
@@ -195,7 +197,7 @@ const chooseEqu = async (type: number, data: Array) => { } const OnEqu = async (ueId: string) => { - showChooseEqu.value = false; + showChooseEqu.value = false; await DownAndOnEqu(ueId, ""); } const ChangeEqu = async (ueId: string) => { diff --git a/Web/src/services/user/UserService.ts b/Web/src/services/user/UserService.ts index c184230..a485adc 100644 --- a/Web/src/services/user/UserService.ts +++ b/Web/src/services/user/UserService.ts @@ -58,11 +58,35 @@ export class UserService { return await ApiService.Request("post", "/User/User/UpdateUserSign", { sign }); } - /** + /** * 获取用户技能 * GET /User/User/GetUserSkill */ static async GetUserSkill() { return await ApiService.Request("get", "/User/User/GetUserSkill"); } + + /** + * 获取个人药品栏 + * GET /User/User/GetUserDrugColumn + */ + static async GetUserDrugColumn() { + return await ApiService.Request("get", "/User/User/GetUserDrugColumn"); + } + + /** + * 移除药品栏药品 + * GET /User/User/RemoverUserDrug + */ + static async RemoverUserDrug(id: string) { + return await ApiService.Request("get", "/User/User/RemoverUserDrug", { id }); + } + + /** + * 添加到药品栏 + * GET /User/User/AddUserDrug + */ + static async AddUserDrug(goodsId: number, count: number) { + return await ApiService.Request("get", "/User/User/AddUserDrug", { goodsId, count }); + } } \ No newline at end of file