121212
This commit is contained in:
148
Service/Application.Web/Controllers/Pub/TradeController.cs
Normal file
148
Service/Application.Web/Controllers/Pub/TradeController.cs
Normal 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("该物品不允许寄售!");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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("使用失败,请稍后尝试!");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user