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,69 @@
using SqlSugar;
using System;
namespace Application.Domain.Entity
{
[Tenant("Kg.SeaTime.Log")]
public class game_charm_log
{
/// <summary>
/// logId
/// </summary>
[SugarColumn(IsPrimaryKey = true, Length = 50)]
public string logId { get; set; }
/// <summary>
/// userId
/// </summary>
[SugarColumn(Length = 50, IsNullable = true)]
public string? userId { get; set; }
/// <summary>
/// fromId
/// </summary>
[SugarColumn(Length = 50, IsNullable = true)]
public string? fromId { get; set; }
/// <summary>
/// goodsId
/// </summary>
[SugarColumn(IsNullable = true)]
public Int32? goodsId { get; set; }
/// <summary>
/// name
/// </summary>
[SugarColumn(Length = 50, IsNullable = true)]
public string? name { get; set; }
/// <summary>
/// img
/// </summary>
[SugarColumn(Length = 50, IsNullable = true)]
public string? img { get; set; }
/// <summary>
/// count
/// </summary>
[SugarColumn(IsNullable = true)]
public int? count { get; set; }
/// <summary>
/// charm
/// </summary>
[SugarColumn(IsNullable = true)]
public int? charm { get; set; }
/// <summary>
/// sumCharm
/// </summary>
[SugarColumn(IsNullable = true)]
public int? sumCharm { get; set; }
/// <summary>
/// addTime
/// </summary>
[SugarColumn(IsNullable = true)]
public DateTime? addTime { get; set; }
}
}

View File

@@ -0,0 +1,11 @@
namespace Application.Domain.Entity;
public class GiftLogView
{
public UserModel user { get; set; }
public UserModel from { get; set; }
public string name { get; set; }
public string img { get; set; }
public int count { get; set; }
public DateTime? time { get; set; }
}

View File

@@ -16,11 +16,12 @@ public static class GoodsEnum
Pack,//宝箱
ChoicePack,//选择宝箱
Weight,//负重
Gift,//礼物道具
Exp,//经验
State,//状态物品
Ship,//船只
Practise,//修炼道具
Durability,//负重道具
Durability,//耐久道具
AddExp,//扣除经验获得道具
GetExp//使用后获得经验
}

View File

@@ -20,4 +20,14 @@ public interface IUnitUserRelationService
Task<bool> DeleteUserEnemy(string userId, string eId);
#endregion
#region
Task<game_charm_log> GetUserNewGift(string userId);
Task<List<GiftLogView>> GetUserGiftLog(string userId, int page, int limit, RefAsync<int> total);
Task<bool> AddCharm(string userId, string fromId, int goodsId, string name, string img, int charm,
int count);
#endregion
}

View File

@@ -168,6 +168,10 @@ public class RankService(ISqlSugarClient DbClient, IRedisCache redis) : IRankSer
{
temp.sign = item.renown.ToString();
}
else if(type==11)
{
temp.sign = item.charm.ToString();
}
temp.par = "";
result.Add(temp);
}

View File

@@ -38,10 +38,10 @@ public class UnitUserRelationService(ISqlSugarClient DbClient, IRedisCache redis
public async Task<bool> CheckIsFriend(string userId, string toId)
{
string frId = StringAssist.GetSortKey(userId, toId);
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_friend>();
return await db.Queryable<unit_user_friend>().Where(it => it.frId == frId).AnyAsync();
var data = await GetUserFriendInfo(userId, toId);
return data != null;
}
public async Task<bool> AddFriend(string userId, string toId)
{
@@ -62,6 +62,21 @@ public class UnitUserRelationService(ISqlSugarClient DbClient, IRedisCache redis
return await db.Deleteable<unit_user_friend>().Where(it => it.frId == frId).ExecuteCommandAsync() > 0;
}
private async Task<unit_user_friend> GetUserFriendInfo(string userId, string toId)
{
string frId = StringAssist.GetSortKey(userId, toId);
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_friend>();
return await db.Queryable<unit_user_friend>().Where(it => it.frId == frId).SingleAsync();
}
private async Task<bool> UpdateFriendNear(string frId, int op, int count)
{
int opCount = op == 1 ? count : 0 - count;
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_friend>();
return await db.Updateable<unit_user_friend>().SetColumns(it => it.near == it.near + opCount)
.Where(it => it.frId == frId).ExecuteCommandAsync() > 0;
}
#endregion
#region
@@ -120,4 +135,91 @@ public class UnitUserRelationService(ISqlSugarClient DbClient, IRedisCache redis
}
#endregion
#region
public async Task<game_charm_log> GetUserNewGift(string userId)
{
string key = string.Format(UserCache.BaseCacheKey, "UserNewGift");
if (await redis.HExistsHashAsync(key, userId))
{
return await redis.GetHashAsync<game_charm_log>(key, userId);
}
var db = DbClient.AsTenant().GetConnectionWithAttr<game_charm_log>();
var data = await db.Queryable<game_charm_log>().Where(it => it.userId == userId)
.OrderByDescending(it => it.addTime).FirstAsync();
if (data == null)
{
data = new game_charm_log();
}
await redis.AddHashAsync(key, userId, data);
return data;
}
public async Task<List<GiftLogView>> GetUserGiftLog(string userId, int page, int limit, RefAsync<int> total)
{
var db = DbClient.AsTenant().GetConnectionWithAttr<game_charm_log>();
var data = await db.Queryable<game_charm_log>().Where(it => it.userId == userId)
.OrderByDescending(it => it.addTime).ToPageListAsync(page, limit, total);
List<GiftLogView> result = new List<GiftLogView>();
foreach (var item in data)
{
GiftLogView temp = new GiftLogView()
{
user = await UserModelTool.GetUserView(item.userId),
from = await UserModelTool.GetUserView(item.fromId),
name = item.name,
img = item.img,
count = (int)item.count,
time = item.addTime
};
result.Add(temp);
}
return result;
}
public async Task<bool> AddCharm(string userId, string fromId, int goodsId, string name, string img, int charm,
int count)
{
int sumCharm = count * charm;
var accService = App.GetService<IUnitUserAccService>();
bool result = await accService.UpdateUserData(userId, 1, nameof(AccEnum.AccType.charm), sumCharm, "赠送礼物获得");
if (result)
{
game_charm_log log = new game_charm_log()
{
logId = StringAssist.NewGuid,
userId = userId,
fromId = fromId,
goodsId = goodsId,
name = name,
img = img,
count = count,
charm = charm,
sumCharm = sumCharm,
addTime = DateTime.Now
};
var db = DbClient.AsTenant().GetConnectionWithAttr<game_charm_log>();
if (await db.Insertable(log).ExecuteCommandAsync() > 0)
{
string key = string.Format(UserCache.BaseCacheKey, "UserNewGift");
await redis.AddHashAsync(key, userId,log);
//判断关系是否为好友
var frInfo = await GetUserFriendInfo(userId, fromId);
if (frInfo != null)
{
//添加亲密度
await UpdateFriendNear(frInfo.frId, 1, sumCharm);
}
}
}
return result;
}
#endregion
}

View File

@@ -69,6 +69,11 @@ public static class GameBus
var mapService = App.GetService<IGameMapService>();
isok = await mapService.AddUserCityMap(userId, Convert.ToInt32(parameter));
}
else if (goodsType.Equals(nameof(GameEnum.PropCode.skill)))
{
var skillService = App.GetService<IGameSkillService>();
isok = await skillService.UpdateUserSkill(userId, Convert.ToInt32(parameter));
}
return isok;
}

View File

@@ -6,4 +6,22 @@ public class UbbTool
{
return $"<a data-type='go' data-parms='/user/user?no={no}' href='javascript:void'>{name}</a>";
}
private static string _GiftUbb = "<img src='{0}' alt='{1}' />";
public static string GiftUbb(string id, string name)
{
return string.Format(_GiftUbb, id, name);
}
public static string GiveGiftStr(int count)
{
string result = string.Empty;
result += GiftUbb("images/gift/x.png", "×");
char[] num = count.ToString().ToCharArray();
foreach (char s in num)
{
result += GiftUbb(string.Format("images/gift/num_{0}.png", s.ToString()), s.ToString());
}
return result;
}
}

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