Merge remote-tracking branch 'master/master'

This commit is contained in:
Putoo
2026-07-04 18:07:47 +08:00
7 changed files with 247 additions and 2 deletions

View File

@@ -0,0 +1,45 @@
using SqlSugar;
using System;
namespace Application.Domain.Entity
{
[Tenant("Kg.SeaTime.Game")]
public class unit_user_practise
{
/// <summary>
/// practiseId
/// </summary>
[SugarColumn(IsPrimaryKey = true, Length = 50)]
public string practiseId { get; set; }
/// <summary>
/// userId
/// </summary>
[SugarColumn(Length = 50, IsNullable = true)]
public string userId { get; set; }
/// <summary>
/// name
/// </summary>
[SugarColumn(Length = 50, IsNullable = true)]
public string name { get; set; }
/// <summary>
/// exp
/// </summary>
[SugarColumn(Length = 18, IsNullable = true)]
public decimal? exp { get; set; }
/// <summary>
/// addTime
/// </summary>
[SugarColumn(IsNullable = true)]
public DateTime? addTime { get; set; }
/// <summary>
/// endTime
/// </summary>
[SugarColumn(IsNullable = true)]
public DateTime? endTime { get; set; }
}
}

View File

@@ -19,6 +19,7 @@ public static class GoodsEnum
Exp,//经验
State,//状态物品
Ship,//船只
Practise,//修炼道具
}
public enum DrugCls

View File

@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace Application.Domain
{
public interface IUnitUserPractiseService
{
Task<bool> DelPractise(string practiseId);
Task<bool> AddPractise(unit_user_practise practise);
Task<unit_user_practise> GetUserPractiseInfo(string practiseId);
Task<List<unit_user_practise>> GetUserPractiseList(string userId, int page, int limit, RefAsync<int> total);
}
}

View File

@@ -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<bool> DelPractise(string practiseId)
{
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_practise>();
return await db.Deleteable<unit_user_practise>().Where(i => i.practiseId == practiseId).ExecuteCommandAsync() > 0;
}
public async Task<bool> AddPractise(unit_user_practise practise)
{
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_practise>();
return await db.Insertable(practise).ExecuteCommandAsync() > 0;
}
public async Task<unit_user_practise> GetUserPractiseInfo(string practiseId)
{
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_practise>();
return await db.Queryable<unit_user_practise>().Where(i => i.practiseId == practiseId).SingleAsync();
}
public async Task<List<unit_user_practise>> GetUserPractiseList(string userId, int page, int limit, RefAsync<int> total)
{
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_practise>();
return await db.Queryable<unit_user_practise>().Where(i => i.userId == userId).ToPageListAsync(page, limit, total);
}
}
}

View File

@@ -0,0 +1,146 @@
using Microsoft.AspNetCore.Mvc;
namespace Application.Web.Controllers.Pub
{
/// <summary>
/// 山寨修炼接口
/// </summary>
[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;
}
/// <summary>
/// 获取山寨修炼列表
/// </summary>
/// <param name="page"></param>
/// <returns></returns>
[HttpGet]
public async Task<IPoAction> GetUserPractise(int page)
{
int limit = 10;
RefAsync<int> total = 0;
string userId = StateHelper.userId;
var list = await practiseService.GetUserPractiseList(userId, page, limit, total);
return PoAction.Ok(new { list, limit, total });
}
/// <summary>
/// 修炼道具
/// </summary>
/// <returns></returns>
[HttpGet]
public async Task<IPoAction> MakeGoodsList()
{
string userId = StateHelper.userId;
var list = await goodsService.GetUserGoodsData(userId, GoodsEnum.Code.Practise.ToString());
return PoAction.Ok(new { list });
}
/// <summary>
/// 立即修炼
/// </summary>
/// <param name="par"></param>
/// <returns></returns>
[HttpPost]
public async Task<IPoAction> 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("修炼失败!");
}
}
/// <summary>
/// 完成修炼
/// </summary>
/// <param name="par"></param>
/// <returns></returns>
[HttpPost]
public async Task<IPoAction> 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("完成失败!");
}
}
}
}

View File

@@ -0,0 +1,9 @@
using Microsoft.AspNetCore.Mvc;
namespace Application.Web
{
public class MakePractiseParms
{
public string par { get; set; }
}
}

View File

@@ -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"
}