From e1bff431e4576a4be636f55d88a6bddd9b004168 Mon Sep 17 00:00:00 2001
From: LN <2826967552@qq.com>
Date: Sat, 4 Jul 2026 14:08:35 +0800
Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=BF=AE=E7=82=BC=E5=8A=9F?=
=?UTF-8?q?=E8=83=BD?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../game/user/unit_user_practise.cs | 45 ++++++
Service/Application.Domain/Enum/GoodsEnum.cs | 1 +
.../Interface/Pub/IUnitUserPractiseService.cs | 14 ++
.../Service/Pub/UnitUserPractiseService.cs | 30 ++++
.../Controllers/Pub/PractiseController.cs | 146 ++++++++++++++++++
.../Practise/MakePractiseParms.cs | 9 ++
.../Properties/launchSettings.json | 4 +-
7 files changed, 247 insertions(+), 2 deletions(-)
create mode 100644 Service/Application.Domain.Entity/game/user/unit_user_practise.cs
create mode 100644 Service/Application.Domain/Services/Interface/Pub/IUnitUserPractiseService.cs
create mode 100644 Service/Application.Domain/Services/Service/Pub/UnitUserPractiseService.cs
create mode 100644 Service/Application.Web/Controllers/Pub/PractiseController.cs
create mode 100644 Service/Application.Web/Model/RequestParms/Practise/MakePractiseParms.cs
diff --git a/Service/Application.Domain.Entity/game/user/unit_user_practise.cs b/Service/Application.Domain.Entity/game/user/unit_user_practise.cs
new file mode 100644
index 0000000..c70340c
--- /dev/null
+++ b/Service/Application.Domain.Entity/game/user/unit_user_practise.cs
@@ -0,0 +1,45 @@
+using SqlSugar;
+using System;
+
+namespace Application.Domain.Entity
+{
+ [Tenant("Kg.SeaTime.Game")]
+ public class unit_user_practise
+ {
+ ///
+ /// practiseId
+ ///
+ [SugarColumn(IsPrimaryKey = true, Length = 50)]
+ public string practiseId { get; set; }
+
+ ///
+ /// userId
+ ///
+ [SugarColumn(Length = 50, IsNullable = true)]
+ public string userId { get; set; }
+
+ ///
+ /// name
+ ///
+ [SugarColumn(Length = 50, IsNullable = true)]
+ public string name { get; set; }
+
+ ///
+ /// exp
+ ///
+ [SugarColumn(Length = 18, IsNullable = true)]
+ public decimal? exp { get; set; }
+
+ ///
+ /// addTime
+ ///
+ [SugarColumn(IsNullable = true)]
+ public DateTime? addTime { get; set; }
+
+ ///
+ /// endTime
+ ///
+ [SugarColumn(IsNullable = true)]
+ public DateTime? endTime { get; set; }
+ }
+}
diff --git a/Service/Application.Domain/Enum/GoodsEnum.cs b/Service/Application.Domain/Enum/GoodsEnum.cs
index 29130f3..fe24f1b 100644
--- a/Service/Application.Domain/Enum/GoodsEnum.cs
+++ b/Service/Application.Domain/Enum/GoodsEnum.cs
@@ -14,5 +14,6 @@ public static class GoodsEnum
Card,//附魔卡片
Mark,//圣痕
Pack,//宝箱
+ Practise,//修炼道具
}
}
\ No newline at end of file
diff --git a/Service/Application.Domain/Services/Interface/Pub/IUnitUserPractiseService.cs b/Service/Application.Domain/Services/Interface/Pub/IUnitUserPractiseService.cs
new file mode 100644
index 0000000..df1a782
--- /dev/null
+++ b/Service/Application.Domain/Services/Interface/Pub/IUnitUserPractiseService.cs
@@ -0,0 +1,14 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace Application.Domain
+{
+ public interface IUnitUserPractiseService
+ {
+ Task DelPractise(string practiseId);
+ Task AddPractise(unit_user_practise practise);
+ Task GetUserPractiseInfo(string practiseId);
+ Task> GetUserPractiseList(string userId, int page, int limit, RefAsync total);
+ }
+}
diff --git a/Service/Application.Domain/Services/Service/Pub/UnitUserPractiseService.cs b/Service/Application.Domain/Services/Service/Pub/UnitUserPractiseService.cs
new file mode 100644
index 0000000..73ae784
--- /dev/null
+++ b/Service/Application.Domain/Services/Service/Pub/UnitUserPractiseService.cs
@@ -0,0 +1,30 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace Application.Domain
+{
+ public class UnitUserPractiseService(ISqlSugarClient DbClient, IRedisCache redis) : IUnitUserPractiseService, ITransient
+ {
+ public async Task DelPractise(string practiseId)
+ {
+ var db = DbClient.AsTenant().GetConnectionWithAttr();
+ return await db.Deleteable().Where(i => i.practiseId == practiseId).ExecuteCommandAsync() > 0;
+ }
+ public async Task AddPractise(unit_user_practise practise)
+ {
+ var db = DbClient.AsTenant().GetConnectionWithAttr();
+ return await db.Insertable(practise).ExecuteCommandAsync() > 0;
+ }
+ public async Task GetUserPractiseInfo(string practiseId)
+ {
+ var db = DbClient.AsTenant().GetConnectionWithAttr();
+ return await db.Queryable().Where(i => i.practiseId == practiseId).SingleAsync();
+ }
+ public async Task> GetUserPractiseList(string userId, int page, int limit, RefAsync total)
+ {
+ var db = DbClient.AsTenant().GetConnectionWithAttr();
+ return await db.Queryable().Where(i => i.userId == userId).ToPageListAsync(page, limit, total);
+ }
+ }
+}
diff --git a/Service/Application.Web/Controllers/Pub/PractiseController.cs b/Service/Application.Web/Controllers/Pub/PractiseController.cs
new file mode 100644
index 0000000..cf336da
--- /dev/null
+++ b/Service/Application.Web/Controllers/Pub/PractiseController.cs
@@ -0,0 +1,146 @@
+using Microsoft.AspNetCore.Mvc;
+
+namespace Application.Web.Controllers.Pub
+{
+ ///
+ /// 山寨修炼接口
+ ///
+ [Route("[controller]/[action]")]
+ [ApiController]
+ [Authorize]
+ public class PractiseController : ControllerBase
+ {
+ private readonly IGameGoodsService goodsService;
+ private readonly IUnitUserAttrService attrService;
+ private readonly IUnitUserPractiseService practiseService;
+ public PractiseController(IUnitUserPractiseService _practiseService, IGameGoodsService goodsService, IUnitUserAttrService attrService)
+ {
+ practiseService = _practiseService;
+ this.goodsService = goodsService;
+ this.attrService = attrService;
+ }
+
+ ///
+ /// 获取山寨修炼列表
+ ///
+ ///
+ ///
+ [HttpGet]
+ public async Task GetUserPractise(int page)
+ {
+ int limit = 10;
+ RefAsync total = 0;
+ string userId = StateHelper.userId;
+ var list = await practiseService.GetUserPractiseList(userId, page, limit, total);
+ return PoAction.Ok(new { list, limit, total });
+ }
+
+ ///
+ /// 修炼道具
+ ///
+ ///
+ [HttpGet]
+ public async Task MakeGoodsList()
+ {
+ string userId = StateHelper.userId;
+ var list = await goodsService.GetUserGoodsData(userId, GoodsEnum.Code.Practise.ToString());
+ return PoAction.Ok(new { list });
+ }
+
+ ///
+ /// 立即修炼
+ ///
+ ///
+ ///
+ [HttpPost]
+ public async Task MakeGoods([FromBody] MakePractiseParms par)
+ {
+ var userGoods = await goodsService.GetUserGoodsInfo(par.par);
+ if (userGoods == null)
+ {
+ return PoAction.Message("道具不存在!");
+ }
+ var goodsInfo = await goodsService.GetGoodsInfo((int)userGoods.goodsId);
+ if (goodsInfo == null)
+ {
+ return PoAction.Message("道具不存在!");
+ }
+ if (string.IsNullOrEmpty(goodsInfo.content))
+ {
+ return PoAction.Message("暂时无法修炼!");
+ }
+ string userId = StateHelper.userId;
+ if (userGoods.userId != userId)
+ {
+ return PoAction.Message("道具不存在!");
+ }
+ if (userGoods.count < 1)
+ {
+ return PoAction.Message("道具数量不足,无法修炼!");
+ }
+ if (await goodsService.UpdateUserGoods(userId, 0, (int)userGoods.goodsId, 1, "用户修炼扣除!"))
+ {
+ string[] content = goodsInfo.content.Split("|");
+ unit_user_practise practise = new unit_user_practise();
+ practise.practiseId = StringAssist.NewGuid;
+ practise.userId = userId;
+ practise.name = userGoods.goodsName;
+ practise.exp = Convert.ToDecimal(content[0]);
+ practise.addTime = DateTime.Now;
+ practise.endTime = DateTime.Now.AddMinutes(Convert.ToInt32(content[1]));
+ if (await practiseService.AddPractise(practise))
+ {
+ return PoAction.Ok("修炼成功!");
+ }
+ else
+ {
+ await goodsService.UpdateUserGoods(userId, 1, (int)userGoods.goodsId, 1, "用户修炼失败扣除返还!");
+ return PoAction.Message("修炼失败!");
+ }
+ }
+ else
+ {
+ return PoAction.Message("修炼失败!");
+ }
+ }
+
+ ///
+ /// 完成修炼
+ ///
+ ///
+ ///
+ [HttpPost]
+ public async Task OkPractise([FromBody] MakePractiseParms par)
+ {
+ var parctiseInfo = await practiseService.GetUserPractiseInfo(par.par);
+ if (parctiseInfo == null)
+ {
+ return PoAction.Message("修炼信息不存在!");
+ }
+ string userId = StateHelper.userId;
+ if (parctiseInfo.userId != userId)
+ {
+ return PoAction.Message("修炼信息不存在!");
+ }
+ if (parctiseInfo.endTime > DateTime.Now)
+ {
+ return PoAction.Message("该修炼道具还没有到时间呢!");
+ }
+ if (await practiseService.DelPractise(parctiseInfo.practiseId))
+ {
+ if (await attrService.UpdateUserExp(userId, Convert.ToInt64(parctiseInfo.exp)))
+ {
+ return PoAction.Ok(string.Format("修炼成功,获得{0}经验!", parctiseInfo.exp));
+ }
+ else
+ {
+ return PoAction.Message("完成失败!");
+ }
+ }
+ else
+ {
+ return PoAction.Message("完成失败!");
+ }
+ }
+ }
+}
diff --git a/Service/Application.Web/Model/RequestParms/Practise/MakePractiseParms.cs b/Service/Application.Web/Model/RequestParms/Practise/MakePractiseParms.cs
new file mode 100644
index 0000000..69a236b
--- /dev/null
+++ b/Service/Application.Web/Model/RequestParms/Practise/MakePractiseParms.cs
@@ -0,0 +1,9 @@
+using Microsoft.AspNetCore.Mvc;
+
+namespace Application.Web
+{
+ public class MakePractiseParms
+ {
+ public string par { get; set; }
+ }
+}
diff --git a/Service/Application.Web/Properties/launchSettings.json b/Service/Application.Web/Properties/launchSettings.json
index 2fd1bf3..50823b2 100644
--- a/Service/Application.Web/Properties/launchSettings.json
+++ b/Service/Application.Web/Properties/launchSettings.json
@@ -5,7 +5,7 @@
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": false,
- "applicationUrl": "http://localhost:5031;",
+ "applicationUrl": "http://[::]:5031;",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
@@ -14,7 +14,7 @@
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": false,
- "applicationUrl": "https://localhost:7198;http://localhost:5031",
+ "applicationUrl": "https://[::]:7198;",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}