75 lines
2.3 KiB
C#
75 lines
2.3 KiB
C#
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 IUnitUserAccService _accService;
|
|
|
|
public ShipController(IUnitUserWeight weightService,
|
|
IUnitUserAccService accService)
|
|
{
|
|
_accService = accService;
|
|
_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);
|
|
var maxShipWeight = await _weightService.GetUserShipMaxWeight(userId);
|
|
return PoAction.Ok(new { data, onShip = weightInfo.shipOnWeight, maxShip = maxShipWeight });
|
|
}
|
|
|
|
/// <summary>
|
|
/// 出售船只
|
|
/// </summary>
|
|
/// <param name="usId"></param>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
public async Task<IPoAction> 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("船只出售失败!");
|
|
}
|
|
}
|
|
}
|
|
} |