增加船只接口

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,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("船只出售失败!");
}
}
}
}