1212121
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
Reference in New Issue
Block a user