增加船只接口

This commit is contained in:
LN
2026-06-13 18:05:55 +08:00
parent f6323aba8e
commit a68368d227
13 changed files with 475 additions and 75 deletions

View File

@@ -0,0 +1,75 @@
using SqlSugar;
using System;
namespace Application.Domain.Entity
{
[Tenant("Kg.SeaTime.Resource")]
public class game_ship
{
/// <summary>
/// shipId
/// </summary>
[SugarColumn(IsPrimaryKey = true, Length = 50)]
public int shipId { get; set; }
/// <summary>
/// npc
/// </summary>
[SugarColumn(IsNullable = true)]
public int? npc { get; set; }
/// <summary>
/// shipName
/// </summary>
[SugarColumn(Length = 50, IsNullable = true)]
public string shipName { get; set; }
/// <summary>
/// img
/// </summary>
[SugarColumn(Length = 50, IsNullable = true)]
public string img { get; set; }
/// <summary>
/// price
/// </summary>
[SugarColumn(Length = 18, IsNullable = true)]
public decimal? price { get; set; }
/// <summary>
/// salePrice
/// </summary>
[SugarColumn(Length = 18, IsNullable = true)]
public decimal? salePrice { get; set; }
/// <summary>
/// payType
/// </summary>
[SugarColumn(Length = 50, IsNullable = true)]
public string payType { get; set; }
/// <summary>
/// weight
/// </summary>
[SugarColumn(IsNullable = true)]
public int? weight { get; set; }
/// <summary>
/// speed
/// </summary>
[SugarColumn(IsNullable = true)]
public int? speed { get; set; }
/// <summary>
/// neeGold
/// </summary>
[SugarColumn(IsNullable = true)]
public int? neeGold { get; set; }
/// <summary>
/// remark
/// </summary>
[SugarColumn(Length = 50, IsNullable = true)]
public string remark { get; set; }
}
}

View File

@@ -28,4 +28,8 @@ public interface IGameGoodsService
#endregion
#region
Task<game_ship> GetShipInfo(int shipId);
#endregion
}

View File

@@ -13,7 +13,7 @@ public interface IUnitUserWeight
Task<bool> CheckUserWeight(string userId, int useWeight);
#region
Task<unit_user_ship> GetUserShipInfo(string usId);
Task<List<unit_user_ship>> GetUserShip(string userId);
Task<int> GetUserShipMaxWeight(string userId);
Task<bool> UpdateUserShipOnWeight(string userId, int op, int weight);

View File

@@ -186,4 +186,20 @@ public class GameGoodsService(ISqlSugarClient DbClient, IRedisCache redis) : IGa
}
#endregion
#region
public async Task<game_ship> GetShipInfo(int shipId)
{
string key = string.Format(BaseCache.BaseCacheKey, "ShipData");
var data = await redis.GetHashAsync<game_ship>(key, shipId.ToString());
if (data == null)
{
var db = DbClient.AsTenant().GetConnectionWithAttr<game_ship>();
data = await db.Queryable<game_ship>().Where(it => it.shipId == shipId).SingleAsync();
await redis.AddHashAsync(key, shipId.ToString(), data);
}
return data;
}
#endregion
}

View File

@@ -119,7 +119,19 @@ public class UnitUserWeight(ISqlSugarClient DbClient, IRedisCache redis) : IUnit
}
#region
public async Task<unit_user_ship> GetUserShipInfo(string usId)
{
string key = string.Format(UserCache.BaseCacheKeys, "UserShip", "Info");
var data = await redis.GetHashAsync<unit_user_ship>(key, usId);
if (data == null)
{
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_ship>();
data = await db.Queryable<unit_user_ship>().Where(it => it.usId == usId).SingleAsync();
await redis.AddHashAsync(key, usId, data);
}
return data;
}
public async Task<List<unit_user_ship>> GetUserShip(string userId)
{
string key = string.Format(UserCache.BaseCacheKeys, "WeightData", "Ship");

View File

@@ -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>

View 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("船只出售失败!");
}
}
}
}

View File

@@ -0,0 +1,9 @@
using Microsoft.AspNetCore.Mvc;
namespace Application.Web
{
public class BuyShipParms
{
public string usId { get; set; }
}
}

View File

@@ -75,6 +75,8 @@
</template>
<script setup lang="ts">
import { StateHelper } from '../composables/StateHelper';
definePageMeta({
layout: layout.empty,

View File

@@ -25,18 +25,18 @@
</div>
</template>
<script setup lang="ts">
definePageMeta({
definePageMeta({
layout: layout.empty,
middleware: middleware.loading
})
})
const nick = ref('');
const sex = ref(0);
const code = ref('');
const isNeedCode = ref(false);
const data = ref<any>({});
const nick = ref('');
const sex = ref(0);
const code = ref('');
const isNeedCode = ref(false);
const data = ref<any>({});
const SubRegInfo = async (): Promise<void> => {
const SubRegInfo = async () : Promise<void> => {
if (nick.value == null || nick.value == '') {
MessageExtend.ShowToast("昵称不能为空!", "default");
return;
@@ -50,19 +50,19 @@ const SubRegInfo = async (): Promise<void> => {
else {
MessageExtend.ShowDialog("注册角色", result.msg);
}
}
}
onMounted(async () => {
onMounted(async () => {
try {
await BindData();
}
finally {
PageLoading.Close();
}
})
})
const BindData = async () => {
const BindData = async () => {
let result = await PubService.GetOnAreaInfo();
if (result.code == 0) {
data.value = result.data;
@@ -74,5 +74,5 @@ const BindData = async () => {
});
}
}
}
</script>

View File

@@ -1 +1,58 @@
<template></template>
<template>
<div class="content">特殊属性</div>
<div class="content">
<span>幸运:0%</span>&nbsp;&nbsp;&nbsp;<span>爆率:0%</span><br>
<span>升空:0</span>&nbsp;&nbsp;&nbsp;<span>下潜:0</span>
</div>
<div class="content">经验铜贝</div>
<div class="content">
<span>普通经验:0%</span>&nbsp;&nbsp;&nbsp;<span>副本经验:0%</span><br>
<span>铜贝增益:0%</span>
</div>
<div class="content">基础属性</div>
<div class="content">
<span>吸血:{{data.inBlood * 100}}%</span>&nbsp;&nbsp;&nbsp;<span>制裁:{{data.punish * 100}}%</span><br>
<span>暴击:{{data.crit * 100}}%</span>&nbsp;&nbsp;&nbsp;<span>闪避:{{data.dodge * 100}}%</span><br>
<span>免伤:{{data.noHarm * 100}}%</span>&nbsp;&nbsp;&nbsp;<span>额外伤害:{{data.harm_Add}}</span><br>
<span>反弹:{{data.rebound * 100}}%</span>&nbsp;&nbsp;&nbsp;<span>抗反弹:{{data.reboundLess * 100}}%</span><br>
<span>迟缓:{{data.slow * 100}}%</span>&nbsp;&nbsp;&nbsp;<span>抗迟缓:{{data.slowLess * 100}}%</span><br>
<span>中毒:{{data.poison * 100}}%</span>&nbsp;&nbsp;&nbsp;<span>抗中毒:{{data.poisonLess * 100}}%</span><br>
<span>诅咒:{{data.curse * 100}}%</span>&nbsp;&nbsp;&nbsp;<span>抗诅咒:{{data.curseLess * 100}}%</span><br>
<span>弱化:{{data.weaken * 100}}%</span>&nbsp;&nbsp;&nbsp;<span>抗弱化:{{data.weakenLess * 100}}%</span><br>
<span>致命:{{data.deadly * 100}}%</span>&nbsp;&nbsp;&nbsp;<span>抗致命:{{data.deadlyLess * 100}}%</span><br>
<span>沮丧:{{data.depressed * 100}}%</span>&nbsp;&nbsp;&nbsp;<span>抗沮丧:{{data.depressedLess * 100}}%</span><br>
<span>突破:{{data.breach * 100}}%</span>&nbsp;&nbsp;&nbsp;<span>抗突破:{{data.breachLess * 100}}%</span><br>
<span>麻痹:{{data.palsyAtk * 100}}%</span>&nbsp;&nbsp;&nbsp;<span>抗麻痹:{{data.palsyAtkLess * 100}}%</span><br>
<span>卸时装:{{data.del_Fashion * 100}}%</span>&nbsp;&nbsp;&nbsp;<span>连击:{{data.atk_Next * 100}}%</span><br>
</div>
</template>
<script setup lang="ts">
import { UserService } from '../../services/user/UserService';
definePageMeta({
layout: layout.default,
middleware: middleware.loading
})
const data = ref<any>([]);
onMounted(async () => {
try {
await BindData();
}
finally {
PageLoading.Close();
}
})
const BindData = async () => {
let result = await UserService.GetUserBaseAttrInfo();
if (result.code == 0) {
data.value = result.data;
console.log(data)
}
else {
MessageExtend.ShowDialog("特性", result.msg);
}
}
</script>

View File

@@ -1 +1,88 @@
<template></template>
<template>
<div class="content">我的船队</div>
<div class="content">现负重/总负重({{weight.onWeight}}/{{weight.maxWeight}}):</div>
<div class="content">
<div class="item" v-for="(item,index) in data" :key="index">
{{index+1}}.<Abutton @click="showView(item)">{{item.name}}</Abutton>
<Abutton @click="buyShip(item)">卖出</Abutton>
</div>
<span v-if="data.length==0">暂无船只,请通过Npc购买!</span>
</div>
<div class="content" v-if="data.length > 0">
<span>每人最多拥有5只船只哦!</span>
</div>
<GamePopup v-model:show="showInfo" title="【船只说明】" style="width: 50%;">
<!-- 自定义内容 -->
<div class="content">
名称:{{shipInfo.shipName}}<br>
介绍:{{shipInfo.remark}}<br>
载重:{{shipInfo.weight}}<br>
卖出价格:{{shipInfo.salePrice}}{{ GameTool.GetCurrencyName(shipInfo.payType) }}<br>
时速:{{shipInfo.speed}}<br>
消耗:{{shipInfo.neeGold}}铜贝//百海里<br>
</div>
</GamePopup>
</template>
<script setup lang="ts">
definePageMeta({
layout: layout.default,
middleware: middleware.loading
})
const data = ref<Array<any>>([]);
const weight = ref<any>({});
const showInfo = ref(false);
const onShow = ref<any>({});
const shipInfo = ref<any>({});
onMounted(async () => {
try {
await BindData();
}
finally {
PageLoading.Close();
}
})
const BindData = async () => {
let result = await ShipService.GetShipData();
if (result.code == 0) {
data.value = result.data.data;
weight.value = result.data.weightInfo;
}
else {
MessageExtend.ShowDialog("船队", result.msg);
}
}
const GetShipInfo = async (shipId : string) => {
let result = await ShipService.GetShipInfo(shipId);
if (result.code == 0) {
shipInfo.value = result.data.data;
console.log(shipInfo.value)
}
else {
MessageExtend.ShowDialog("船只详情", result.msg);
}
}
const showView = (data : any) => {
GetShipInfo(data.goodsId)
showInfo.value = true;
onShow.value = data;
}
const buyShip = async (data : any) => {
MessageExtend.ShowConfirmDialogAsyc("船只操作", `您确定要出售船只吗?`, async () => {
let result = await ShipService.BuyShip(data.usId);
if (result.code == 0) {
MessageExtend.Notify("出售成功,获得" + data.copper + "铜贝", "success");
await BindData();
}
else {
MessageExtend.ShowDialog("船只详情", result.msg);
}
return true;
});
}
</script>

View File

@@ -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 });
}
}