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

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