This commit is contained in:
Putoo
2026-06-29 18:17:54 +08:00
parent e47a5a19a6
commit 93d21ba9fd
35 changed files with 1073 additions and 293 deletions

View File

@@ -10,14 +10,14 @@ namespace Application.Web.Controllers.Pub
[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)
private readonly IUnitUserWeight _weightService;
private readonly IUnitUserAccService _accService;
public ShipController(IUnitUserWeight weightService,
IUnitUserAccService accService)
{
accService = _accService;
goodsService = _goodsService;
weightService = _weightService;
_accService = accService;
_weightService = weightService;
}
/// <summary>
@@ -28,27 +28,11 @@ namespace Application.Web.Controllers.Pub
public async Task<IPoAction> GetUserShip()
{
string userId = StateHelper.userId;
var data = await weightService.GetUserShip(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 });
var weightInfo = await _weightService.GetUserWeightInfo(userId);
var maxShipWeight = await _weightService.GetUserShipMaxWeight(userId);
return PoAction.Ok(new { data, onShip = weightInfo.shipOnWeight, maxShip = maxShipWeight });
}
/// <summary>
@@ -57,46 +41,25 @@ namespace Application.Web.Controllers.Pub
/// <param name="usId"></param>
/// <returns></returns>
[HttpPost]
public async Task<IPoAction> BuyShip([FromBody] BuyShipParms parms)
public async Task<IPoAction> SaleShip([FromBody] BuyShipParms parms)
{
var userShip = await weightService.GetUserShipInfo(parms.usId);
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)
if (await _weightService.DeleteUserShip(userShip.usId, userId))
{
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(userShip.sale), "出售船只获得!"))
{
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("出售失败!");
}
return PoAction.Ok(new { price = userShip.sale });
}
else
{
@@ -109,4 +72,4 @@ namespace Application.Web.Controllers.Pub
}
}
}
}
}