121
This commit is contained in:
@@ -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("添加失败,请稍后尝试.");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user