452424
This commit is contained in:
@@ -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; }
|
||||
}
|
||||
}
|
||||
10
Service/Application.Domain.Entity/model/UserDrugModel.cs
Normal file
10
Service/Application.Domain.Entity/model/UserDrugModel.cs
Normal 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; }
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
@@ -201,5 +201,12 @@ public class GameGoodsService(ISqlSugarClient DbClient, IRedisCache redis) : IGa
|
||||
|
||||
return data;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 药品
|
||||
|
||||
|
||||
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
@@ -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("活力不足!");
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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("添加失败,请稍后尝试!");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -17,8 +17,25 @@
|
||||
<div class="common">
|
||||
数量:{{ count }}
|
||||
</div>
|
||||
<div class="common" v-if="data.code == 'Drug'">
|
||||
<Abutton @click="ShowDrugBar">添加药品栏</Abutton>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<GamePopup v-model:show="showDrugView" title="【添加药品栏】">
|
||||
<!-- 自定义内容 -->
|
||||
<div class="common" style="margin-top: 10px;">
|
||||
药品名称:{{ data.goodsName }}<br>
|
||||
说明:{{ data.tips }}<br>
|
||||
</div>
|
||||
<div class="common" style="text-align: left;">
|
||||
添加数量:<input type="number" class="search-ipt" v-model="AddDrugCount"><br>
|
||||
</div>
|
||||
<div class="common" style="text-align: center;">
|
||||
<button class="ipt-btn" name="serch" @click="AddDrugBar" style="margin-top: 15px;">确认</button>
|
||||
</div>
|
||||
</GamePopup>
|
||||
</template>
|
||||
<script setup lang="ts">
|
||||
|
||||
@@ -28,7 +45,7 @@ definePageMeta({
|
||||
})
|
||||
const data = ref<any>({});
|
||||
const count = ref(0);
|
||||
|
||||
let goodsId = PageExtend.QueryString("id");
|
||||
onMounted(async () => {
|
||||
try {
|
||||
await BindData();
|
||||
@@ -41,7 +58,6 @@ onMounted(async () => {
|
||||
|
||||
|
||||
const BindData = async (): Promise<void> => {
|
||||
let goodsId = PageExtend.QueryString("id");
|
||||
let result = await GoodsService.GetGoodsInfo(Number(goodsId));
|
||||
if (result.code == 0) {
|
||||
data.value = result.data.goods;
|
||||
@@ -53,4 +69,29 @@ const BindData = async (): Promise<void> => {
|
||||
}
|
||||
};
|
||||
|
||||
/**添加到药品栏 */
|
||||
const showDrugView = ref(false);
|
||||
const AddDrugCount = ref(1);
|
||||
const ShowDrugBar = async () => {
|
||||
showDrugView.value = true;
|
||||
}
|
||||
|
||||
const AddDrugBar = async () => {
|
||||
if (AddDrugCount.value < 1 || AddDrugCount.value > 999) {
|
||||
MessageExtend.ShowToast("每次添加数量在1~999哦.");
|
||||
return;
|
||||
}
|
||||
MessageExtend.LoadingToast("添加中...");
|
||||
let result = await UserService.AddUserDrug(Number(goodsId), AddDrugCount.value)
|
||||
MessageExtend.LoadingClose();
|
||||
if (result.code == 0) {
|
||||
showDrugView.value = false;
|
||||
await BindData();
|
||||
MessageExtend.Notify(`成功添加${data.value.goodsName}×${AddDrugCount.value}到药品栏!`, "success");
|
||||
}
|
||||
else {
|
||||
MessageExtend.ShowDialog("提示", result.msg);
|
||||
}
|
||||
}
|
||||
|
||||
</script>
|
||||
@@ -73,10 +73,12 @@
|
||||
套装:<Abar :href='"/user/equ/suit?id=" + item.suitCode'>{{ item.suitName }}</Abar>
|
||||
</div>
|
||||
</div>
|
||||
<div class="content">
|
||||
<div class="content">
|
||||
<Abar href="/">我的九宫牌</Abar><br>
|
||||
<Abar href="/">我的圣痕</Abar><br>
|
||||
<Abar href="/user/bag/drug">我的药品栏</Abar><br>
|
||||
<Abar href="/user/bag">装备物品</Abar>
|
||||
|
||||
</div>
|
||||
<!-- 选择装备 -->
|
||||
<GamePopup v-model:show="showChooseEqu" title="【选择装备】" style="min-width: 60%;">
|
||||
@@ -195,7 +197,7 @@ const chooseEqu = async (type: number, data: Array<any>) => {
|
||||
}
|
||||
|
||||
const OnEqu = async (ueId: string) => {
|
||||
showChooseEqu.value = false;
|
||||
showChooseEqu.value = false;
|
||||
await DownAndOnEqu(ueId, "");
|
||||
}
|
||||
const ChangeEqu = async (ueId: string) => {
|
||||
|
||||
@@ -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 });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user