This commit is contained in:
Putoo
2026-07-11 18:52:38 +08:00
parent dec8c2e076
commit c40f3711bc
27 changed files with 577 additions and 18 deletions

View File

@@ -0,0 +1,162 @@
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
namespace Application.Web.Controllers.User;
/// <summary>
/// 赠送接口
/// </summary>
[ApiExplorerSettings(GroupName = "User")]
[Route("User/[controller]/[action]")]
[ApiController]
[Authorize]
public class GiveController : ControllerBase
{
private readonly IGameGoodsService _goodsService;
private readonly IGameEquService _equService;
private readonly IUnitUserWeight _weightService;
private readonly IUnitUserRelationService _relationService;
private readonly IUnitUserService _userService;
private readonly IGameChatService _chatService;
private readonly IMessageService _messageService;
public GiveController(IGameGoodsService goodsService, IGameEquService equService, IUnitUserWeight weightService,
IUnitUserRelationService relationService, IUnitUserService userService, IGameChatService chatService,
IMessageService messageService)
{
_goodsService = goodsService;
_equService = equService;
_weightService = weightService;
_relationService = relationService;
_userService = userService;
_chatService = chatService;
_messageService = messageService;
}
/// <summary>
/// 获取赠送礼物物品
/// </summary>
/// <param name="no"></param>
/// <returns></returns>
[HttpGet]
public async Task<IPoAction> GetUserGiftGoods(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.Gift));
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> ToGift(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 goodsInfo = await _goodsService.GetUserGoodsInfo(userId, goodsId);
if (goodsInfo.code != nameof(GoodsEnum.Code.Gift))
{
return PoAction.Message("该道具无法赠送!");
}
if (goodsInfo.count < count)
{
return PoAction.Message("您礼物数量不足!");
}
if (await _goodsService.UpdateUserGoods(userId, 0, goodsId, count, "赠送礼物"))
{
var goods = await _goodsService.GetGoodsInfo(goodsId);
dynamic giftConfig = JsonConvert.DeserializeObject<dynamic>(goods.content);
int charm = Convert.ToInt32(giftConfig.charm);
int isBroad = Convert.ToInt32(giftConfig.isBroad);
int broadCount = Convert.ToInt32(giftConfig.broadCount);
string gifUbb = UbbTool.GiftUbb(goods.img, goods.goodsName);
if (await _relationService.AddCharm(fromInfo.userId, userId, goodsId, goods.goodsName, goods.img, charm,
count))
{
var myInfo = await _userService.GetUserInfoByUserId(userId);
string noticeMsg = $"[{UbbTool.HomeUbb(myInfo.userNo, myInfo.nick)}]赠送您{gifUbb}×{count}!";
await _chatService.SendChat(fromInfo.userId, nameof(GameChatEnum.Code.Notice), noticeMsg);
if (isBroad == 1 && count >= broadCount)
{
//发送系统广布
string tip =
$"赠送给[{UbbTool.HomeUbb(fromInfo.userNo, fromInfo.nick)}] {gifUbb} {UbbTool.GiveGiftStr(count)}";
await _messageService.SendBroadcast(userId, nameof(MessageEnum.BroadcastCode.Gift), tip);
}
return PoAction.Ok(true);
}
else
{
return PoAction.Message("赠送失败,请稍后尝试!");
}
}
else
{
return PoAction.Message("赠送失败,请稍后尝试!");
}
}
/// <summary>
/// 获取礼物记录
/// </summary>
/// <param name="no"></param>
/// <param name="page"></param>
/// <returns></returns>
[HttpGet]
public async Task<IPoAction> GetGiftLog(string? no, int page)
{
string userId = StateHelper.userId;
if (!string.IsNullOrEmpty(no))
{
var noInfo = await _userService.GetUserInfoByUserNo(no);
if (noInfo != null)
{
userId = noInfo.userId;
}
}
RefAsync<int> total = 0;
var data = await _relationService.GetUserGiftLog(userId, page, 10, total);
return PoAction.Ok(new { data, total = total.Value });
}
}

View File

@@ -55,11 +55,18 @@ public class UserController : ControllerBase
var vigourInfo = await _attrService.GetUserVigourInfo(userId);
var accInfo = await _accService.GetUserAccInfo(userId);
var userDataInfo = await _accService.GetUserDataInfo(userId);
object acc = new { accInfo.gold, accInfo.cowry, userDataInfo.teach, userDataInfo.renown,userDataInfo.enemy };
object acc = new { accInfo.gold, accInfo.cowry, userDataInfo.teach, userDataInfo.renown, userDataInfo.enemy };
var buff = await _attrService.GetUserStateData(userId, "ALL");
var stock = await _attrService.GetUserStock(userId);
object result = new { user, attr = attrInfo, exp, vigourInfo.vitality, acc, buff, stock };
string gift = string.Empty;
var giftData = await _relationService.GetUserNewGift(userId);
if (!string.IsNullOrEmpty(giftData.logId))
{
gift = $"收到{giftData.name}";
}
object result = new { user, attr = attrInfo, exp, vigourInfo.vitality, acc, buff, stock,gift };
return PoAction.Ok(result);
}
@@ -176,7 +183,7 @@ public class UserController : ControllerBase
object user = new { userInfo.userNo, userInfo.nick, userInfo.sex, userInfo.sign };
var attrInfo = await _attrService.GetUserAttrModel(userInfo.userId); //基础属性
var accInfo = await _accService.GetUserDataInfo(userInfo.userId);
object acc = new { accInfo.teach,accInfo.enemy };
object acc = new { accInfo.teach, accInfo.enemy };
var online = await _mapService.GetUserOnMap(userInfo.userId);
int isOnline = online.upTime >
@@ -192,11 +199,17 @@ public class UserController : ControllerBase
var equ = await _equService.GetUserOnEqu(userInfo.userId);
var suit = await _equService.GetUserEquSuit(userInfo.userId);
string gift = string.Empty;
var giftData = await _relationService.GetUserNewGift(userInfo.userId);
if (!string.IsNullOrEmpty(giftData.logId))
{
gift = $"收到{giftData.name}";
}
var isPk = await UserStateTool.CheckPkState(userId, userInfo.userId, isEnemy, isAtArea);
object result = new
{
user, attr = new { attrInfo.lev }, acc, isOnline, onMapName, isFriend, isEnemy, team, equ, suit,isPk
user, attr = new { attrInfo.lev }, acc, isOnline, onMapName, isFriend, isEnemy, team, equ, suit, gift, isPk
};
return PoAction.Ok(result);
}