268 lines
9.2 KiB
C#
268 lines
9.2 KiB
C#
using Microsoft.AspNetCore.Mvc;
|
|
|
|
namespace Application.Web.Controllers.User;
|
|
|
|
/// <summary>
|
|
/// 关系接口
|
|
/// </summary>
|
|
[ApiExplorerSettings(GroupName = "User")]
|
|
[Route("User/[controller]/[action]")]
|
|
[ApiController]
|
|
[Authorize]
|
|
public class RelationController : ControllerBase
|
|
{
|
|
private readonly IUnitUserRelationService _relationService;
|
|
private readonly IUnitUserService _userService;
|
|
private readonly IMessageService _messageService;
|
|
private readonly IUnitUserAccService _accService;
|
|
private readonly IUnitUserAttrService _attrService;
|
|
private readonly IGameChatService _chatService;
|
|
|
|
public RelationController(IUnitUserRelationService relationService, IUnitUserService userService,
|
|
IMessageService messageService, IUnitUserAccService accService,IUnitUserAttrService attrService,IGameChatService chatService)
|
|
{
|
|
_relationService = relationService;
|
|
_userService = userService;
|
|
_messageService = messageService;
|
|
_accService = accService;
|
|
_attrService = attrService;
|
|
_chatService = chatService;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 关系列表数据
|
|
/// </summary>
|
|
/// <param name="type"></param>
|
|
/// <param name="page"></param>
|
|
/// <returns></returns>
|
|
[HttpGet]
|
|
public async Task<IPoAction> GetRelation(int type, int page)
|
|
{
|
|
string userId = StateHelper.userId;
|
|
RefAsync<int> total = 0;
|
|
List<RelationView> result = new List<RelationView>();
|
|
if (type == 0)
|
|
{
|
|
var data = await _relationService.GetUserFriend(userId);
|
|
total = data.Count;
|
|
data = data.OrderByDescending(it => it.isOnline).ThenByDescending(it => it.sort).ToList();
|
|
result = PageExtend.GetPageList(data, page, 10);
|
|
}
|
|
else if (type == 1)
|
|
{
|
|
var data = await _relationService.GetUserFriend(userId);
|
|
data = data.FindAll(it => it.near >= 1000);
|
|
total = data.Count;
|
|
data = data.OrderByDescending(it => it.isOnline).ThenByDescending(it => it.near)
|
|
.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)
|
|
{
|
|
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 IsFriend = await _relationService.CheckIsFriend(userId, userInfo.userId);
|
|
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))
|
|
{
|
|
return PoAction.Message("已发送过交友消息,等待对方通过!");
|
|
}
|
|
|
|
var myInfo = await _userService.GetUserInfoByUserId(userId);
|
|
string sign = $"{UbbTool.HomeUbb(myInfo.userNo, myInfo.nick)} 希望添加您为好友?";
|
|
List<MsgEventBtn> btns = new List<MsgEventBtn>()
|
|
{
|
|
new MsgEventBtn() { status = 1, name = "通过", tips = "已通过申请" },
|
|
new MsgEventBtn() { status = 2, name = "拒绝", tips = "已拒绝申请" }
|
|
};
|
|
if (await _messageService.SendEventMsg(userInfo.userId, nameof(MessageEnum.EventCode.Friend), "交友消息通知",
|
|
sign, userId, token, btns, 3))
|
|
{
|
|
return PoAction.Ok(true, "好友申请已发送,请等待对方确认!");
|
|
}
|
|
else
|
|
{
|
|
return PoAction.Message("添加失败,请稍后尝试!");
|
|
}
|
|
}
|
|
else //删除好友
|
|
{
|
|
bool result = await _relationService.DeleteFriend(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> 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("已经是仇人啦,无需重复添加!");
|
|
}
|
|
|
|
int needGold = GameConfig.GameRelationEnemyNeedGold;
|
|
int lev = await _attrService.GetUserLev(userInfo.userId);
|
|
if (lev <= 30)
|
|
{
|
|
return PoAction.Message("对方不大于30级无法添加加为仇人!");
|
|
}
|
|
|
|
if (lev > 120 && lev <= 220)
|
|
{
|
|
needGold = needGold * 3;
|
|
}
|
|
else if (lev > 220)
|
|
{
|
|
needGold = needGold * 5;
|
|
}
|
|
|
|
var myAcc = await _accService.GetUserAccInfo(userId, nameof(AccEnum.AccType.gold));
|
|
if (myAcc < needGold)
|
|
{
|
|
return PoAction.Message("您的金元不足!");
|
|
}
|
|
|
|
if (await _accService.UpdateUserAcc(userId, 0, nameof(AccEnum.AccType.gold),
|
|
needGold, nameof(AccEnum.Name.其他), "添加仇人"))
|
|
{
|
|
if (await _relationService.AddUserEnemy(userId, userInfo.userId))
|
|
{
|
|
var myInfo = await _userService.GetUserInfoByUserId(userId);
|
|
string msg = $"请注意,您已被[{UbbTool.HomeUbb(myInfo.userNo, myInfo.nick)}]添加为仇人,被对方击杀将会受到严重惩罚!";
|
|
await _chatService.SendChat(userInfo.userId, (int)userInfo.areaId, nameof(GameChatEnum.Code.Notice), msg);
|
|
|
|
return PoAction.Ok(true, "仇人添加成功!");
|
|
}
|
|
else
|
|
{
|
|
return PoAction.Message("添加失败,请稍后尝试.");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
return PoAction.Message("添加失败,请稍后尝试.");
|
|
}
|
|
}
|
|
} |