From a68368d2272dc2ab7f8971c763b0fedf2286a3f1 Mon Sep 17 00:00:00 2001 From: LN <2826967552@qq.com> Date: Sat, 13 Jun 2026 18:05:55 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=88=B9=E5=8F=AA=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../resource/game/game_ship.cs | 75 ++++++++++ .../Interface/Goods/IGameGoodsService.cs | 6 +- .../Interface/User/IUnitUserWeight.cs | 2 +- .../Service/Goods/GameGoodsService.cs | 18 ++- .../Services/Service/User/UnitUserWeight.cs | 12 ++ .../Application.Web.csproj.user | 4 +- .../Controllers/Pub/ShipController.cs | 112 +++++++++++++++ .../Model/RequestParms/Ship/BuyShipParms.cs | 9 ++ Web/src/pages/index.vue | 2 + Web/src/pages/login/register.vue | 136 +++++++++--------- Web/src/pages/user/attr.vue | 59 +++++++- Web/src/pages/user/ship/index.vue | 89 +++++++++++- Web/src/services/Index/ShipService.ts | 26 ++++ 13 files changed, 475 insertions(+), 75 deletions(-) create mode 100644 Service/Application.Domain.Entity/resource/game/game_ship.cs create mode 100644 Service/Application.Web/Controllers/Pub/ShipController.cs create mode 100644 Service/Application.Web/Model/RequestParms/Ship/BuyShipParms.cs create mode 100644 Web/src/services/Index/ShipService.ts diff --git a/Service/Application.Domain.Entity/resource/game/game_ship.cs b/Service/Application.Domain.Entity/resource/game/game_ship.cs new file mode 100644 index 0000000..c4554cf --- /dev/null +++ b/Service/Application.Domain.Entity/resource/game/game_ship.cs @@ -0,0 +1,75 @@ +using SqlSugar; +using System; + +namespace Application.Domain.Entity +{ + [Tenant("Kg.SeaTime.Resource")] + public class game_ship + { + /// + /// shipId + /// + [SugarColumn(IsPrimaryKey = true, Length = 50)] + public int shipId { get; set; } + + /// + /// npc + /// + [SugarColumn(IsNullable = true)] + public int? npc { get; set; } + + /// + /// shipName + /// + [SugarColumn(Length = 50, IsNullable = true)] + public string shipName { get; set; } + + /// + /// img + /// + [SugarColumn(Length = 50, IsNullable = true)] + public string img { get; set; } + + /// + /// price + /// + [SugarColumn(Length = 18, IsNullable = true)] + public decimal? price { get; set; } + + /// + /// salePrice + /// + [SugarColumn(Length = 18, IsNullable = true)] + public decimal? salePrice { get; set; } + + /// + /// payType + /// + [SugarColumn(Length = 50, IsNullable = true)] + public string payType { get; set; } + + /// + /// weight + /// + [SugarColumn(IsNullable = true)] + public int? weight { get; set; } + + /// + /// speed + /// + [SugarColumn(IsNullable = true)] + public int? speed { get; set; } + + /// + /// neeGold + /// + [SugarColumn(IsNullable = true)] + public int? neeGold { get; set; } + + /// + /// remark + /// + [SugarColumn(Length = 50, IsNullable = true)] + public string remark { get; set; } + } +} diff --git a/Service/Application.Domain/Services/Interface/Goods/IGameGoodsService.cs b/Service/Application.Domain/Services/Interface/Goods/IGameGoodsService.cs index fe0d91c..a537a8e 100644 --- a/Service/Application.Domain/Services/Interface/Goods/IGameGoodsService.cs +++ b/Service/Application.Domain/Services/Interface/Goods/IGameGoodsService.cs @@ -15,7 +15,7 @@ public interface IGameGoodsService Task GetUserGoodsInfo(string userId, int goodsId); Task GetUserGoodsCount(string userId, int goodsId); - Task> GetUserGoodsData(string userId, List code, List noCode, string search, int page, + Task> GetUserGoodsData(string userId, List code, List noCode, string search, int page, int limit, RefAsync total); Task> GetUserGoodsData(string userId, string code); @@ -28,4 +28,8 @@ public interface IGameGoodsService #endregion + + #region 船只 + Task GetShipInfo(int shipId); + #endregion } \ No newline at end of file diff --git a/Service/Application.Domain/Services/Interface/User/IUnitUserWeight.cs b/Service/Application.Domain/Services/Interface/User/IUnitUserWeight.cs index ae01546..b33d4bd 100644 --- a/Service/Application.Domain/Services/Interface/User/IUnitUserWeight.cs +++ b/Service/Application.Domain/Services/Interface/User/IUnitUserWeight.cs @@ -13,7 +13,7 @@ public interface IUnitUserWeight Task CheckUserWeight(string userId, int useWeight); #region 船只相关 - + Task GetUserShipInfo(string usId); Task> GetUserShip(string userId); Task GetUserShipMaxWeight(string userId); Task UpdateUserShipOnWeight(string userId, int op, int weight); diff --git a/Service/Application.Domain/Services/Service/Goods/GameGoodsService.cs b/Service/Application.Domain/Services/Service/Goods/GameGoodsService.cs index a73d7e4..25bd294 100644 --- a/Service/Application.Domain/Services/Service/Goods/GameGoodsService.cs +++ b/Service/Application.Domain/Services/Service/Goods/GameGoodsService.cs @@ -163,7 +163,7 @@ public class GameGoodsService(ISqlSugarClient DbClient, IRedisCache redis) : IGa return await db.Insertable(bagLog).SplitTable().ExecuteCommandAsync() > 0; } - + #endregion @@ -186,4 +186,20 @@ public class GameGoodsService(ISqlSugarClient DbClient, IRedisCache redis) : IGa } #endregion + + #region 船只 + public async Task GetShipInfo(int shipId) + { + string key = string.Format(BaseCache.BaseCacheKey, "ShipData"); + var data = await redis.GetHashAsync(key, shipId.ToString()); + if (data == null) + { + var db = DbClient.AsTenant().GetConnectionWithAttr(); + data = await db.Queryable().Where(it => it.shipId == shipId).SingleAsync(); + await redis.AddHashAsync(key, shipId.ToString(), data); + } + + return data; + } + #endregion } \ No newline at end of file diff --git a/Service/Application.Domain/Services/Service/User/UnitUserWeight.cs b/Service/Application.Domain/Services/Service/User/UnitUserWeight.cs index 48b59b2..cf771a9 100644 --- a/Service/Application.Domain/Services/Service/User/UnitUserWeight.cs +++ b/Service/Application.Domain/Services/Service/User/UnitUserWeight.cs @@ -119,7 +119,19 @@ public class UnitUserWeight(ISqlSugarClient DbClient, IRedisCache redis) : IUnit } #region 船只相关 + public async Task GetUserShipInfo(string usId) + { + string key = string.Format(UserCache.BaseCacheKeys, "UserShip", "Info"); + var data = await redis.GetHashAsync(key, usId); + if (data == null) + { + var db = DbClient.AsTenant().GetConnectionWithAttr(); + data = await db.Queryable().Where(it => it.usId == usId).SingleAsync(); + await redis.AddHashAsync(key, usId, data); + } + return data; + } public async Task> GetUserShip(string userId) { string key = string.Format(UserCache.BaseCacheKeys, "WeightData", "Ship"); diff --git a/Service/Application.Web/Application.Web.csproj.user b/Service/Application.Web/Application.Web.csproj.user index 2c8f5c1..031db34 100644 --- a/Service/Application.Web/Application.Web.csproj.user +++ b/Service/Application.Web/Application.Web.csproj.user @@ -2,7 +2,7 @@ https - ApiControllerEmptyScaffolder - root/Common/Api + MvcControllerEmptyScaffolder + root/Common/MVC/Controller \ No newline at end of file diff --git a/Service/Application.Web/Controllers/Pub/ShipController.cs b/Service/Application.Web/Controllers/Pub/ShipController.cs new file mode 100644 index 0000000..e2fcb7c --- /dev/null +++ b/Service/Application.Web/Controllers/Pub/ShipController.cs @@ -0,0 +1,112 @@ +using Microsoft.AspNetCore.Mvc; + +namespace Application.Web.Controllers.Pub +{ + /// + /// 船队接口 + /// + [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; + } + + /// + /// 获取用户船只 + /// + /// + [HttpGet] + public async Task GetUserShip() + { + string userId = StateHelper.userId; + var data = await weightService.GetUserShip(userId); + //个人负重 + var weightInfo = await weightService.GetUserWeightInfo(userId); + return PoAction.Ok(new { data, weightInfo }); + } + + /// + /// 获取船只详情 + /// + /// + /// + [HttpGet] + public async Task GetShipInfo(int shipId) + { + var data = await goodsService.GetShipInfo(shipId); + if (data == null) + { + return PoAction.Message("船只详情不存在!"); + } + + return PoAction.Ok(new { data }); + } + + /// + /// 出售船只 + /// + /// + /// + [HttpPost] + public async Task 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("船只出售失败!"); + } + } + } +} diff --git a/Service/Application.Web/Model/RequestParms/Ship/BuyShipParms.cs b/Service/Application.Web/Model/RequestParms/Ship/BuyShipParms.cs new file mode 100644 index 0000000..5b897ab --- /dev/null +++ b/Service/Application.Web/Model/RequestParms/Ship/BuyShipParms.cs @@ -0,0 +1,9 @@ +using Microsoft.AspNetCore.Mvc; + +namespace Application.Web +{ + public class BuyShipParms + { + public string usId { get; set; } + } +} diff --git a/Web/src/pages/index.vue b/Web/src/pages/index.vue index bd5c152..33c05f7 100644 --- a/Web/src/pages/index.vue +++ b/Web/src/pages/index.vue @@ -75,6 +75,8 @@ \ No newline at end of file diff --git a/Web/src/pages/user/attr.vue b/Web/src/pages/user/attr.vue index 41a40c8..e7910ec 100644 --- a/Web/src/pages/user/attr.vue +++ b/Web/src/pages/user/attr.vue @@ -1 +1,58 @@ - \ No newline at end of file + + \ No newline at end of file diff --git a/Web/src/pages/user/ship/index.vue b/Web/src/pages/user/ship/index.vue index 41a40c8..0061996 100644 --- a/Web/src/pages/user/ship/index.vue +++ b/Web/src/pages/user/ship/index.vue @@ -1 +1,88 @@ - \ No newline at end of file + + \ No newline at end of file diff --git a/Web/src/services/Index/ShipService.ts b/Web/src/services/Index/ShipService.ts new file mode 100644 index 0000000..9ce7b6c --- /dev/null +++ b/Web/src/services/Index/ShipService.ts @@ -0,0 +1,26 @@ +export class ShipService { + /** + * 获取船队列表 + * GET /Ship/GetUserShip + */ + static async GetShipData() { + return await ApiService.Request("get", "/Ship/GetUserShip"); + } + + /** + * 获取船只详情 + * GET /Ship/GetShipInfo + */ + static async GetShipInfo(shipId : string) { + return await ApiService.Request("get", "/Ship/GetShipInfo", { shipId }); + } + + + /** + * 出售船只 + * GET /Ship/BuyShip + */ + static async BuyShip(usId : string) { + return await ApiService.Request("post", "/Ship/BuyShip", { usId }); + } +} \ No newline at end of file