121
This commit is contained in:
@@ -65,5 +65,10 @@ namespace Application.Domain.Entity
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = true)]
|
||||
public int? state { get; set; }
|
||||
/// <summary>
|
||||
/// opUser
|
||||
/// </summary>
|
||||
[SugarColumn(Length = 50, IsNullable = true)]
|
||||
public string? opUser { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -84,4 +84,4 @@ namespace Application.Domain.Entity
|
||||
[SugarColumn(IsNullable = true)]
|
||||
public DateTime? addTime { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
using SqlSugar;
|
||||
using System;
|
||||
|
||||
namespace Application.Domain.Entity
|
||||
{
|
||||
[Tenant("Kg.SeaTime.Game")]
|
||||
public class unit_user_config
|
||||
{
|
||||
/// <summary>
|
||||
/// userId
|
||||
/// </summary>
|
||||
[SugarColumn(IsPrimaryKey = true, Length = 50)]
|
||||
public string userId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 加好友权限:1默认 0禁止加好友 2不限制
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = true)]
|
||||
public int? friendRole { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 频道管理权限:0无 1区域 2全部
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = true)]
|
||||
public int? chatRole { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 自动拾取物品:-1未开通,1开通,0禁止
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = true)]
|
||||
public int? autoBag { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 自动使用药品:-1未开通,1开通,0禁止
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = true)]
|
||||
public int? autoDrug { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
using SqlSugar;
|
||||
using System;
|
||||
|
||||
namespace Application.Domain.Entity
|
||||
{
|
||||
[Tenant("Kg.SeaTime.Game")]
|
||||
public class unit_user_enemy
|
||||
{
|
||||
/// <summary>
|
||||
/// euId
|
||||
/// </summary>
|
||||
[SugarColumn(IsPrimaryKey = true, Length = 100)]
|
||||
public string euId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// userId
|
||||
/// </summary>
|
||||
[SugarColumn(Length = 50, IsNullable = true)]
|
||||
public string? userId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// eId
|
||||
/// </summary>
|
||||
[SugarColumn(Length = 50, IsNullable = true)]
|
||||
public string? eId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// addTime
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = true)]
|
||||
public DateTime? addTime { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,9 @@ public class UserModel
|
||||
public string userNo { get; set; }
|
||||
public string nick { get; set; }
|
||||
public string sex { get; set; }
|
||||
public string sign { get; set; }
|
||||
public string headImg { get; set; }
|
||||
|
||||
public int area { get; set; }
|
||||
public string icon { get; set; }
|
||||
public int lev { get; set; }
|
||||
|
||||
45
Service/Application.Domain.Entity/resource/game/game_ack.cs
Normal file
45
Service/Application.Domain.Entity/resource/game/game_ack.cs
Normal file
@@ -0,0 +1,45 @@
|
||||
using SqlSugar;
|
||||
using System;
|
||||
|
||||
namespace Application.Domain.Entity
|
||||
{
|
||||
[Tenant("Kg.SeaTime.Resource")]
|
||||
public class game_ack
|
||||
{
|
||||
/// <summary>
|
||||
/// ackCode
|
||||
/// </summary>
|
||||
[SugarColumn(IsPrimaryKey = true, Length = 50)]
|
||||
public string ackCode { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// areaId
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = true)]
|
||||
public int? areaId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// status
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = true)]
|
||||
public int? status { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// addTime
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = true)]
|
||||
public DateTime? addTime { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// useTime
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = true)]
|
||||
public DateTime? useTime { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// useUser
|
||||
/// </summary>
|
||||
[SugarColumn(Length = 50, IsNullable = true)]
|
||||
public string? useUser { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -30,10 +30,16 @@ namespace Application.Domain.Entity
|
||||
[SugarColumn(IsNullable = true)]
|
||||
public DateTime? opTime { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否需要激活码
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = true)]
|
||||
public int? isNeedCode { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 添加时间
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = true)]
|
||||
public DateTime? addTime { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,4 +9,8 @@ public static class GameConfig
|
||||
public const int SendChatGoodsService = 10002;//金海螺
|
||||
public const int UpLevAddWeight = 10;//升级增加负重
|
||||
public const int GameBaseVigour = 50;//初始活力
|
||||
public const int GameRelationEnemyNeedGold = 50;//添加仇人所需金元
|
||||
public const int GameUpdateNickNeedGoods = 10001;//更新昵称所需道具
|
||||
public const int GameUpdateSexNeedGoods = 10001;//更新性别所需道具
|
||||
public const int GameUserFriendMaxCount = 50;//好友最大上限人数
|
||||
}
|
||||
@@ -6,4 +6,12 @@ public static class UserEnum
|
||||
{
|
||||
Person
|
||||
}
|
||||
|
||||
public enum ConfigCode
|
||||
{
|
||||
FriendRole,
|
||||
ChatRole,
|
||||
AutoBag,
|
||||
AutoDrug,
|
||||
}
|
||||
}
|
||||
@@ -15,7 +15,13 @@ public class MessageHandle
|
||||
|
||||
if (state == 1)
|
||||
{
|
||||
if (await relationService.AddFriend(events.userId, events.pars))
|
||||
var friendCount = await relationService.GetUserFriendCount(events.pars);
|
||||
if (friendCount >= GameConfig.GameUserFriendMaxCount)
|
||||
{
|
||||
return new MessageHandleResult() { success = false, msg = "Ta的好友人数已达上限!" };
|
||||
}
|
||||
|
||||
if (await relationService.AddFriend(events.pars,events.userId ))
|
||||
{
|
||||
var chatService = App.GetService<IGameChatService>();
|
||||
var userService = App.GetService<IUnitUserService>();
|
||||
@@ -39,7 +45,7 @@ public class MessageHandle
|
||||
return new MessageHandleResult() { success = true, msg = "已拒绝该好友申请!" };
|
||||
}
|
||||
}
|
||||
else if (events.code == nameof(MessageEnum.EventCode.Friend))
|
||||
else if (events.code == nameof(MessageEnum.EventCode.Trade))
|
||||
{
|
||||
return new MessageHandleResult() { success = true, msg = "消息通知已处理!" };
|
||||
}
|
||||
|
||||
@@ -10,5 +10,6 @@ public interface IGameChatService
|
||||
|
||||
Task<bool> SendChat(string userId, int areaId, string code, string sign, string par = "");
|
||||
Task<bool> SendChat(string userId, string code, string sign, string par = "");
|
||||
Task<bool> DeleteChat(string chatId);
|
||||
Task<game_chat> GetChatInfo(string chatId);
|
||||
Task<bool> DeleteChat(string chatId, string opUser);
|
||||
}
|
||||
@@ -13,4 +13,12 @@ public interface IAreaService
|
||||
/// <param name="areaId"></param>
|
||||
/// <returns></returns>
|
||||
Task<game_area> GetAreaInfo(int areaId);
|
||||
|
||||
#region 激活码
|
||||
|
||||
Task<game_ack> GetAckInfo(string code);
|
||||
Task<bool> UseAck(string code, string userId);
|
||||
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace Application.Domain;
|
||||
|
||||
public interface IGameMaxNameService
|
||||
{
|
||||
|
||||
}
|
||||
@@ -11,4 +11,13 @@ public interface IUnitUserRelationService
|
||||
Task<bool> DeleteFriend(string userId, string toId);
|
||||
|
||||
#endregion
|
||||
|
||||
#region 仇人
|
||||
|
||||
Task<List<RelationView>> GetUserEnemyData(string userId);
|
||||
Task<bool> CheckUserEnemy(string userId, string eId);
|
||||
Task<bool> AddUserEnemy(string userId, string eId);
|
||||
Task<bool> DeleteUserEnemy(string userId, string eId);
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -8,8 +8,10 @@ public interface IUnitUserService
|
||||
Task<unit_user> GetUserInfoByUserId(string userId);
|
||||
Task<unit_user> GetUserInfoByUserNo(string userNo);
|
||||
Task<unit_user> GetUserInfoByToken(string token);
|
||||
|
||||
|
||||
Task<bool> CheckUserNickIsAt(string nick);
|
||||
Task<bool> UpdateUserNick(string userId, string nick);
|
||||
Task<bool> UpdateUserSex(string userId, string sex);
|
||||
Task<bool> UpdateUserSign(string userId, string sign);
|
||||
#endregion
|
||||
|
||||
#region 用户注册
|
||||
@@ -31,5 +33,16 @@ public interface IUnitUserService
|
||||
Task<int> GetOnlineCount();
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region 权限配置
|
||||
|
||||
Task<unit_user_config> GetUserConfigInfo(string userId);
|
||||
Task<int> GetUserConfigInfo(string userId, string code);
|
||||
Task<bool> UpdateUserConfigInfo(string userId, string code, int state);
|
||||
|
||||
|
||||
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -123,6 +123,7 @@ public class GameChatService : IGameChatService, ITransient
|
||||
chat.addTime = DateTime.Now;
|
||||
chat.sort = TimeExtend.GetTimeStampSeconds;
|
||||
chat.delTime = TimeExtend.GetTimeStampBySeconds(DateTime.Now.AddDays(3));
|
||||
chat.opUser = "";
|
||||
switch (code)
|
||||
{
|
||||
case "Region":
|
||||
@@ -146,7 +147,7 @@ public class GameChatService : IGameChatService, ITransient
|
||||
var db = _dbClient.AsTenant().GetConnectionWithAttr<game_chat>();
|
||||
return await db.Insertable(chat).ExecuteCommandAsync() > 0;
|
||||
}
|
||||
|
||||
|
||||
public async Task<bool> SendChat(string userId, string code, string sign, string par = "")
|
||||
{
|
||||
var userService = App.GetService<IUnitUserService>();
|
||||
@@ -156,15 +157,24 @@ public class GameChatService : IGameChatService, ITransient
|
||||
return await SendChat(userId, (int)userInfo.areaId, code, sign, par);
|
||||
}
|
||||
|
||||
public async Task<game_chat> GetChatInfo(string chatId)
|
||||
{
|
||||
var db = _dbClient.AsTenant().GetConnectionWithAttr<game_chat>();
|
||||
return await db.Queryable<game_chat>().Where(it => it.chatId == chatId).SingleAsync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除聊天
|
||||
/// </summary>
|
||||
/// <param name="chatId"></param>
|
||||
/// <param name="opUser"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<bool> DeleteChat(string chatId)
|
||||
public async Task<bool> DeleteChat(string chatId, string opUser)
|
||||
{
|
||||
var db = _dbClient.AsTenant().GetConnectionWithAttr<game_chat>();
|
||||
return await db.Updateable<game_chat>().SetColumns(it => it.state == 0).Where(it => it.chatId == chatId)
|
||||
return await db.Updateable<game_chat>().SetColumns(it => it.state == 0)
|
||||
.SetColumns(it => it.opUser == opUser)
|
||||
.Where(it => it.chatId == chatId)
|
||||
.ExecuteCommandAsync() > 0;
|
||||
}
|
||||
}
|
||||
@@ -57,4 +57,25 @@ public class AreaService : IAreaService, ITransient
|
||||
await _redisClient.DelAsync(key);
|
||||
}
|
||||
}
|
||||
|
||||
#region 激活码
|
||||
|
||||
public async Task<game_ack> GetAckInfo(string code)
|
||||
{
|
||||
var db = _dbClient.AsTenant().GetConnectionWithAttr<game_ack>();
|
||||
return await db.Queryable<game_ack>().Where(it => it.ackCode == code).SingleAsync();
|
||||
}
|
||||
|
||||
public async Task<bool> UseAck(string code, string userId)
|
||||
{
|
||||
DateTime time = DateTime.Now;
|
||||
var db = _dbClient.AsTenant().GetConnectionWithAttr<game_ack>();
|
||||
return await db.Updateable<game_ack>().SetColumns(it => it.status == 1)
|
||||
.SetColumns(it => it.useTime == time)
|
||||
.SetColumns(it => it.useUser == userId)
|
||||
.Where(it => it.ackCode == code)
|
||||
.ExecuteCommandAsync() > 0;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace Application.Domain;
|
||||
|
||||
public class GameMaxNameService(ISqlSugarClient DbClient, IRedisCache redis) : IGameMaxNameService, ITransient
|
||||
{
|
||||
|
||||
}
|
||||
@@ -5,27 +5,27 @@ public class UnitUserAccService(ISqlSugarClient DbClient, IRedisCache redis) : I
|
||||
public async Task<long> GetUserAccInfo(string userId, string accType)
|
||||
{
|
||||
long result = 0;
|
||||
if (accType == AccEnum.AccType.copper.ToString())
|
||||
if (accType == nameof(AccEnum.AccType.copper))
|
||||
{
|
||||
var info = await GetUserCopperInfo(userId);
|
||||
result = (long)info.copper;
|
||||
}
|
||||
else if (accType == AccEnum.AccType.cowry.ToString())
|
||||
else if (accType == nameof(AccEnum.AccType.cowry))
|
||||
{
|
||||
var info = await GetUserAccInfo(userId);
|
||||
result = (long)info.cowry;
|
||||
}
|
||||
else if (accType == AccEnum.AccType.gold.ToString())
|
||||
else if (accType == nameof(AccEnum.AccType.gold))
|
||||
{
|
||||
var info = await GetUserAccInfo(userId);
|
||||
result = (long)info.gold;
|
||||
}
|
||||
else if (accType == AccEnum.AccType.teach.ToString())
|
||||
else if (accType == nameof(AccEnum.AccType.teach))
|
||||
{
|
||||
var info = await GetUserAccInfo(userId);
|
||||
result = (long)info.teach;
|
||||
}
|
||||
else if (accType == AccEnum.AccType.renown.ToString())
|
||||
else if (accType == nameof(AccEnum.AccType.renown))
|
||||
{
|
||||
var info = await GetUserAccInfo(userId);
|
||||
result = (long)info.renown;
|
||||
@@ -53,10 +53,10 @@ public class UnitUserAccService(ISqlSugarClient DbClient, IRedisCache redis) : I
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_acc>();
|
||||
await DbClient.AsTenant().BeginTranAsync();
|
||||
isOk = await db.Updateable<unit_user_acc>()
|
||||
.SetColumnsIF(accType.Equals(AccEnum.AccType.cowry.ToString()), it => it.cowry == it.cowry + opCount)
|
||||
.SetColumnsIF(accType.Equals(AccEnum.AccType.gold.ToString()), it => it.gold == it.gold + opCount)
|
||||
.SetColumnsIF(accType.Equals(AccEnum.AccType.teach.ToString()), it => it.teach == it.teach + opCount)
|
||||
.SetColumnsIF(accType.Equals(AccEnum.AccType.renown.ToString()), it => it.renown == it.renown + opCount)
|
||||
.SetColumnsIF(accType.Equals(nameof(AccEnum.AccType.cowry)), it => it.cowry == it.cowry + opCount)
|
||||
.SetColumnsIF(accType.Equals(nameof(AccEnum.AccType.gold)), it => it.gold == it.gold + opCount)
|
||||
.SetColumnsIF(accType.Equals(nameof(AccEnum.AccType.teach)), it => it.teach == it.teach + opCount)
|
||||
.SetColumnsIF(accType.Equals(nameof(AccEnum.AccType.renown)), it => it.renown == it.renown + opCount)
|
||||
.Where(it => it.userId == userId).ExecuteCommandAsync() > 0;
|
||||
//生成日志
|
||||
if (isOk)
|
||||
|
||||
@@ -59,7 +59,64 @@ public class UnitUserRelationService(ISqlSugarClient DbClient, IRedisCache redis
|
||||
{
|
||||
string frId = StringAssist.GetSortKey(userId, toId);
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_friend>();
|
||||
return await db.Deleteable<unit_user_friend>().Where(it => it.frId == frId).ExecuteCommandAsync()>0;
|
||||
return await db.Deleteable<unit_user_friend>().Where(it => it.frId == frId).ExecuteCommandAsync() > 0;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 仇人
|
||||
|
||||
public async Task<List<RelationView>> GetUserEnemyData(string userId)
|
||||
{
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_enemy>();
|
||||
var data = await db.Queryable<unit_user_enemy>().Where(it => it.userId == userId)
|
||||
.OrderByDescending(it => it.addTime)
|
||||
.ToListAsync();
|
||||
List<RelationView> result = new List<RelationView>();
|
||||
foreach (var item in data)
|
||||
{
|
||||
RelationView temp = new RelationView();
|
||||
temp.user = await UserModelTool.GetUserView(item.eId);
|
||||
temp.near = 0;
|
||||
|
||||
var mapService = App.GetService<IGameMapService>();
|
||||
var onMap = await mapService.GetUserOnMapInfo(item.eId);
|
||||
temp.mapName = onMap.mapName;
|
||||
temp.cityName = onMap.cityName;
|
||||
temp.sort = TimeExtend.GetTimeStampBySeconds((DateTime)item.addTime);
|
||||
temp.isOnline = onMap.isOnline;
|
||||
result.Add(temp);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public async Task<bool> CheckUserEnemy(string userId, string eId)
|
||||
{
|
||||
string euId = $"{userId}_{eId}";
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_enemy>();
|
||||
return await db.Queryable<unit_user_enemy>().Where(it => it.euId == euId).AnyAsync();
|
||||
}
|
||||
|
||||
public async Task<bool> AddUserEnemy(string userId, string eId)
|
||||
{
|
||||
string euId = $"{userId}_{eId}";
|
||||
unit_user_enemy enemy = new unit_user_enemy()
|
||||
{
|
||||
euId = euId,
|
||||
userId = userId,
|
||||
eId = eId,
|
||||
addTime = DateTime.Now
|
||||
};
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_enemy>();
|
||||
return await db.Insertable(enemy).ExecuteCommandAsync() > 0;
|
||||
}
|
||||
|
||||
public async Task<bool> DeleteUserEnemy(string userId, string eId)
|
||||
{
|
||||
string euId = $"{userId}_{eId}";
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_enemy>();
|
||||
return await db.Deleteable<unit_user_enemy>().Where(it => it.euId == euId).ExecuteCommandAsync() > 0;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -2,36 +2,28 @@
|
||||
|
||||
namespace Application.Domain;
|
||||
|
||||
public class UnitUserService : IUnitUserService, ITransient
|
||||
public class UnitUserService(ISqlSugarClient DbClient, IRedisCache redis) : 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>();
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user>();
|
||||
return await db.Queryable<unit_user>().Where(it => it.accId == accId).ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<unit_user> GetUserInfoByUserId(string userId)
|
||||
{
|
||||
string key = string.Format(UserCache.BaseCacheKeys, "UserInfo", "UserId");
|
||||
var data = await _redisClient.GetHashAsync<unit_user>(key, userId);
|
||||
var data = await redis.GetHashAsync<unit_user>(key, userId);
|
||||
if (data == null)
|
||||
{
|
||||
var db = _dbClient.AsTenant().GetConnectionWithAttr<unit_user>();
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user>();
|
||||
data = await db.Queryable<unit_user>().Where(it => it.userId == userId).SingleAsync();
|
||||
if (data != null)
|
||||
{
|
||||
await _redisClient.AddHashAsync(key, userId, data);
|
||||
await redis.AddHashAsync(key, userId, data);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,14 +33,14 @@ public class UnitUserService : IUnitUserService, ITransient
|
||||
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);
|
||||
var data = await redis.GetHashAsync<unit_user>(key, userNo);
|
||||
if (data == null)
|
||||
{
|
||||
var db = _dbClient.AsTenant().GetConnectionWithAttr<unit_user>();
|
||||
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);
|
||||
await redis.AddHashAsync(key, userNo, data);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,14 +50,14 @@ public class UnitUserService : IUnitUserService, ITransient
|
||||
public async Task<unit_user> GetUserInfoByToken(string token)
|
||||
{
|
||||
string key = string.Format(UserCache.BaseCacheKeys, "UserInfo", "token");
|
||||
var data = await _redisClient.GetHashAsync<unit_user>(key, token);
|
||||
var data = await redis.GetHashAsync<unit_user>(key, token);
|
||||
if (data == null)
|
||||
{
|
||||
var db = _dbClient.AsTenant().GetConnectionWithAttr<unit_user>();
|
||||
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);
|
||||
await redis.AddHashAsync(key, token, data);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,9 +78,52 @@ public class UnitUserService : IUnitUserService, ITransient
|
||||
break;
|
||||
}
|
||||
|
||||
await _redisClient.DelHashAsync(string.Format(UserCache.BaseCacheKeys, "UserInfo", "UserId"), result.userId);
|
||||
await _redisClient.DelHashAsync(string.Format(UserCache.BaseCacheKeys, "UserInfo", "UserNo"), result.userNo);
|
||||
await _redisClient.DelHashAsync(string.Format(UserCache.BaseCacheKeys, "UserInfo", "Sid"), result.token);
|
||||
await redis.DelHashAsync(string.Format(UserCache.BaseCacheKeys, "UserInfo", "UserId"), result.userId);
|
||||
await redis.DelHashAsync(string.Format(UserCache.BaseCacheKeys, "UserInfo", "UserNo"), result.userNo);
|
||||
await redis.DelHashAsync(string.Format(UserCache.BaseCacheKeys, "UserInfo", "Sid"), result.token);
|
||||
}
|
||||
|
||||
public async Task<bool> CheckUserNickIsAt(string nick)
|
||||
{
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user>();
|
||||
return await db.Queryable<unit_user>().Where(it => it.nick.Contains(nick)).AnyAsync();
|
||||
}
|
||||
|
||||
public async Task<bool> UpdateUserNick(string userId, string nick)
|
||||
{
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user>();
|
||||
bool result = await db.Updateable<unit_user>().SetColumns(it => it.nick == nick)
|
||||
.Where(it => it.userId == userId).ExecuteCommandAsync() > 0;
|
||||
if (result)
|
||||
{
|
||||
await ClearUserInfo(0, userId);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
public async Task<bool> UpdateUserSex(string userId, string sex)
|
||||
{
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user>();
|
||||
bool result = await db.Updateable<unit_user>().SetColumns(it => it.sex == sex)
|
||||
.Where(it => it.userId == userId).ExecuteCommandAsync() > 0;
|
||||
if (result)
|
||||
{
|
||||
await ClearUserInfo(0, userId);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
public async Task<bool> UpdateUserSign(string userId, string sign)
|
||||
{
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user>();
|
||||
bool result = await db.Updateable<unit_user>().SetColumns(it => it.sign == sign)
|
||||
.Where(it => it.userId == userId).ExecuteCommandAsync() > 0;
|
||||
if (result)
|
||||
{
|
||||
await ClearUserInfo(0, userId);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -100,8 +135,8 @@ public class UnitUserService : IUnitUserService, ITransient
|
||||
unit_user result = new unit_user();
|
||||
try
|
||||
{
|
||||
var db = _dbClient.AsTenant().GetConnectionWithAttr<unit_user>();
|
||||
await _dbClient.AsTenant().BeginTranAsync();
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user>();
|
||||
await DbClient.AsTenant().BeginTranAsync();
|
||||
string userId = StringAssist.NewGuid;
|
||||
result.userId = userId;
|
||||
result.areaId = areaId;
|
||||
@@ -123,12 +158,12 @@ public class UnitUserService : IUnitUserService, ITransient
|
||||
result = null;
|
||||
}
|
||||
|
||||
await _dbClient.AsTenant().CommitTranAsync();
|
||||
await DbClient.AsTenant().CommitTranAsync();
|
||||
}
|
||||
catch
|
||||
{
|
||||
result = null;
|
||||
await _dbClient.AsTenant().RollbackTranAsync();
|
||||
await DbClient.AsTenant().RollbackTranAsync();
|
||||
}
|
||||
|
||||
return result;
|
||||
@@ -136,7 +171,7 @@ public class UnitUserService : IUnitUserService, ITransient
|
||||
|
||||
public async Task<bool> RegisterUserInfo(string userId, string nick, string sex)
|
||||
{
|
||||
var db = _dbClient.AsTenant().GetConnectionWithAttr<unit_user>();
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user>();
|
||||
bool result = await db.Updateable<unit_user>().SetColumns(it => it.nick == nick)
|
||||
.SetColumns(it => it.sex == sex)
|
||||
.SetColumns(it => it.regOk == 1)
|
||||
@@ -163,6 +198,15 @@ public class UnitUserService : IUnitUserService, ITransient
|
||||
unit_user_attr userAttr = GameTool.GetAttrData(1);
|
||||
userAttr.userId = userId;
|
||||
db.Insertable(userAttr).AddQueue();
|
||||
|
||||
//注册配置
|
||||
unit_user_config config = new unit_user_config();
|
||||
config.userId = userId;
|
||||
config.friendRole = 1;
|
||||
config.chatRole = 0;
|
||||
config.autoBag = -1;
|
||||
config.autoDrug = -1;
|
||||
db.Insertable(config).AddQueue();
|
||||
|
||||
//注册个人血量
|
||||
unit_user_blood blood = new unit_user_blood();
|
||||
@@ -248,10 +292,78 @@ public class UnitUserService : IUnitUserService, ITransient
|
||||
|
||||
public async Task<int> GetOnlineCount()
|
||||
{
|
||||
long time = TimeExtend.GetTimeStampBySeconds(DateTime.Now.AddMinutes(0-GameConfig.OnLineTime));
|
||||
var db = _dbClient.AsTenant().GetConnectionWithAttr<unit_user_online>();
|
||||
long time = TimeExtend.GetTimeStampBySeconds(DateTime.Now.AddMinutes(0 - GameConfig.OnLineTime));
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_online>();
|
||||
return await db.Queryable<unit_user_online>().Where(it => it.upTime > time).CountAsync();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 权限配置
|
||||
|
||||
public async Task<unit_user_config> GetUserConfigInfo(string userId)
|
||||
{
|
||||
string key = string.Format(UserCache.BaseCacheKeys, "UserInfo", "Config");
|
||||
var data = await redis.GetHashAsync<unit_user_config>(key, userId);
|
||||
if (data == null)
|
||||
{
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_config>();
|
||||
data = await db.Queryable<unit_user_config>().Where(it => it.userId == userId).SingleAsync();
|
||||
if (data != null)
|
||||
{
|
||||
await redis.AddHashAsync(key, userId, data);
|
||||
}
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
public async Task<int> GetUserConfigInfo(string userId, string code)
|
||||
{
|
||||
int result = 0;
|
||||
var config = await GetUserConfigInfo(userId);
|
||||
switch (code)
|
||||
{
|
||||
case "FriendRole":
|
||||
result = (int)config.friendRole;
|
||||
break;
|
||||
case "ChatRole":
|
||||
result = (int)config.chatRole;
|
||||
break;
|
||||
case "AutoBag":
|
||||
result = (int)config.autoBag;
|
||||
break;
|
||||
case "AutoDrug":
|
||||
result = (int)config.autoDrug;
|
||||
break;
|
||||
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private async Task ClearUserConfig(string userId)
|
||||
{
|
||||
string key = string.Format(UserCache.BaseCacheKeys, "UserInfo", "Config");
|
||||
await redis.DelHashAsync(key, userId);
|
||||
}
|
||||
|
||||
public async Task<bool> UpdateUserConfigInfo(string userId, string code, int state)
|
||||
{
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_config>();
|
||||
bool result = await db.Updateable<unit_user_config>()
|
||||
.SetColumnsIF(code == "FriendRole", it => it.friendRole == state)
|
||||
.SetColumnsIF(code == "ChatRole", it => it.chatRole == state)
|
||||
.SetColumnsIF(code == "AutoBag", it => it.autoBag == state)
|
||||
.SetColumnsIF(code == "AutoDrug", it => it.autoDrug == state)
|
||||
.Where(it => it.userId == userId).ExecuteCommandAsync() > 0;
|
||||
if (result)
|
||||
{
|
||||
await ClearUserConfig(userId);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -19,6 +19,7 @@ public class UserModelTool
|
||||
result.headImg = "";
|
||||
result.area = 0;
|
||||
result.icon = "";
|
||||
result.sign = "会陪你在航海的世界里浪迹天涯~";
|
||||
result.lev = 999;
|
||||
}
|
||||
else
|
||||
@@ -31,6 +32,7 @@ public class UserModelTool
|
||||
result.userNo = userInfo.userNo;
|
||||
result.nick = userInfo.nick;
|
||||
result.sex = userInfo.sex;
|
||||
result.sign = userInfo.sign;
|
||||
result.headImg = userInfo.headImg;
|
||||
result.area = (int)userInfo.areaId;
|
||||
result.icon = "";
|
||||
@@ -38,6 +40,7 @@ public class UserModelTool
|
||||
{
|
||||
result.icon = "";
|
||||
}
|
||||
|
||||
result.lev = await attrService.GetUserLev(userId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,11 +12,13 @@ public class ChatController : ControllerBase
|
||||
{
|
||||
private readonly IGameChatService _chatService;
|
||||
private readonly IGameGoodsService _goodsService;
|
||||
private readonly IUnitUserService _userService;
|
||||
|
||||
public ChatController(IGameChatService chatService, IGameGoodsService goodsService)
|
||||
public ChatController(IGameChatService chatService, IGameGoodsService goodsService, IUnitUserService userService)
|
||||
{
|
||||
_chatService = chatService;
|
||||
_goodsService = goodsService;
|
||||
_userService = userService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -53,8 +55,10 @@ public class ChatController : ControllerBase
|
||||
break;
|
||||
}
|
||||
|
||||
int chatRole = await _userService.GetUserConfigInfo(userId, nameof(UserEnum.ConfigCode.ChatRole)); //获取聊天权限
|
||||
|
||||
return PoAction.Ok(new { data, total = Total.Value, sendGoodsCount, sendGoodsName });
|
||||
|
||||
return PoAction.Ok(new { data, total = Total.Value, sendGoodsCount, sendGoodsName, chatRole });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -73,7 +77,7 @@ public class ChatController : ControllerBase
|
||||
string userId = StateHelper.userId;
|
||||
int areaId = StateHelper.areaId;
|
||||
string par = string.Empty;
|
||||
string code = GameChatEnum.Code.Public.ToString();
|
||||
string code = nameof(GameChatEnum.Code.Public);
|
||||
int goodsId = 0;
|
||||
bool isSend = false;
|
||||
switch (pars.type)
|
||||
@@ -110,12 +114,35 @@ public class ChatController : ControllerBase
|
||||
return PoAction.Message("无法发言!");
|
||||
}
|
||||
|
||||
int chatRole = await _userService.GetUserConfigInfo(userId, nameof(UserEnum.ConfigCode.ChatRole));
|
||||
if (chatRole < 0)
|
||||
{
|
||||
return PoAction.Message("发言权限已被系统限制!");
|
||||
}
|
||||
|
||||
bool upGoods = true;
|
||||
if (goodsId != 0)
|
||||
{
|
||||
var myCount = await _goodsService.GetUserGoodsCount(userId, goodsId);
|
||||
if (myCount < 1)
|
||||
bool checkGoods = true;
|
||||
|
||||
if ((nameof(GameChatEnum.Code.Region) == code || nameof(GameChatEnum.Code.Public) == code) && chatRole > 0)
|
||||
{
|
||||
return PoAction.Message("暂无发言道具,去商城购买海螺才可以发言哦!");
|
||||
checkGoods = false;
|
||||
upGoods = false;
|
||||
}
|
||||
else if (nameof(GameChatEnum.Code.Dress) == code && chatRole > 1)
|
||||
{
|
||||
checkGoods = false;
|
||||
upGoods = false;
|
||||
}
|
||||
|
||||
if (checkGoods)
|
||||
{
|
||||
var myCount = await _goodsService.GetUserGoodsCount(userId, goodsId);
|
||||
if (myCount < 1)
|
||||
{
|
||||
return PoAction.Message("暂无发言道具,去商城购买海螺才可以发言哦!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -123,7 +150,7 @@ public class ChatController : ControllerBase
|
||||
bool result = await _chatService.SendChat(userId, areaId, code, sign, par);
|
||||
if (result)
|
||||
{
|
||||
if (goodsId != 0) //扣除道具
|
||||
if (goodsId != 0 && upGoods) //扣除道具
|
||||
{
|
||||
await _goodsService.UpdateUserGoods(userId, 0, goodsId, 1, "发言");
|
||||
}
|
||||
@@ -135,4 +162,56 @@ public class ChatController : ControllerBase
|
||||
return PoAction.Message("发送失败,请稍后尝试!");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除聊天记录
|
||||
/// </summary>
|
||||
/// <param name="chatId"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public async Task<IPoAction> DeleteChat(string chatId)
|
||||
{
|
||||
var chatInfo = await _chatService.GetChatInfo(chatId);
|
||||
if (chatInfo == null)
|
||||
{
|
||||
return PoAction.Message("发言不存在!");
|
||||
}
|
||||
|
||||
if (chatInfo.state != 1)
|
||||
{
|
||||
return PoAction.Message("发言不存在!");
|
||||
}
|
||||
|
||||
if (chatInfo.areaId != StateHelper.areaId)
|
||||
{
|
||||
return PoAction.Message("发言不存在!");
|
||||
}
|
||||
|
||||
bool IsOp = false;
|
||||
string userId = StateHelper.userId;
|
||||
int chatRole = await _userService.GetUserConfigInfo(userId, nameof(UserEnum.ConfigCode.ChatRole));
|
||||
if ((chatInfo.code == nameof(GameChatEnum.Code.Public) || chatInfo.code == nameof(GameChatEnum.Code.Region)) &&
|
||||
chatRole > 0)
|
||||
{
|
||||
IsOp = true;
|
||||
}
|
||||
else if (chatRole > 1 && chatInfo.code == nameof(GameChatEnum.Code.Dress))
|
||||
{
|
||||
IsOp = true;
|
||||
}
|
||||
|
||||
if (IsOp == false)
|
||||
{
|
||||
return PoAction.Message("无权限!");
|
||||
}
|
||||
|
||||
if (await _chatService.DeleteChat(chatId, userId))
|
||||
{
|
||||
return PoAction.Ok(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
return PoAction.Message("操作失败,请稍后尝试!");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -158,7 +158,7 @@ namespace Application.Web.Controllers.Login
|
||||
{
|
||||
return PoAction.Message("暂未开放本区服!");
|
||||
}
|
||||
|
||||
|
||||
//判断是否已经注册
|
||||
var userData = await _userService.GetUserDataByAccId(accInfo.accId);
|
||||
if (userData.Any(it => it.areaId == area))
|
||||
@@ -247,7 +247,7 @@ namespace Application.Web.Controllers.Login
|
||||
string Key = App.Configuration["JwtTokenOptions:SecurityKey"].ToString();
|
||||
string Issuer = App.Configuration["JwtTokenOptions:Issuer"].ToString();
|
||||
string Audience = App.Configuration["JwtTokenOptions:Audience"].ToString();
|
||||
|
||||
|
||||
string accId = string.Empty;
|
||||
var tokenData = await JwtTool.GetJwtData(parms.token, Key, "accId");
|
||||
if (tokenData != null)
|
||||
@@ -297,13 +297,53 @@ namespace Application.Web.Controllers.Login
|
||||
string sex = parms.sex == 0 ? "女" : "男";
|
||||
string userId = StateHelper.userId;
|
||||
var userInfo = await _userService.GetUserInfoByUserId(userId);
|
||||
if (userInfo == null)
|
||||
{
|
||||
return PoAction.Message("角色不存在!");
|
||||
}
|
||||
|
||||
if (userInfo.regOk == 1)
|
||||
{
|
||||
return PoAction.Ok(true);
|
||||
}
|
||||
|
||||
var areaInfo = await _areaService.GetAreaInfo((int)userInfo.areaId);
|
||||
if (areaInfo.isNeedCode == 1) //需要激活码
|
||||
{
|
||||
if (string.IsNullOrEmpty(parms.code))
|
||||
{
|
||||
return PoAction.Message("请输入激活码!");
|
||||
}
|
||||
|
||||
var ackInfo = await _areaService.GetAckInfo(parms.code);
|
||||
if (ackInfo == null)
|
||||
{
|
||||
return PoAction.Message("激活码过期!");
|
||||
}
|
||||
|
||||
if (ackInfo.status != 0)
|
||||
{
|
||||
return PoAction.Message("激活码过期!");
|
||||
}
|
||||
|
||||
if (ackInfo.areaId != 0 && ackInfo.areaId != areaInfo.areaId)
|
||||
{
|
||||
return PoAction.Message($"当前激活码可用于{ackInfo.areaId}区激活!");
|
||||
}
|
||||
}
|
||||
|
||||
if (await _userService.CheckUserNickIsAt(parms.nick))
|
||||
{
|
||||
return PoAction.Message("昵称已存在!");
|
||||
}
|
||||
|
||||
if (await _userService.RegisterUserInfo(userId, parms.nick, sex))
|
||||
{
|
||||
if (areaInfo.isNeedCode == 1)
|
||||
{
|
||||
await _areaService.UseAck(parms.code, userId);
|
||||
}
|
||||
|
||||
return PoAction.Ok(true);
|
||||
}
|
||||
else
|
||||
|
||||
@@ -119,7 +119,7 @@ public class MapController : ControllerBase
|
||||
page,
|
||||
10, Total);
|
||||
|
||||
return PoAction.Ok(new { data, total = Total.Value });
|
||||
return PoAction.Ok(new { data, total = Total.Value, map = mapInfo });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -106,6 +106,28 @@ namespace Application.Web.Controllers.Pub
|
||||
}
|
||||
return PoAction.Ok(userData);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取区服信息
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public async Task<IPoAction> GetOnAreaInfo()
|
||||
{
|
||||
int areaId = StateHelper.areaId;
|
||||
var areaInfo = await _areaService.GetAreaInfo(areaId);
|
||||
if (areaInfo == null)
|
||||
{
|
||||
return PoAction.Message("区服不存在!");
|
||||
}
|
||||
|
||||
if (areaInfo.status != 1)
|
||||
{
|
||||
return PoAction.Message("当前区服繁忙!");
|
||||
}
|
||||
|
||||
return PoAction.Ok(areaInfo);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -14,13 +14,15 @@ public class RelationController : ControllerBase
|
||||
private readonly IUnitUserRelationService _relationService;
|
||||
private readonly IUnitUserService _userService;
|
||||
private readonly IMessageService _messageService;
|
||||
private readonly IUnitUserAccService _accService;
|
||||
|
||||
public RelationController(IUnitUserRelationService relationService, IUnitUserService userService,
|
||||
IMessageService messageService)
|
||||
IMessageService messageService, IUnitUserAccService accService)
|
||||
{
|
||||
_relationService = relationService;
|
||||
_userService = userService;
|
||||
_messageService = messageService;
|
||||
_accService = accService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -51,10 +53,23 @@ public class RelationController : ControllerBase
|
||||
.ThenByDescending(it => it.sort).ToList();
|
||||
result = PageExtend.GetPageList(data, page, 10);
|
||||
}
|
||||
else if (type == 3)
|
||||
{
|
||||
var data = await _relationService.GetUserEnemyData(userId);
|
||||
total = data.Count;
|
||||
data = data.OrderByDescending(it => it.isOnline)
|
||||
.ThenByDescending(it => it.sort).ToList();
|
||||
result = PageExtend.GetPageList(data, page, 10);
|
||||
}
|
||||
|
||||
return PoAction.Ok(new { data = result, total = total.Value, online = result.Count(it => it.isOnline == 1) });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 好友处理
|
||||
/// </summary>
|
||||
/// <param name="no"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public async Task<IPoAction> FriendHandle(string no)
|
||||
{
|
||||
@@ -76,8 +91,33 @@ public class RelationController : ControllerBase
|
||||
}
|
||||
|
||||
bool IsFriend = await _relationService.CheckIsFriend(userId, userInfo.userId);
|
||||
if (IsFriend == false)
|
||||
if (IsFriend == false) //添加好友
|
||||
{
|
||||
var friendRole =
|
||||
await _userService.GetUserConfigInfo(userInfo.userId, nameof(UserEnum.ConfigCode.FriendRole));
|
||||
if (friendRole == 0)
|
||||
{
|
||||
return PoAction.Message("该玩家拒绝任何人添加好友!");
|
||||
}
|
||||
|
||||
var friendCount = await _relationService.GetUserFriendCount(userId);
|
||||
if (friendCount >= GameConfig.GameUserFriendMaxCount)
|
||||
{
|
||||
return PoAction.Message("好友人数已达上限!");
|
||||
}
|
||||
|
||||
if (friendRole == 2)//不限制加好友
|
||||
{
|
||||
if (await _relationService.AddFriend(userId, userInfo.userId))
|
||||
{
|
||||
return PoAction.Ok(true, "添加好友成功!");
|
||||
}
|
||||
else
|
||||
{
|
||||
return PoAction.Ok(true, "添加好友失败,请稍后尝试!");
|
||||
}
|
||||
}
|
||||
|
||||
string token = $"{nameof(MessageEnum.EventCode.Friend)}_{userId}_{userInfo.userId}";
|
||||
if (await _messageService.CheckAtEventMsg(token))
|
||||
{
|
||||
@@ -114,4 +154,91 @@ public class RelationController : ControllerBase
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除仇人
|
||||
/// </summary>
|
||||
/// <param name="no"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public async Task<IPoAction> DeleteEnemy(string no)
|
||||
{
|
||||
string userId = StateHelper.userId;
|
||||
var userInfo = await _userService.GetUserInfoByUserNo(no); //基础资料
|
||||
if (userInfo == null)
|
||||
{
|
||||
return PoAction.Message("玩家不存在!");
|
||||
}
|
||||
|
||||
bool IsEnemy = await _relationService.CheckUserEnemy(userId, userInfo.userId);
|
||||
if (IsEnemy == false)
|
||||
{
|
||||
return PoAction.Message("不是仇人,无需删除哦");
|
||||
}
|
||||
|
||||
bool result = await _relationService.DeleteUserEnemy(userId, userInfo.userId);
|
||||
if (result)
|
||||
{
|
||||
return PoAction.Ok(true, "删除成功!");
|
||||
}
|
||||
else
|
||||
{
|
||||
return PoAction.Message("删除失败,请稍后尝试.");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加仇人
|
||||
/// </summary>
|
||||
/// <param name="no"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public async Task<IPoAction> AddEnemy(string no)
|
||||
{
|
||||
string userId = StateHelper.userId;
|
||||
var userInfo = await _userService.GetUserInfoByUserNo(no); //基础资料
|
||||
if (userInfo == null)
|
||||
{
|
||||
return PoAction.Message("玩家不存在!");
|
||||
}
|
||||
|
||||
if (userInfo.userId == userId)
|
||||
{
|
||||
return PoAction.Message("不能加自己为仇人!");
|
||||
}
|
||||
|
||||
if (userInfo.areaId != StateHelper.areaId)
|
||||
{
|
||||
return PoAction.Message("玩家不存在!");
|
||||
}
|
||||
|
||||
bool IsEnemy = await _relationService.CheckUserEnemy(userId, userInfo.userId);
|
||||
if (IsEnemy == true)
|
||||
{
|
||||
return PoAction.Message("已经是仇人啦,无需重复添加!");
|
||||
}
|
||||
|
||||
var myAcc = await _accService.GetUserAccInfo(userId, nameof(AccEnum.AccType.gold));
|
||||
if (myAcc < GameConfig.GameRelationEnemyNeedGold)
|
||||
{
|
||||
return PoAction.Message("您的金元不足!");
|
||||
}
|
||||
|
||||
if (await _accService.UpdateUserAcc(userId, 0, nameof(AccEnum.AccType.gold),
|
||||
GameConfig.GameRelationEnemyNeedGold, nameof(AccEnum.Name.其他), "添加仇人"))
|
||||
{
|
||||
if (await _relationService.AddUserEnemy(userId, userInfo.userId))
|
||||
{
|
||||
return PoAction.Ok(true, "仇人添加成功!");
|
||||
}
|
||||
else
|
||||
{
|
||||
return PoAction.Message("添加失败,请稍后尝试.");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return PoAction.Message("添加失败,请稍后尝试.");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -13,18 +13,22 @@ public class UserController : ControllerBase
|
||||
private readonly IUnitUserAccService _accService;
|
||||
private readonly IGameMapService _mapService;
|
||||
private readonly IUnitUserRelationService _relationService;
|
||||
private readonly IGameGoodsService _goodsService;
|
||||
private readonly IGameChatService _chatService;
|
||||
|
||||
public UserController(IUnitUserService userService, IUnitUserAttrService attrService,
|
||||
IUnitUserAccService accService, IGameMapService mapService,IUnitUserRelationService relationService)
|
||||
IUnitUserAccService accService, IGameMapService mapService, IUnitUserRelationService relationService,
|
||||
IGameGoodsService goodsService, IGameChatService chatService)
|
||||
{
|
||||
_userService = userService;
|
||||
_attrService = attrService;
|
||||
_accService = accService;
|
||||
_mapService = mapService;
|
||||
_relationService = relationService;
|
||||
_goodsService = goodsService;
|
||||
_chatService = chatService;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取个人资料信息
|
||||
@@ -53,27 +57,34 @@ public class UserController : ControllerBase
|
||||
/// <param name="no"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public async Task<IPoAction> GetUserBaseInfo(string no)
|
||||
public async Task<IPoAction> GetUserBaseInfo(string? no)
|
||||
{
|
||||
string userId = StateHelper.userId;
|
||||
var userInfo = await _userService.GetUserInfoByUserNo(no); //基础资料
|
||||
if (userInfo == null)
|
||||
if (!string.IsNullOrEmpty(no))
|
||||
{
|
||||
return PoAction.Message("玩家不存在!", 102);
|
||||
var userInfo = await _userService.GetUserInfoByUserNo(no); //基础资料
|
||||
if (userInfo == null)
|
||||
{
|
||||
return PoAction.Message("玩家不存在!", 102);
|
||||
}
|
||||
|
||||
if (userInfo.userId == userId)
|
||||
{
|
||||
return PoAction.Message("用户本身!", 101);
|
||||
}
|
||||
|
||||
if (userInfo.areaId != StateHelper.areaId)
|
||||
{
|
||||
return PoAction.Message("玩家不存在!", 102);
|
||||
}
|
||||
|
||||
userId = userInfo.userId;
|
||||
}
|
||||
|
||||
if (userInfo.userId == userId)
|
||||
{
|
||||
return PoAction.Message("用户本身!", 101);
|
||||
}
|
||||
if (userInfo.areaId != StateHelper.areaId)
|
||||
{
|
||||
return PoAction.Message("玩家不存在!", 102);
|
||||
}
|
||||
|
||||
var model = await UserModelTool.GetUserView(userInfo.userId);
|
||||
var model = await UserModelTool.GetUserView(userId);
|
||||
return PoAction.Ok(model);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取用户资料
|
||||
/// </summary>
|
||||
@@ -93,6 +104,7 @@ public class UserController : ControllerBase
|
||||
{
|
||||
return PoAction.Message("用户本身!", 101);
|
||||
}
|
||||
|
||||
if (userInfo.areaId != StateHelper.areaId)
|
||||
{
|
||||
return PoAction.Message("玩家不存在!", 102);
|
||||
@@ -112,7 +124,126 @@ public class UserController : ControllerBase
|
||||
var onCity = await _mapService.GetCityInfo((int)onMapInfo.cityId);
|
||||
string onMapName = $"{onCity.cityName}-{onMapInfo.mapName}";
|
||||
bool isFriend = await _relationService.CheckIsFriend(userId, userInfo.userId);
|
||||
object result = new { user, attr = new { attrInfo.lev }, acc, isOnline, onMapName ,isFriend};
|
||||
bool isEnemy = await _relationService.CheckUserEnemy(userId, userInfo.userId);
|
||||
object result = new { user, attr = new { attrInfo.lev }, acc, isOnline, onMapName, isFriend, isEnemy };
|
||||
return PoAction.Ok(result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新昵称
|
||||
/// </summary>
|
||||
/// <param name="parms"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<IPoAction> UpdateUserNick([FromBody] UpdateNickParms parms)
|
||||
{
|
||||
parms.nick = StringAssist.NoHTML(parms.nick);
|
||||
if (string.IsNullOrEmpty(parms.nick))
|
||||
{
|
||||
return PoAction.Message("昵称不能为空!");
|
||||
}
|
||||
|
||||
string userId = StateHelper.userId;
|
||||
var userInfo = await _userService.GetUserInfoByUserId(userId);
|
||||
if (userInfo.nick == parms.nick)
|
||||
{
|
||||
return PoAction.Message("昵称无变化,无需修改!");
|
||||
}
|
||||
|
||||
if (await _userService.CheckUserNickIsAt(parms.nick))
|
||||
{
|
||||
return PoAction.Message("昵称已存在!");
|
||||
}
|
||||
|
||||
|
||||
var myGoods = await _goodsService.GetUserGoodsCount(userId, GameConfig.GameUpdateNickNeedGoods);
|
||||
if (myGoods < 1)
|
||||
{
|
||||
return PoAction.Message("暂无改名道具!");
|
||||
}
|
||||
|
||||
if (await _goodsService.UpdateUserGoods(userId, 0, GameConfig.GameUpdateNickNeedGoods, 1, "改名使用"))
|
||||
{
|
||||
if (await _userService.UpdateUserNick(userId, parms.nick))
|
||||
{
|
||||
string sign = $"玩家注意:【{UbbTool.HomeUbb(userInfo.userNo, userInfo.nick)}】已将昵称修改为【{parms.nick}】";
|
||||
await _chatService.SendChat("0", StateHelper.areaId, nameof(GameChatEnum.Code.Region), sign);
|
||||
return PoAction.Ok(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
return PoAction.Message("操作失败,请稍后尝试!");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return PoAction.Message("操作失败,请稍后尝试!");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 变更性别
|
||||
/// </summary>
|
||||
/// <param name="parms"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<IPoAction> UpdateUserSex([FromBody] UpdateSexParms parms)
|
||||
{
|
||||
parms.sex = parms.sex == "男" ? "男" : "女";
|
||||
|
||||
string userId = StateHelper.userId;
|
||||
var userInfo = await _userService.GetUserInfoByUserId(userId);
|
||||
if (userInfo.sex == parms.sex)
|
||||
{
|
||||
return PoAction.Message("已是当前性别,无需修改!");
|
||||
}
|
||||
|
||||
var myGoods = await _goodsService.GetUserGoodsCount(userId, GameConfig.GameUpdateSexNeedGoods);
|
||||
if (myGoods < 1)
|
||||
{
|
||||
return PoAction.Message("暂无性别变更道具!");
|
||||
}
|
||||
|
||||
if (await _goodsService.UpdateUserGoods(userId, 0, GameConfig.GameUpdateSexNeedGoods, 1, "变更性别使用"))
|
||||
{
|
||||
if (await _userService.UpdateUserSex(userId, parms.sex))
|
||||
{
|
||||
return PoAction.Ok(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
return PoAction.Message("操作失败,请稍后尝试!");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return PoAction.Message("操作失败,请稍后尝试!");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新签名
|
||||
/// </summary>
|
||||
/// <param name="parms"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<IPoAction> UpdateUserSign([FromBody] UpdateSignParms parms)
|
||||
{
|
||||
if (parms.sign.Length > 80)
|
||||
{
|
||||
return PoAction.Message("签名不能超过80个字符!");
|
||||
}
|
||||
|
||||
parms.sign = StringAssist.NoHTML(parms.sign);
|
||||
string userId = StateHelper.userId;
|
||||
|
||||
if (await _userService.UpdateUserSign(userId, parms.sign))
|
||||
{
|
||||
return PoAction.Ok(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
return PoAction.Message("操作失败,请稍后尝试!");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,4 +4,5 @@ public class RegisterInfoParms
|
||||
{
|
||||
public string nick { get; set; } = string.Empty;
|
||||
public int sex { get; set; }
|
||||
public string code { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace Application.Web;
|
||||
|
||||
public class UpdateNickParms
|
||||
{
|
||||
public string nick { get; set; }
|
||||
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace Application.Web;
|
||||
|
||||
public class UpdateSexParms
|
||||
{
|
||||
public string sex { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace Application.Web;
|
||||
|
||||
public class UpdateSignParms
|
||||
{
|
||||
public string sign { get; set; }
|
||||
}
|
||||
@@ -5,7 +5,7 @@
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"launchBrowser": false,
|
||||
"applicationUrl": "http://localhost:5031",
|
||||
"applicationUrl": "http://localhost:5031;http://192.168.0.110:5032",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user