This commit is contained in:
Putoo
2026-07-12 17:36:07 +08:00
parent c40f3711bc
commit 035eb476ea
19 changed files with 932 additions and 22 deletions

View File

@@ -0,0 +1,63 @@
using SqlSugar;
using System;
namespace Application.Domain.Entity
{
[Tenant("Kg.SeaTime.Game")]
public class game_trade
{
/// <summary>
/// tradeId
/// </summary>
[SugarColumn(IsPrimaryKey = true, Length = 50)]
public string tradeId { get; set; }
/// <summary>
/// userId
/// </summary>
[SugarColumn(Length = 50, IsNullable = true)]
public string? userId { get; set; }
/// <summary>
/// code
/// </summary>
[SugarColumn(Length = 50, IsNullable = true)]
public string? code { get; set; }
/// <summary>
/// propId
/// </summary>
[SugarColumn(Length = 50, IsNullable = true)]
public string? propId { get; set; }
/// <summary>
/// name
/// </summary>
[SugarColumn(Length = 50, IsNullable = true)]
public string? name { get; set; }
/// <summary>
/// count
/// </summary>
[SugarColumn(IsNullable = true)]
public int? count { get; set; }
/// <summary>
/// price
/// </summary>
[SugarColumn(IsNullable = true)]
public long? price { get; set; }
/// <summary>
/// content
/// </summary>
[SugarColumn(IsNullable = true)]
public string? content { get; set; }
/// <summary>
/// addTime
/// </summary>
[SugarColumn(IsNullable = true)]
public DateTime? addTime { get; set; }
}
}

View File

@@ -17,6 +17,7 @@ public static class GoodsEnum
ChoicePack,//选择宝箱
Weight,//负重
Gift,//礼物道具
Tease,//整蛊道具
Exp,//经验
State,//状态物品
Ship,//船只

View File

@@ -14,6 +14,8 @@ public interface IGameEquService
Task<List<unit_user_equ>> GetUserEquData(string userId, int type, string equName, int PageIndex, int PageSize,
RefAsync<int> Total, bool isRemOn = false, bool isRemLock = false);
Task<List<unit_user_equ>> GetUserEquData(string userId, int type, string equName, int PageIndex,
int PageSize, RefAsync<int> Total,int DealType);
Task<List<unit_user_equ>> GetUserEquData(string userId, string query);
Task<List<unit_user_equ>> GetUserEquData(string userId, int equId);
Task<List<unit_user_equ>> GetUserEquData(string userId, string code, List<string> noUeId);

View File

@@ -17,6 +17,9 @@ public interface IGameGoodsService
Task<List<unit_user_goods>> GetUserGoodsData(string userId, List<string> code, List<string> noCode, string search, int page,
int limit, RefAsync<int> total);
Task<List<unit_user_goods>> GetUserGoodsData(string userId, List<string> code, List<string> noCode, string search, int page,
int limit, RefAsync<int> total,int DealType);
Task<List<unit_user_goods>> GetUserGoodsData(string userId, string code);
Task<bool> UpdateUserGoods(string userId, int op, int goodsId, int count, string remark = "");

View File

@@ -0,0 +1,7 @@
namespace Application.Domain;
public interface ITradeService
{
Task<bool> AddTrade(string userId, string code,string name, string propId, int count, long price,string content);
Task<int> GetUserTradeCount(string userId);
}

View File

@@ -137,7 +137,7 @@ public class GameChatService : IGameChatService, ITransient
chat.delTime = TimeExtend.GetTimeStampBySeconds(DateTime.Now.AddHours(6));
break;
case "Notice":
chat.delTime = TimeExtend.GetTimeStampBySeconds(DateTime.Now.AddDays(1));
chat.delTime = TimeExtend.GetTimeStampBySeconds(DateTime.Now.AddDays(7));
chat.code = nameof(GameChatEnum.Code.System);
break;
case "Group":

View File

@@ -55,14 +55,32 @@ public class GameEquService(ISqlSugarClient DbClient, IRedisCache redis) : IGame
.OrderByDescending(it => it.lev)
.OrderByDescending(it => it.ueId).ToPageListAsync(PageIndex, PageSize, Total);
}
public async Task<List<unit_user_equ>> GetUserEquData(string userId,string query)
public async Task<List<unit_user_equ>> GetUserEquData(string userId, int type, string equName, int PageIndex,
int PageSize, RefAsync<int> Total,int DealType)
{
long onTime = TimeExtend.GetTimeStampSeconds;
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_equ>();
return await db.Queryable<unit_user_equ>().Where(it =>
it.userId == userId && it.isOn == 0 && it.isLock == 0 &&
it.useEndTime > onTime)
.WhereIF(DealType == 0, it => it.isDeal == 1)
.WhereIF(DealType == 1, it => it.isDeal == 1 && it.isGive == 1)
.WhereIF(!string.IsNullOrEmpty(equName),
it => it.equName.Contains(equName) || it.unitEquName.Contains(equName))
.OrderByDescending(it => it.isOn)
.OrderByDescending(it => it.lev)
.OrderByDescending(it => it.ueId).ToPageListAsync(PageIndex, PageSize, Total);
}
public async Task<List<unit_user_equ>> GetUserEquData(string userId, string query)
{
long onTime = TimeExtend.GetTimeStampSeconds;
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_equ>();
return await db.Queryable<unit_user_equ>().Where(it => it.userId == userId)
.WhereIF(!string.IsNullOrEmpty(query),
it => it.equName.Contains(query) || it.unitEquName.Contains(query))
.ToListAsync();
.ToListAsync();
}
public async Task<List<unit_user_equ>> GetUserEquData(string userId, int equId)
@@ -857,8 +875,8 @@ public class GameEquService(ISqlSugarClient DbClient, IRedisCache redis) : IGame
await EquOnOrDown(item, 0);
}
}
}
#endregion
#region

View File

@@ -70,6 +70,23 @@ public class GameGoodsService(ISqlSugarClient DbClient, IRedisCache redis) : IGa
.ToPageListAsync(page, limit, total);
}
public async Task<List<unit_user_goods>> GetUserGoodsData(string userId, List<string> code, List<string> noCode,
string search, int page,
int limit, RefAsync<int> total, int DealType)
{
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_goods>();
return await db.Queryable<unit_user_goods>().Where(it =>
it.userId == userId && it.count > 0)
.WhereIF(DealType == 0, it => it.isDeal == 1)
.WhereIF(DealType == 1, it => it.isDeal == 1 && it.isGive == 1)
.WhereIF(code.Count > 0, it => code.Contains(it.code))
.WhereIF(noCode.Count > 0, it => !noCode.Contains(it.code))
.WhereIF(!string.IsNullOrEmpty(search), it => it.goodsName.Contains(search))
.OrderBy(it => it.lev, OrderByType.Desc)
.OrderBy(it => it.count, OrderByType.Desc)
.ToPageListAsync(page, limit, total);
}
public async Task<List<unit_user_goods>> GetUserGoodsData(string userId, string code)
{
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_goods>();
@@ -263,7 +280,7 @@ public class GameGoodsService(ISqlSugarClient DbClient, IRedisCache redis) : IGa
{
result = "您已经使用过该药品啦!";
}
if (!string.IsNullOrEmpty(scene))
{
//要判断使用个数
@@ -282,14 +299,16 @@ public class GameGoodsService(ISqlSugarClient DbClient, IRedisCache redis) : IGa
return result;
}
public async Task<string> CheckUseDrug(string userId, int goodsId,string scene = "")
public async Task<string> CheckUseDrug(string userId, int goodsId, string scene = "")
{
string result = string.Empty;
var goodsInfo = await GetGoodsContent(goodsId);
if (!string.IsNullOrEmpty(goodsInfo))
{
result = await CheckUseDrug(userId,goodsId, goodsInfo, scene);
result = await CheckUseDrug(userId, goodsId, goodsInfo, scene);
}
return result;
}
@@ -320,7 +339,8 @@ public class GameGoodsService(ISqlSugarClient DbClient, IRedisCache redis) : IGa
}
else if (_drugConfig.cls == nameof(GoodsEnum.DrugCls.BloodStock))
{
result = await attrService.AddUserStock(userId, goodsId.ToString(), Convert.ToString(_drugConfig.name),Convert.ToString(_drugConfig.type),
result = await attrService.AddUserStock(userId, goodsId.ToString(), Convert.ToString(_drugConfig.name),
Convert.ToString(_drugConfig.type),
Convert.ToString(_drugConfig.code),
Convert.ToInt64(_drugConfig.num), Convert.ToString(_drugConfig.par),
Convert.ToInt32(_drugConfig.minute));
@@ -332,13 +352,14 @@ public class GameGoodsService(ISqlSugarClient DbClient, IRedisCache redis) : IGa
return result;
}
public async Task<bool> UseDrug(string userId, int goodsId, string scene = "")
{
bool result = false;
var goodsInfo = await GetGoodsContent(goodsId);
if (!string.IsNullOrEmpty(goodsInfo))
{
result = await UseDrug(userId,goodsId, goodsInfo, scene);
result = await UseDrug(userId, goodsId, goodsInfo, scene);
}
return result;

View File

@@ -0,0 +1,28 @@
namespace Application.Domain;
public class TradeService(ISqlSugarClient DbClient, IRedisCache redis) : ITradeService, ITransient
{
public async Task<bool> AddTrade(string userId, string code,string name, string propId, int count,long price, string content)
{
game_trade trade = new game_trade()
{
tradeId = StringAssist.NewGuid,
userId = userId,
code = code,
name = name,
propId = propId,
count = count,
price = price,
content = content,
addTime = DateTime.Now
};
var db = DbClient.AsTenant().GetConnectionWithAttr<game_trade>();
return await db.Insertable(trade).ExecuteCommandAsync() > 0;
}
public async Task<int> GetUserTradeCount(string userId)
{
var db = DbClient.AsTenant().GetConnectionWithAttr<game_trade>();
return await db.Queryable<game_trade>().Where(it => it.userId == userId).CountAsync();
}
}

View File

@@ -0,0 +1,148 @@
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
namespace Application.Web.Controllers.Pub;
[Route("[controller]/[action]")]
[ApiController]
[Authorize]
public class TradeController : ControllerBase
{
private readonly IGameGoodsService _goodsService;
private readonly IGameEquService _equService;
private readonly IUnitUserWeight _weightService;
private readonly IUnitUserService _userService;
private readonly IGameChatService _chatService;
private readonly IUnitUserAttrService _attrService;
private readonly ITradeService _tradeService;
public TradeController(IGameGoodsService goodsService, IGameEquService equService, IUnitUserWeight weightService,
IUnitUserService userService, IGameChatService chatService,
IUnitUserAttrService attrService, ITradeService tradeService)
{
_goodsService = goodsService;
_equService = equService;
_weightService = weightService;
_userService = userService;
_chatService = chatService;
_attrService = attrService;
_tradeService = tradeService;
}
/// <summary>
/// 寄售物品
/// </summary>
/// <param name="type"></param>
/// <param name="prop"></param>
/// <param name="price"></param>
/// <returns></returns>
[HttpGet]
public async Task<IPoAction> Trade(int type, string prop, long price, int count)
{
count = count < 1 ? 1 : count;
string userId = StateHelper.userId;
int lev = await _attrService.GetUserLev(userId);
if (lev < 60)
{
return PoAction.Message("60级后才可以寄售物品哦!");
}
var tradeCount = await _tradeService.GetUserTradeCount(userId);
if (tradeCount >= 5)
{
return PoAction.Message("玩家最多同时寄售5件物品哦!");
}
if (type == 0) //装备
{
var equInfo = await _equService.GetUserEquInfo(prop);
if (equInfo == null)
{
return PoAction.Message("装备不存在!");
}
if (equInfo.userId != userId || equInfo.isOn == 1 || equInfo.isLock == 1 || equInfo.isDeal == 0)
{
return PoAction.Message("该装备无法寄售!");
}
long minPrice = (int)equInfo.lev * 100;
if (price < minPrice)
{
return PoAction.Message($"该装备最低寄售价格{minPrice}铜贝!");
}
if (await _equService.DeductUserEqu(userId, [equInfo], "寄售装备"))
{
string data = JsonConvert.SerializeObject(equInfo);
if (await _tradeService.AddTrade(userId, nameof(GameEnum.PropCode.Equ), equInfo.unitEquName,
equInfo.ueId, 1, price, data))
{
return PoAction.Ok(true);
}
else
{
await _equService.AddUserEqu(equInfo, "寄售失败返还!");
return PoAction.Message("寄售失败,请稍后尝试!");
}
}
else
{
return PoAction.Message("寄售失败,请稍后尝试!");
}
}
else if (type == 1) //物品
{
if (count > 99)
{
return PoAction.Message("单次寄售数量最多为99个!");
}
int goodsId = Convert.ToInt32(prop);
var MyGoods = await _goodsService.GetUserGoodsInfo(userId, goodsId);
if (MyGoods == null)
{
return PoAction.Message("物品数量不足!");
}
if (MyGoods.count < count)
{
return PoAction.Message("物品数量不足!");
}
if (MyGoods.isDeal == 0)
{
return PoAction.Message("该物品无法寄售!");
}
long minPrice = (int)MyGoods.lev * 100;
if (price < minPrice)
{
return PoAction.Message($"该物品最低寄售价格{minPrice}铜贝!");
}
if (await _goodsService.UpdateUserGoods(userId, 0, goodsId, count, "寄售物品"))
{
if (await _tradeService.AddTrade(userId, nameof(GameEnum.PropCode.Goods), MyGoods.goodsName, prop,
count, price,
""))
{
return PoAction.Ok(true);
}
else
{
await _goodsService.UpdateUserGoods(userId, 1, goodsId, count, "寄售失败返还!");
return PoAction.Message("寄售失败,请稍后尝试!");
}
}
else
{
return PoAction.Message("寄售失败,请稍后尝试!");
}
}
else
{
return PoAction.Message("该物品不允许寄售!");
}
}
}

View File

@@ -19,10 +19,11 @@ public class GiveController : ControllerBase
private readonly IUnitUserService _userService;
private readonly IGameChatService _chatService;
private readonly IMessageService _messageService;
private readonly IUnitUserAttrService _attrService;
public GiveController(IGameGoodsService goodsService, IGameEquService equService, IUnitUserWeight weightService,
IUnitUserRelationService relationService, IUnitUserService userService, IGameChatService chatService,
IMessageService messageService)
IMessageService messageService,IUnitUserAttrService attrService)
{
_goodsService = goodsService;
_equService = equService;
@@ -31,6 +32,7 @@ public class GiveController : ControllerBase
_userService = userService;
_chatService = chatService;
_messageService = messageService;
_attrService = attrService;
}
/// <summary>
@@ -159,4 +161,286 @@ public class GiveController : ControllerBase
return PoAction.Ok(new { data, total = total.Value });
}
/// <summary>
/// 获取赠送物品列表
/// </summary>
/// <param name="npcId"></param>
/// <param name="type"></param>
/// <param name="query"></param>
/// <param name="page"></param>
/// <returns></returns>
[HttpGet]
public async Task<IPoAction> GetGoodsData(string no, int type, string? query, int page)
{
var fromInfo = await _userService.GetUserInfoByUserNo(no);
if (fromInfo == null)
{
return PoAction.Message("玩家不存在!");
}
string userId = StateHelper.userId;
int areaId = StateHelper.areaId;
if (areaId != fromInfo.areaId)
{
return PoAction.Message("玩家不存在!");
}
RefAsync<int> total = 0;
if (type == 0)
{
var data = await _equService.GetUserEquData(userId, 0, query, page, 10, total, 1);
return PoAction.Ok(new
{
userNo = fromInfo.userNo,
nick = fromInfo.nick, data, total = total.Value
});
}
else if (type == 1)
{
List<string> code = new List<string>() { nameof(GoodsEnum.Code.Drug) };
var data = await _goodsService.GetUserGoodsData(userId, code, new List<string>(), query, page, 10, total,
1);
return PoAction.Ok(new
{
userNo = fromInfo.userNo,
nick = fromInfo.nick, data, total = total.Value
});
}
else if (type == 2)
{
List<string> code = new List<string>();
List<string> noCode = new List<string>() { nameof(GoodsEnum.Code.Drug) };
var data = await _goodsService.GetUserGoodsData(userId, code, noCode, query, page, 10, total, 1);
return PoAction.Ok(new
{
userNo = fromInfo.userNo,
nick = fromInfo.nick, data, total = total.Value
});
}
else
{
return PoAction.Ok(new
{
userNo = fromInfo.userNo,
nick = fromInfo.nick, data = new List<string>(), total = total.Value
});
}
}
/// <summary>
/// 赠送物品
/// </summary>
/// <param name="no"></param>
/// <param name="type"></param>
/// <param name="propId"></param>
/// <param name="count"></param>
/// <returns></returns>
[HttpGet]
public async Task<IPoAction> GiveGoods(string no, int type, string propId, int count)
{
string userId = StateHelper.userId;
int myLev = await _attrService.GetUserLev(userId);
if (myLev < 60)
{
return PoAction.Message("等级达到60级才可以赠送哦!");
}
count = count < 1 ? 1 : count;
var fromInfo = await _userService.GetUserInfoByUserNo(no);
if (fromInfo == null)
{
return PoAction.Message("玩家不存在!");
}
int areaId = StateHelper.areaId;
if (areaId != fromInfo.areaId)
{
return PoAction.Message("玩家不存在!");
}
if (type == 0)
{
var equInfo = await _equService.GetUserEquInfo(propId);
if (equInfo == null)
{
return PoAction.Message("装备不存在!");
}
if (equInfo.userId != userId || equInfo.isOn == 1 || equInfo.isLock == 1)
{
return PoAction.Message("该装备锁定或穿戴中!");
}
if (equInfo.isDeal == 0 || equInfo.isGive == 0)
{
return PoAction.Message("该装备无法交易或不可赠送!");
}
//验证负重
if (await _weightService.CheckUserWeight(fromInfo.userId, (int)equInfo.weight) == false)
{
return PoAction.Message("对方负重不足!");
}
if (await _equService.DeductUserEqu(userId, [equInfo], $"赠送给玩家:{fromInfo.userId}"))
{
equInfo.userId = fromInfo.userId;
if (await _equService.AddUserEqu(equInfo, $"收到赠送,来源玩家:{userId}"))
{
var myInfo = await _userService.GetUserInfoByUserId(userId);
string msg = $"收到[{UbbTool.HomeUbb(myInfo.userNo, myInfo.nick)}]赠送的装备[{equInfo.equName}]";
await _chatService.SendChat(fromInfo.userId, (int)fromInfo.areaId, nameof(GameChatEnum.Code.Notice),
msg);
return PoAction.Ok(true);
}
else
{
return PoAction.Message("赠送失败,请稍后尝试!");
}
}
else
{
return PoAction.Message("赠送失败,请稍后尝试!");
}
}
else if (type == 1 || type == 2)
{
int goodsId = Convert.ToInt32(propId);
var MyGoods = await _goodsService.GetUserGoodsInfo(userId, goodsId);
if (MyGoods == null)
{
return PoAction.Message("物品数量不足!");
}
if (MyGoods.count < count)
{
return PoAction.Message("物品数量不足!");
}
if (MyGoods.isDeal == 0 || MyGoods.isGive == 0)
{
return PoAction.Message("该无法无法交易或不可赠送!");
}
int useWeight = (int)MyGoods.weight * count;
if (await _weightService.CheckUserWeight(fromInfo.userId, useWeight) == false)
{
return PoAction.Message("对方负重不足!");
}
if (await _goodsService.UpdateUserGoods(userId, 0, goodsId, count, $"赠送给玩家:{fromInfo.userId}"))
{
if (await _goodsService.UpdateUserGoods(fromInfo.userId, 1, goodsId, count, $"收到赠送,来源玩家:{userId}"))
{
var myInfo = await _userService.GetUserInfoByUserId(userId);
string msg = $"收到[{UbbTool.HomeUbb(myInfo.userNo, myInfo.nick)}]赠送的物品[{MyGoods.goodsName}]×{count}";
await _chatService.SendChat(fromInfo.userId, (int)fromInfo.areaId, nameof(GameChatEnum.Code.Notice),
msg);
return PoAction.Ok(true);
}
else
{
return PoAction.Message("赠送失败,请稍后尝试");
}
}
else
{
return PoAction.Message("赠送失败,请稍后尝试");
}
}
else
{
return PoAction.Message("赠送失败,请稍后尝试");
}
}
/// <summary>
/// 逗一下物品列表
/// </summary>
/// <param name="no"></param>
/// <returns></returns>
[HttpGet]
public async Task<IPoAction> GetUserDouGoods(string no)
{
var fromInfo = await _userService.GetUserInfoByUserNo(no);
if (fromInfo == null)
{
return PoAction.Message("玩家不存在!");
}
string userId = StateHelper.userId;
int areaId = StateHelper.areaId;
if (areaId != fromInfo.areaId)
{
return PoAction.Message("玩家不存在!");
}
var data = await _goodsService.GetUserGoodsData(userId, nameof(GoodsEnum.Code.Tease));
return PoAction.Ok(new
{
userNo = fromInfo.userNo,
nick = fromInfo.nick,
data = data
});
}
/// <summary>
/// 使用逗物品
/// </summary>
/// <param name="no"></param>
/// <param name="goodsId"></param>
/// <param name="count"></param>
/// <returns></returns>
[HttpGet]
public async Task<IPoAction> UseDou(string no,int goodsId, int count)
{
var fromInfo = await _userService.GetUserInfoByUserNo(no);
if (fromInfo == null)
{
return PoAction.Message("玩家不存在!");
}
string userId = StateHelper.userId;
int areaId = StateHelper.areaId;
if (areaId != fromInfo.areaId)
{
return PoAction.Message("玩家不存在!");
}
count = count < 1 ? 1 : count;
var myGoods = await _goodsService.GetUserGoodsInfo(userId, goodsId);
if (myGoods == null)
{
return PoAction.Message("您暂无该道具!");
}
if (myGoods.count < count)
{
return PoAction.Message("您的道具不足!");
}
if (myGoods.code != nameof(GoodsEnum.Code.Tease))
{
return PoAction.Message("该道具无法使用!");
}
if (await _goodsService.UpdateUserGoods(userId, 0, goodsId, count, "使用道具"))
{
var goodsInfo = await _goodsService.GetGoodsInfo(goodsId);
UserStateModel stateConfig = JsonConvert.DeserializeObject<UserStateModel>(goodsInfo.content);
if(await _attrService.AddUserState(fromInfo.userId, goodsInfo.goodsId.ToString(), stateConfig.name,
stateConfig.scene, stateConfig.tips, stateConfig.attr, stateConfig.time, count))
{
var myInfo = await _userService.GetUserInfoByUserId(userId);
string msg = $"[{UbbTool.HomeUbb(myInfo.userNo, myInfo.nick)}]对您使用了[{goodsInfo.goodsName}]×{count}";
await _chatService.SendChat(fromInfo.userId, (int)fromInfo.areaId, nameof(GameChatEnum.Code.Notice),
msg);
}
return PoAction.Ok(true);
}
else
{
return PoAction.Message("使用失败,请稍后尝试!");
}
}
}