修复
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
namespace Application.Domain;
|
||||
|
||||
public interface IGameMallService
|
||||
{
|
||||
Task<List<game_mall>> GetMallData(int area, string type, int page, int limit, RefAsync<int> total);
|
||||
Task<game_mall> GetMallInfo(string mallId);
|
||||
Task<bool> AddLog(game_mall mall, string userId, int count);
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
namespace Application.Domain;
|
||||
|
||||
public interface IMessageService
|
||||
{
|
||||
Task<int> GetNoReadCount(string userId);
|
||||
|
||||
#region 私聊消息
|
||||
|
||||
string GetTalkId(string userId, string otId);
|
||||
Task<List<unit_user_message>> GetUserNoReadData(string talkId);
|
||||
|
||||
Task<List<unit_user_message>> GetUserMessageData(string talkId, int page, int limit,
|
||||
RefAsync<int> total);
|
||||
Task<List<MessageView>> GetUserMessage(string userId, int type, int page, int limit,
|
||||
RefAsync<int> total);
|
||||
|
||||
Task<bool> SendMsg(string sendId, string toUser, string msg);
|
||||
Task SetMsgRead(List<long> msgIds, string userId);
|
||||
Task<bool> DeleteMsgByTalkId(string talkId, string userId);
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
namespace Application.Domain;
|
||||
|
||||
public class GameMallService(ISqlSugarClient DbClient, IRedisCache redis) : IGameMallService, ITransient
|
||||
{
|
||||
public async Task<List<game_mall>> GetMallData(int area, string type, int page, int limit, RefAsync<int> total)
|
||||
{
|
||||
DateTime onTime = DateTime.Now;
|
||||
string _area = area.ToString();
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<game_mall>();
|
||||
return await db.Queryable<game_mall>().Where(it =>
|
||||
it.endTime > onTime && (it.areaId.Contains("0") || it.areaId.Contains(_area)))
|
||||
.WhereIF(type=="0",it=>it.payType=="cowry")
|
||||
.WhereIF(type=="1",it=>it.payType=="gold")
|
||||
.OrderBy(it=>it.sort,OrderByType.Asc)
|
||||
.ToPageListAsync(page, limit, total);
|
||||
}
|
||||
|
||||
public async Task<game_mall> GetMallInfo(string mallId)
|
||||
{
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<game_mall>();
|
||||
return await db.Queryable<game_mall>().Where(it => it.mallId == mallId).SingleAsync();
|
||||
}
|
||||
|
||||
public async Task<bool> AddLog(game_mall mall, string userId, int count)
|
||||
{
|
||||
game_mall_log log = new game_mall_log();
|
||||
log.logId = StringAssist.NewGuid;
|
||||
log.mallId = mall.mallId;
|
||||
log.type = mall.type;
|
||||
log.pars = mall.goodsId;
|
||||
log.count = count;
|
||||
log.price = mall.price;
|
||||
log.payType = mall.payType;
|
||||
log.userId = userId;
|
||||
log.addTime = DateTime.Now;
|
||||
log.endTime = DateTime.Now.AddDays(30);
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<game_mall_log>();
|
||||
return await db.Insertable(log).ExecuteCommandAsync() > 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,166 @@
|
||||
namespace Application.Domain;
|
||||
|
||||
public class MessageService(ISqlSugarClient DbClient, IRedisCache redis) : IMessageService, ITransient
|
||||
{
|
||||
public async Task<int> GetNoReadCount(string userId)
|
||||
{
|
||||
string key = string.Format(UserCache.BaseCacheKeys, "Message", "Count");
|
||||
if (await redis.HExistsHashAsync(key, userId))
|
||||
{
|
||||
return await redis.GetHashAsync<int>(key, userId);
|
||||
}
|
||||
|
||||
int result = 0;
|
||||
//普通消息
|
||||
int noRead = await GetUserNoReadDataCountByUserId(userId);
|
||||
result += noRead;
|
||||
//邮件详细
|
||||
//通知消息
|
||||
await redis.AddHashAsync(key, userId, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
private async Task ClearMessageCache(string userId)
|
||||
{
|
||||
string key = string.Format(UserCache.BaseCacheKeys, "Message", "Count");
|
||||
await redis.DelHashAsync(key, userId);
|
||||
}
|
||||
|
||||
#region 私信消息
|
||||
|
||||
public string GetTalkId(string userId, string otId)
|
||||
{
|
||||
return $"{userId}_{otId}";
|
||||
}
|
||||
|
||||
private List<string> GetTalkIdToUserId(string talkId)
|
||||
{
|
||||
return talkId.Split('_').ToList();
|
||||
}
|
||||
|
||||
private async Task<int> GetUserNoReadDataCountByUserId(string userId)
|
||||
{
|
||||
var db = DbClient.AsTenant().GetConnectionScopeWithAttr<unit_user_message>();
|
||||
return await db.Queryable<unit_user_message>()
|
||||
.Where(it => it.status == 1 && it.userId == userId && it.isRead == 0).CountAsync();
|
||||
}
|
||||
|
||||
public async Task<List<unit_user_message>> GetUserNoReadData(string talkId)
|
||||
{
|
||||
var db = DbClient.AsTenant().GetConnectionScopeWithAttr<unit_user_message>();
|
||||
return await db.Queryable<unit_user_message>()
|
||||
.Where(it => it.status == 1 && it.talkId == talkId && it.isRead == 0)
|
||||
.OrderByDescending(it => it.addTime).ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<List<unit_user_message>> GetUserMessageData(string talkId, int page, int limit,
|
||||
RefAsync<int> total)
|
||||
{
|
||||
var db = DbClient.AsTenant().GetConnectionScopeWithAttr<unit_user_message>();
|
||||
return await db.Queryable<unit_user_message>()
|
||||
.Where(it => it.status == 1 && it.talkId == talkId)
|
||||
.OrderByDescending(it => it.addTime)
|
||||
.ToPageListAsync(page, limit, total);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取最新对话列表
|
||||
/// </summary>
|
||||
/// <param name="userId"></param>
|
||||
/// <param name="type"></param>
|
||||
/// <param name="page"></param>
|
||||
/// <param name="limit"></param>
|
||||
/// <param name="total"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<List<MessageView>> GetUserMessage(string userId, int type, int page, int limit,
|
||||
RefAsync<int> total)
|
||||
{
|
||||
var db = DbClient.AsTenant().GetConnectionScopeWithAttr<unit_user_message>();
|
||||
var talkData = await db.Queryable<unit_user_message>()
|
||||
.GroupBy(it => new { it.talkId })
|
||||
.Where(it => it.userId == userId && it.status == 1)
|
||||
.WhereIF(type == 0, it => it.isRead == 0)
|
||||
.OrderByDescending(it => it.addTime)
|
||||
.Select(it => new { mgsId = SqlFunc.AggregateMax(it.msgId) })
|
||||
.ToPageListAsync(page, limit, total);
|
||||
|
||||
List<MessageView> result = new List<MessageView>();
|
||||
foreach (var item in talkData)
|
||||
{
|
||||
MessageView temp = new MessageView();
|
||||
var msgInfo = await db.Queryable<unit_user_message>().Where(it => it.msgId == item.mgsId).SingleAsync();
|
||||
temp.sign = msgInfo.sign;
|
||||
var users = GetTalkIdToUserId(msgInfo.talkId);
|
||||
temp.user = await UserModelTool.GetUserView(users[1]);
|
||||
result.Add(temp);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public async Task<bool> SendMsg(string sendId, string toUser, string msg)
|
||||
{
|
||||
List<unit_user_message> adds = new List<unit_user_message>();
|
||||
unit_user_message message = new unit_user_message();
|
||||
message.msgId = SnowflakeAssist.NextId();
|
||||
message.userId = toUser;
|
||||
message.sendId = sendId;
|
||||
message.sign = msg;
|
||||
message.isRead = 0;
|
||||
message.status = 1;
|
||||
message.addTime = DateTime.Now;
|
||||
message.endTime = TimeExtend.GetTimeStampBySeconds(DateTime.Now.AddDays(90));
|
||||
message.talkId = GetTalkId(toUser, sendId);
|
||||
adds.Add(message);
|
||||
if (sendId != "0")
|
||||
{
|
||||
message = new unit_user_message();
|
||||
message.msgId = SnowflakeAssist.NextId();
|
||||
message.userId = sendId;
|
||||
message.sendId = sendId;
|
||||
message.sign = msg;
|
||||
message.isRead = 1;
|
||||
message.status = 1;
|
||||
message.addTime = DateTime.Now;
|
||||
message.endTime = TimeExtend.GetTimeStampBySeconds(DateTime.Now.AddDays(90));
|
||||
message.talkId = GetTalkId(sendId, toUser);
|
||||
adds.Add(message);
|
||||
}
|
||||
|
||||
var db = DbClient.AsTenant().GetConnectionScopeWithAttr<unit_user_message>();
|
||||
bool result = await db.Insertable(adds).ExecuteCommandAsync() > 0;
|
||||
if (result)
|
||||
{
|
||||
await ClearMessageCache(toUser);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public async Task SetMsgRead(List<long> msgIds, string userId)
|
||||
{
|
||||
var db = DbClient.AsTenant().GetConnectionScopeWithAttr<unit_user_message>();
|
||||
bool result = await db.Updateable<unit_user_message>().SetColumns(it => it.isRead == 1)
|
||||
.Where(it => msgIds.Contains(it.msgId)).ExecuteCommandAsync() > 0;
|
||||
if (result)
|
||||
{
|
||||
await ClearMessageCache(userId);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<bool> DeleteMsgByTalkId(string talkId, string userId)
|
||||
{
|
||||
var db = DbClient.AsTenant().GetConnectionScopeWithAttr<unit_user_message>();
|
||||
bool result = await db.Updateable<unit_user_message>().SetColumns(it => it.status == 0)
|
||||
.Where(it => it.talkId == talkId && it.status == 1).ExecuteCommandAsync() >
|
||||
0;
|
||||
if (result)
|
||||
{
|
||||
await ClearMessageCache(userId);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -70,9 +70,9 @@ public class UnitUserAccService(ISqlSugarClient DbClient, IRedisCache redis) : I
|
||||
userAccLog.name = name;
|
||||
userAccLog.amount = count;
|
||||
userAccLog.addTime = DateTime.Now;
|
||||
userAccLog.endTime = DateTime.Now.AddDays(3);
|
||||
userAccLog.endTime = DateTime.Now.AddDays(30);
|
||||
userAccLog.remark = remark;
|
||||
await db.Insertable(userAccLog).ExecuteCommandAsync();
|
||||
await AddLog(userAccLog);
|
||||
}
|
||||
|
||||
await DbClient.AsTenant().CommitTranAsync();
|
||||
@@ -102,6 +102,11 @@ public class UnitUserAccService(ISqlSugarClient DbClient, IRedisCache redis) : I
|
||||
return result;
|
||||
}
|
||||
|
||||
private async Task AddLog(unit_user_acc_log log)
|
||||
{
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_acc_log>();
|
||||
await db.Insertable(log).ExecuteCommandAsync();
|
||||
}
|
||||
|
||||
public async Task<unit_user_copper> GetUserCopperInfo(string userId)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user