using Microsoft.AspNetCore.Mvc;
namespace Application.Web.Controllers.Pub
{
///
/// 船队接口
///
[Route("[controller]/[action]")]
[ApiController]
[Authorize]
public class ShipController : ControllerBase
{
private readonly IUnitUserWeight _weightService;
private readonly IUnitUserAccService _accService;
public ShipController(IUnitUserWeight weightService,
IUnitUserAccService accService)
{
_accService = accService;
_weightService = weightService;
}
///
/// 获取用户船只
///
///
[HttpGet]
public async Task GetUserShip()
{
string userId = StateHelper.userId;
var data = await _weightService.GetUserShip(userId);
//个人负重
var weightInfo = await _weightService.GetUserWeightInfo(userId);
var maxShipWeight = await _weightService.GetUserShipMaxWeight(userId);
return PoAction.Ok(new { data, onShip = weightInfo.shipOnWeight, maxShip = maxShipWeight });
}
///
/// 出售船只
///
///
///
[HttpPost]
public async Task SaleShip([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("船只不存在!");
}
if (await _weightService.DeleteUserShip(userShip.usId, userId))
{
if (await _accService.UpdateUserCopper(userId, 1, Convert.ToInt64(userShip.sale), "出售船只获得!"))
{
return PoAction.Ok(new { price = userShip.sale });
}
else
{
return PoAction.Message("出售失败!");
}
}
else
{
return PoAction.Message("船只出售失败!");
}
}
}
}