增加船只接口

This commit is contained in:
LN
2026-06-13 18:05:55 +08:00
parent f6323aba8e
commit a68368d227
13 changed files with 475 additions and 75 deletions

View File

@@ -0,0 +1,75 @@
using SqlSugar;
using System;
namespace Application.Domain.Entity
{
[Tenant("Kg.SeaTime.Resource")]
public class game_ship
{
/// <summary>
/// shipId
/// </summary>
[SugarColumn(IsPrimaryKey = true, Length = 50)]
public int shipId { get; set; }
/// <summary>
/// npc
/// </summary>
[SugarColumn(IsNullable = true)]
public int? npc { get; set; }
/// <summary>
/// shipName
/// </summary>
[SugarColumn(Length = 50, IsNullable = true)]
public string shipName { get; set; }
/// <summary>
/// img
/// </summary>
[SugarColumn(Length = 50, IsNullable = true)]
public string img { get; set; }
/// <summary>
/// price
/// </summary>
[SugarColumn(Length = 18, IsNullable = true)]
public decimal? price { get; set; }
/// <summary>
/// salePrice
/// </summary>
[SugarColumn(Length = 18, IsNullable = true)]
public decimal? salePrice { get; set; }
/// <summary>
/// payType
/// </summary>
[SugarColumn(Length = 50, IsNullable = true)]
public string payType { get; set; }
/// <summary>
/// weight
/// </summary>
[SugarColumn(IsNullable = true)]
public int? weight { get; set; }
/// <summary>
/// speed
/// </summary>
[SugarColumn(IsNullable = true)]
public int? speed { get; set; }
/// <summary>
/// neeGold
/// </summary>
[SugarColumn(IsNullable = true)]
public int? neeGold { get; set; }
/// <summary>
/// remark
/// </summary>
[SugarColumn(Length = 50, IsNullable = true)]
public string remark { get; set; }
}
}

View File

@@ -15,7 +15,7 @@ public interface IGameGoodsService
Task<unit_user_goods> GetUserGoodsInfo(string userId, int goodsId);
Task<int> GetUserGoodsCount(string userId, int goodsId);
Task<List<unit_user_goods>> GetUserGoodsData(string userId, List<string> code, List<string> noCode, string search, int page,
Task<List<unit_user_goods>> GetUserGoodsData(string userId, List<string> code, List<string> noCode, string search, int page,
int limit, RefAsync<int> total);
Task<List<unit_user_goods>> GetUserGoodsData(string userId, string code);
@@ -28,4 +28,8 @@ public interface IGameGoodsService
#endregion
#region
Task<game_ship> GetShipInfo(int shipId);
#endregion
}

View File

@@ -13,7 +13,7 @@ public interface IUnitUserWeight
Task<bool> CheckUserWeight(string userId, int useWeight);
#region
Task<unit_user_ship> GetUserShipInfo(string usId);
Task<List<unit_user_ship>> GetUserShip(string userId);
Task<int> GetUserShipMaxWeight(string userId);
Task<bool> UpdateUserShipOnWeight(string userId, int op, int weight);

View File

@@ -163,7 +163,7 @@ public class GameGoodsService(ISqlSugarClient DbClient, IRedisCache redis) : IGa
return await db.Insertable(bagLog).SplitTable().ExecuteCommandAsync() > 0;
}
#endregion
@@ -186,4 +186,20 @@ public class GameGoodsService(ISqlSugarClient DbClient, IRedisCache redis) : IGa
}
#endregion
#region
public async Task<game_ship> GetShipInfo(int shipId)
{
string key = string.Format(BaseCache.BaseCacheKey, "ShipData");
var data = await redis.GetHashAsync<game_ship>(key, shipId.ToString());
if (data == null)
{
var db = DbClient.AsTenant().GetConnectionWithAttr<game_ship>();
data = await db.Queryable<game_ship>().Where(it => it.shipId == shipId).SingleAsync();
await redis.AddHashAsync(key, shipId.ToString(), data);
}
return data;
}
#endregion
}

View File

@@ -119,7 +119,19 @@ public class UnitUserWeight(ISqlSugarClient DbClient, IRedisCache redis) : IUnit
}
#region
public async Task<unit_user_ship> GetUserShipInfo(string usId)
{
string key = string.Format(UserCache.BaseCacheKeys, "UserShip", "Info");
var data = await redis.GetHashAsync<unit_user_ship>(key, usId);
if (data == null)
{
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_ship>();
data = await db.Queryable<unit_user_ship>().Where(it => it.usId == usId).SingleAsync();
await redis.AddHashAsync(key, usId, data);
}
return data;
}
public async Task<List<unit_user_ship>> GetUserShip(string userId)
{
string key = string.Format(UserCache.BaseCacheKeys, "WeightData", "Ship");

View File

@@ -2,7 +2,7 @@
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ActiveDebugProfile>https</ActiveDebugProfile>
<Controller_SelectedScaffolderID>ApiControllerEmptyScaffolder</Controller_SelectedScaffolderID>
<Controller_SelectedScaffolderCategoryPath>root/Common/Api</Controller_SelectedScaffolderCategoryPath>
<Controller_SelectedScaffolderID>MvcControllerEmptyScaffolder</Controller_SelectedScaffolderID>
<Controller_SelectedScaffolderCategoryPath>root/Common/MVC/Controller</Controller_SelectedScaffolderCategoryPath>
</PropertyGroup>
</Project>

View File

@@ -0,0 +1,112 @@
using Microsoft.AspNetCore.Mvc;
namespace Application.Web.Controllers.Pub
{
/// <summary>
/// 船队接口
/// </summary>
[Route("[controller]/[action]")]
[ApiController]
[Authorize]
public class ShipController : ControllerBase
{
private readonly IUnitUserWeight weightService;
private readonly IGameGoodsService goodsService;
private readonly IUnitUserAccService accService;
public ShipController(IUnitUserWeight _weightService, IGameGoodsService _goodsService, IUnitUserAccService _accService)
{
accService = _accService;
goodsService = _goodsService;
weightService = _weightService;
}
/// <summary>
/// 获取用户船只
/// </summary>
/// <returns></returns>
[HttpGet]
public async Task<IPoAction> GetUserShip()
{
string userId = StateHelper.userId;
var data = await weightService.GetUserShip(userId);
//个人负重
var weightInfo = await weightService.GetUserWeightInfo(userId);
return PoAction.Ok(new { data, weightInfo });
}
/// <summary>
/// 获取船只详情
/// </summary>
/// <param name="shipId"></param>
/// <returns></returns>
[HttpGet]
public async Task<IPoAction> GetShipInfo(int shipId)
{
var data = await goodsService.GetShipInfo(shipId);
if (data == null)
{
return PoAction.Message("船只详情不存在!");
}
return PoAction.Ok(new { data });
}
/// <summary>
/// 出售船只
/// </summary>
/// <param name="usId"></param>
/// <returns></returns>
[HttpPost]
public async Task<IPoAction> BuyShip([FromBody] BuyShipParms parms)
{
var userShip = await weightService.GetUserShipInfo(parms.usId);
if (userShip == null)
{
return PoAction.Message("船只不存在!");
}
string userId = StateHelper.userId;
if (userShip.userId != userId)
{
return PoAction.Message("船只不存在!");
}
var shipInfo = await goodsService.GetShipInfo((int)userShip.goodsId);
if (shipInfo == null)
{
return PoAction.Message("船只信息不存在!");
}
if (await weightService.DeleteUserShip(userShip.usId, userId))
{
if (shipInfo.payType == AccEnum.AccType.copper.ToString())
{
if (await accService.UpdateUserCopper(userId, 1, Convert.ToInt64(shipInfo.salePrice), "出售船只获得!"))
{
return PoAction.Ok(new { price = shipInfo.salePrice });
}
else
{
return PoAction.Message("出售失败!");
}
}
else if (shipInfo.payType == AccEnum.AccType.gold.ToString())
{
if (await accService.UpdateUserAcc(userId, 1, AccEnum.AccType.gold.ToString(), Convert.ToInt64(shipInfo.salePrice)))
{
return PoAction.Ok(new { price = shipInfo.salePrice });
}
else
{
return PoAction.Message("出售失败!");
}
}
else
{
return PoAction.Message("出售失败!");
}
}
else
{
return PoAction.Message("船只出售失败!");
}
}
}
}

View File

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