增加船只接口
This commit is contained in:
@@ -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>
|
||||
112
Service/Application.Web/Controllers/Pub/ShipController.cs
Normal file
112
Service/Application.Web/Controllers/Pub/ShipController.cs
Normal 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("船只出售失败!");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace Application.Web
|
||||
{
|
||||
public class BuyShipParms
|
||||
{
|
||||
public string usId { get; set; }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user