11
This commit is contained in:
@@ -4,4 +4,5 @@ public interface INoticeService
|
||||
{
|
||||
Task<List<game_notice>> GetNoticeDataByTake(int take);
|
||||
Task<List<game_notice>> GetNoticeData(int page, int limit, RefAsync<int> total);
|
||||
Task<game_notice> GetNoticeInfo(string id);
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
namespace Application.Domain;
|
||||
|
||||
public interface IUnitUserService
|
||||
{
|
||||
#region 用户信息
|
||||
|
||||
Task<List<unit_user>> GetUserDataByAccId(string accId);
|
||||
|
||||
#endregion
|
||||
|
||||
#region 用户注册
|
||||
|
||||
/// <summary>
|
||||
/// 注册游戏角色
|
||||
/// </summary>
|
||||
/// <param name="areaId"></param>
|
||||
/// <param name="accId"></param>
|
||||
/// <returns></returns>
|
||||
Task<unit_user> Register(int areaId, string accId);
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -22,4 +22,10 @@ public class NoticeService:INoticeService,ITransient
|
||||
var db = _dbClient.AsTenant().GetConnectionWithAttr<game_notice>();
|
||||
return await db.Queryable<game_notice>().OrderByDescending(it=>it.addTime).ToPageListAsync(page, limit, total);
|
||||
}
|
||||
|
||||
public async Task<game_notice> GetNoticeInfo(string id)
|
||||
{
|
||||
var db = _dbClient.AsTenant().GetConnectionWithAttr<game_notice>();
|
||||
return await db.Queryable<game_notice>().Where(it => it.noticeId == id).SingleAsync();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,135 @@
|
||||
using Photon.Core.Assist;
|
||||
|
||||
namespace Application.Domain;
|
||||
|
||||
public class UnitUserService : IUnitUserService, ITransient
|
||||
{
|
||||
private readonly ISqlSugarClient _dbClient;
|
||||
private readonly IRedisCache _redisClient;
|
||||
|
||||
public UnitUserService(ISqlSugarClient dbClient, IRedisCache redisClient)
|
||||
{
|
||||
_dbClient = dbClient;
|
||||
_redisClient = redisClient;
|
||||
}
|
||||
|
||||
#region 用户信息
|
||||
public async Task<List<unit_user>> GetUserDataByAccId(string accId)
|
||||
{
|
||||
var db = _dbClient.AsTenant().GetConnectionWithAttr<unit_user>();
|
||||
return await db.Queryable<unit_user>().Where(it => it.accId == accId).ToListAsync();
|
||||
}
|
||||
public async Task<unit_user> GetUserInfoByUserNo(string userNo)
|
||||
{
|
||||
string key = string.Format(UserCache.BaseCacheKeys, "UserInfo", "UserNo");
|
||||
var data = await _redisClient.GetHashAsync<unit_user>(key, userNo);
|
||||
if (data == null)
|
||||
{
|
||||
var db = _dbClient.AsTenant().GetConnectionWithAttr<unit_user>();
|
||||
data = await db.Queryable<unit_user>().Where(it => it.userNo == userNo).SingleAsync();
|
||||
if (data != null)
|
||||
{
|
||||
await _redisClient.AddHashAsync(key, userNo, data);
|
||||
}
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
public async Task<unit_user> GetUserInfoBySid(string token)
|
||||
{
|
||||
string key = string.Format(UserCache.BaseCacheKeys, "UserInfo", "Sid");
|
||||
var data = await _redisClient.GetHashAsync<unit_user>(key, token);
|
||||
if (data == null)
|
||||
{
|
||||
var db = _dbClient.AsTenant().GetConnectionWithAttr<unit_user>();
|
||||
data = await db.Queryable<unit_user>().Where(it => it.token == token).SingleAsync();
|
||||
if (data != null)
|
||||
{
|
||||
await _redisClient.AddHashAsync(key, token, data);
|
||||
}
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 用户注册
|
||||
|
||||
|
||||
|
||||
public async Task<unit_user> Register(int areaId, string accId)
|
||||
{
|
||||
unit_user result = new unit_user();
|
||||
try
|
||||
{
|
||||
var db = _dbClient.AsTenant().GetConnectionWithAttr<unit_user>();
|
||||
await _dbClient.AsTenant().BeginTranAsync();
|
||||
string userId = StringAssist.NewGuid;
|
||||
result.userId = userId;
|
||||
result.areaId = areaId;
|
||||
result.accId = accId;
|
||||
result.nick = "四海虾米";
|
||||
result.headImg = "";
|
||||
int no = await GetUserNo();
|
||||
result.userNo = no.ToString();
|
||||
string token = await GetToken();
|
||||
result.token = token;
|
||||
result.sign = "这个小家伙儿很懒,什么也没留下.";
|
||||
result.status = 1;
|
||||
result.regOk = 0;
|
||||
result.isSystem = 0;
|
||||
result.addTime = DateTime.Now;
|
||||
result.upTime = DateTime.Now;
|
||||
bool isok = db.Insertable(result).ExecuteCommand() > 0;
|
||||
if (!isok)
|
||||
{
|
||||
result = null;
|
||||
}
|
||||
|
||||
await _dbClient.AsTenant().CommitTranAsync();
|
||||
}
|
||||
catch
|
||||
{
|
||||
result = null;
|
||||
await _dbClient.AsTenant().RollbackTranAsync();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public async Task<int> GetUserNo()
|
||||
{
|
||||
int No = 0;
|
||||
bool ok = true;
|
||||
while (ok)
|
||||
{
|
||||
No = RandomAssist.GetFormatedNumeric(11012585, 97521695);
|
||||
if (await GetUserInfoByUserNo(No.ToString()) == null)
|
||||
{
|
||||
ok = false;
|
||||
}
|
||||
}
|
||||
|
||||
return No;
|
||||
}
|
||||
|
||||
private async Task<string> GetToken()
|
||||
{
|
||||
string sid = string.Empty;
|
||||
bool ok = true;
|
||||
while (ok)
|
||||
{
|
||||
sid = StringAssist.RandomString(32);
|
||||
if (await GetUserInfoBySid(sid) == null)
|
||||
{
|
||||
ok = false;
|
||||
}
|
||||
}
|
||||
|
||||
return sid;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
Reference in New Issue
Block a user