2024-10-13 12:22:08 +08:00
|
|
|
|
using AngleSharp.Text;
|
2024-10-21 18:39:25 +08:00
|
|
|
|
using Flandre.Core.Common;
|
|
|
|
|
using Flandre.Core.Messaging.Segments;
|
|
|
|
|
using Flandre.Core.Messaging;
|
2024-10-13 12:22:08 +08:00
|
|
|
|
using Manganese.Array;
|
2024-10-10 21:08:04 +08:00
|
|
|
|
using Masuit.Tools;
|
2024-08-20 17:32:06 +08:00
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
|
|
using Microsoft.AspNetCore.Identity;
|
2024-08-20 17:20:58 +08:00
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
2024-10-11 21:28:37 +08:00
|
|
|
|
using Microsoft.AspNetCore.Mvc.Abstractions;
|
2024-08-20 17:32:06 +08:00
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
2024-10-11 19:56:53 +08:00
|
|
|
|
using System;
|
2024-08-20 17:32:06 +08:00
|
|
|
|
using System.Security.Claims;
|
2024-10-11 19:56:53 +08:00
|
|
|
|
using System.Text.Json;
|
2024-10-11 21:28:37 +08:00
|
|
|
|
using System.Threading.Tasks;
|
2024-10-13 12:22:08 +08:00
|
|
|
|
using static System.Runtime.InteropServices.JavaScript.JSType;
|
2024-08-20 17:20:58 +08:00
|
|
|
|
|
|
|
|
|
namespace asg_form.Controllers
|
2024-08-17 15:38:44 +08:00
|
|
|
|
{
|
2024-08-20 17:20:58 +08:00
|
|
|
|
public class InviteReferee : ControllerBase
|
|
|
|
|
{
|
|
|
|
|
private readonly RoleManager<Role> roleManager;
|
|
|
|
|
private readonly UserManager<User> userManager;
|
|
|
|
|
public InviteReferee(
|
|
|
|
|
RoleManager<Role> roleManager, UserManager<User> userManager)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
this.roleManager = roleManager;
|
|
|
|
|
this.userManager = userManager;
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-11 19:56:53 +08:00
|
|
|
|
public class idRequest
|
|
|
|
|
{
|
|
|
|
|
public int invited_id { get; set; }
|
|
|
|
|
public int match_id { get; set; }
|
|
|
|
|
}
|
2024-10-10 09:59:47 +08:00
|
|
|
|
public class InviteBg
|
|
|
|
|
{
|
|
|
|
|
public int id { get; set; }
|
2024-10-10 16:08:18 +08:00
|
|
|
|
public int user_id { get; set; }
|
2024-10-13 12:22:08 +08:00
|
|
|
|
public int invited_id { get; set; }
|
|
|
|
|
public int match_id { get; set; }
|
|
|
|
|
public int status { get; set; }
|
2024-10-10 16:08:18 +08:00
|
|
|
|
|
2024-10-13 12:22:08 +08:00
|
|
|
|
public string? create_time { get; set; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class InviteForUsers
|
|
|
|
|
{
|
2024-10-13 20:07:08 +08:00
|
|
|
|
public int id { get; set; }
|
2024-10-13 12:22:08 +08:00
|
|
|
|
public string invitedChinaname { get; set; }
|
|
|
|
|
public schedule.team_game match { get; set; }
|
2024-10-13 20:07:08 +08:00
|
|
|
|
public int status { get; set; }
|
2024-10-10 09:59:47 +08:00
|
|
|
|
|
2024-10-13 12:22:08 +08:00
|
|
|
|
public string? create_time { get; set; }
|
2024-10-10 09:59:47 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-10-10 16:08:18 +08:00
|
|
|
|
public class inv
|
|
|
|
|
{
|
|
|
|
|
public int invitedId { get; set; }
|
|
|
|
|
public int matchId { get; set; }
|
2024-10-13 21:19:05 +08:00
|
|
|
|
}
|
2024-10-11 19:56:53 +08:00
|
|
|
|
|
2024-08-20 17:32:06 +08:00
|
|
|
|
[Route("api/v1/Invite")]
|
2024-10-10 16:08:18 +08:00
|
|
|
|
[HttpPost]
|
2024-08-20 17:32:06 +08:00
|
|
|
|
[Authorize]
|
2024-10-11 21:28:37 +08:00
|
|
|
|
public async Task<ActionResult<object>> Toinvite([FromBody] inv msg)
|
2024-08-20 17:32:06 +08:00
|
|
|
|
{
|
2024-10-13 20:07:08 +08:00
|
|
|
|
|
2024-08-20 17:32:06 +08:00
|
|
|
|
string Invitorid = this.User.FindFirst(ClaimTypes.NameIdentifier)!.Value;
|
|
|
|
|
var user = await userManager.FindByIdAsync(Invitorid);
|
2024-10-10 09:59:47 +08:00
|
|
|
|
long userId = user.Id;
|
2024-10-19 13:45:13 +08:00
|
|
|
|
if (user.officium != "Commentator" ) return Ok(new error_mb { code = 401, message = "您不是解说无法完成邀请" });
|
2024-08-20 17:32:06 +08:00
|
|
|
|
using (TestDbContext sb = new TestDbContext())
|
|
|
|
|
{
|
2024-10-10 09:59:47 +08:00
|
|
|
|
try
|
|
|
|
|
{
|
2024-10-13 12:22:08 +08:00
|
|
|
|
var invited = await userManager.Users.FirstOrDefaultAsync(u => u.Id == msg.invitedId);
|
2024-10-13 12:38:01 +08:00
|
|
|
|
if (invited == null) return Ok(new { code = 404, message = "用户未找到" });
|
2024-10-13 12:22:08 +08:00
|
|
|
|
var isInvited = await sb.T_Invitation.AnyAsync(i => i.user_id == userId && i.invited_id==msg.invitedId && i.match_id==msg.matchId);
|
|
|
|
|
if (!isInvited)
|
2024-10-10 16:08:18 +08:00
|
|
|
|
{
|
2024-10-13 12:22:08 +08:00
|
|
|
|
string createTime = DateTime.Now.ToString();
|
|
|
|
|
var invitation = new InviteBg
|
2024-10-10 16:08:18 +08:00
|
|
|
|
{
|
2024-10-13 12:22:08 +08:00
|
|
|
|
user_id = (int)userId,
|
|
|
|
|
invited_id = msg.invitedId,
|
|
|
|
|
match_id = msg.matchId,
|
|
|
|
|
status = 0,
|
|
|
|
|
create_time = createTime,
|
|
|
|
|
};
|
|
|
|
|
sb.Add(invitation);
|
|
|
|
|
sb.SaveChanges();
|
|
|
|
|
var match = sb.team_Games.FirstOrDefault(n => n.id == msg.matchId);
|
2024-10-21 18:39:25 +08:00
|
|
|
|
if(match == null) return Ok(new { code = 200, message = "未找到比赛" });
|
2024-10-13 12:22:08 +08:00
|
|
|
|
var data = new
|
2024-10-10 22:42:58 +08:00
|
|
|
|
{
|
2024-10-13 12:22:08 +08:00
|
|
|
|
userName = user.chinaname,
|
|
|
|
|
invitedName = invited.chinaname,
|
|
|
|
|
match
|
2024-10-10 22:42:58 +08:00
|
|
|
|
};
|
2024-10-21 18:39:25 +08:00
|
|
|
|
string mesg = $"[ASG管理系统]解说{invited.chinaname}同学,您收到一条来自解说{user.chinaname}同学的解说邀约,时间为{match.opentime},请您根据自身时间安排,前往解说端确认是否接受邀请。";
|
|
|
|
|
string qqgroup = "925510646";
|
|
|
|
|
var atuserqq = invited.qqnumber;
|
|
|
|
|
if (atuserqq == null) return Ok(new { code = 500, message = "服务器错误" });
|
|
|
|
|
var message = new MessageBuilder().Add(new AtSegment(atuserqq)).Text(mesg).Build();
|
|
|
|
|
|
|
|
|
|
await runbot.runbotr.SendMessageAsync(MessageEnvironment.Channel, qqgroup, null, message, qqgroup);
|
2024-10-13 12:22:08 +08:00
|
|
|
|
return Ok(new { code = 200, message = "成功发送邀请" ,data});
|
2024-10-10 22:42:58 +08:00
|
|
|
|
}
|
2024-10-13 12:22:08 +08:00
|
|
|
|
return Ok(new { code = 200, message = "已经在本场次邀请过这个人" });
|
|
|
|
|
}
|
2024-10-10 16:08:18 +08:00
|
|
|
|
catch (Exception ex)
|
2024-10-10 09:59:47 +08:00
|
|
|
|
{
|
2024-10-13 12:22:08 +08:00
|
|
|
|
return Ok(new { code = 500, message = "服务器错误", details = ex });
|
2024-10-10 09:59:47 +08:00
|
|
|
|
}
|
2024-08-20 17:32:06 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2024-10-11 21:28:37 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[Route("api/v1/myInvitation")]
|
|
|
|
|
[HttpGet]
|
|
|
|
|
[Authorize]
|
|
|
|
|
public async Task<ActionResult<object>> GetMyInvitor([FromQuery]short page = 1, short limit = 6)
|
|
|
|
|
{
|
|
|
|
|
string Forid = this.User.FindFirst(ClaimTypes.NameIdentifier)!.Value;
|
|
|
|
|
var user = await userManager.FindByIdAsync(Forid);
|
|
|
|
|
long userId = user.Id;
|
|
|
|
|
|
2024-10-12 10:35:04 +08:00
|
|
|
|
int wrongPart = -1;
|
|
|
|
|
|
2024-10-11 21:28:37 +08:00
|
|
|
|
using (TestDbContext sub = new TestDbContext())
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2024-10-13 12:22:08 +08:00
|
|
|
|
var query = sub.T_Invitation
|
|
|
|
|
.AsQueryable();
|
2024-10-13 20:07:08 +08:00
|
|
|
|
var TotalRecords = 0;
|
2024-10-13 12:22:08 +08:00
|
|
|
|
var invitationRecordId = query
|
|
|
|
|
.Where(x => x.user_id == userId)
|
|
|
|
|
.OrderByDescending(t => t.status)
|
|
|
|
|
.ThenBy(t => t.create_time)
|
|
|
|
|
.Skip((page - 1) * limit)
|
|
|
|
|
.Take(limit)
|
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
|
|
List<InviteForUsers> invitationRecord = new List<InviteForUsers>();
|
|
|
|
|
foreach (var record in invitationRecordId)
|
2024-10-11 21:28:37 +08:00
|
|
|
|
{
|
2024-10-13 20:07:08 +08:00
|
|
|
|
|
2024-10-13 12:22:08 +08:00
|
|
|
|
var invited = await userManager.Users.FirstOrDefaultAsync(u => u.Id == record.invited_id);
|
2024-10-13 20:07:08 +08:00
|
|
|
|
var theGame = sub.team_Games.FirstOrDefault(i => i.id == record.match_id);
|
2024-10-13 21:19:05 +08:00
|
|
|
|
if (theGame == null) return Ok(new { code = 200, message = "没有比赛资料" });
|
2024-10-13 12:22:08 +08:00
|
|
|
|
var addData = new InviteForUsers
|
2024-10-11 21:28:37 +08:00
|
|
|
|
{
|
2024-10-13 20:07:08 +08:00
|
|
|
|
id = record.id,
|
2024-10-13 12:22:08 +08:00
|
|
|
|
invitedChinaname = invited.chinaname,
|
2024-10-13 20:07:08 +08:00
|
|
|
|
match = theGame,
|
2024-10-13 12:22:08 +08:00
|
|
|
|
create_time = record.create_time,
|
2024-10-13 20:07:08 +08:00
|
|
|
|
status = record.status,
|
2024-10-11 21:28:37 +08:00
|
|
|
|
};
|
2024-10-13 14:13:44 +08:00
|
|
|
|
invitationRecord.Add(addData);
|
2024-10-13 20:07:08 +08:00
|
|
|
|
TotalRecords++;
|
2024-10-13 12:22:08 +08:00
|
|
|
|
}
|
|
|
|
|
var data = new
|
|
|
|
|
{
|
|
|
|
|
rows = invitationRecord,
|
|
|
|
|
total = TotalRecords,
|
|
|
|
|
};
|
|
|
|
|
return Ok(new { code = 200, message = "邀请记录如下", data });
|
2024-10-11 21:28:37 +08:00
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
2024-10-13 12:22:08 +08:00
|
|
|
|
return Ok(new { code = 500, message = "服务器错误", details = ex });
|
2024-10-11 21:28:37 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-13 12:22:08 +08:00
|
|
|
|
public class BeInviteForUsers
|
|
|
|
|
{
|
2024-10-13 20:07:08 +08:00
|
|
|
|
public int id { get; set; }
|
2024-10-13 12:22:08 +08:00
|
|
|
|
public string invitorChinaname { get; set; }
|
|
|
|
|
public schedule.team_game match { get; set; }
|
|
|
|
|
|
|
|
|
|
public string? create_time { get; set; }
|
|
|
|
|
}
|
2024-10-11 21:28:37 +08:00
|
|
|
|
[Route("api/v1/toInvite")]
|
|
|
|
|
[HttpGet]
|
|
|
|
|
[Authorize]
|
2024-10-13 12:22:08 +08:00
|
|
|
|
public async Task<ActionResult<object>> ToInvite([FromQuery]short page = 1, short limit = 6)
|
2024-10-11 21:28:37 +08:00
|
|
|
|
{
|
|
|
|
|
string Myid = this.User.FindFirst(ClaimTypes.NameIdentifier)!.Value;
|
|
|
|
|
var user = await userManager.FindByIdAsync(Myid);
|
|
|
|
|
long userId = user.Id;
|
2024-10-13 12:22:08 +08:00
|
|
|
|
|
|
|
|
|
int wrongPart = -1;
|
|
|
|
|
using (TestDbContext sub = new TestDbContext())
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var query = sub.T_Invitation
|
|
|
|
|
.AsQueryable();
|
2024-10-13 20:07:08 +08:00
|
|
|
|
var TotalRecords = 0;
|
2024-10-13 12:22:08 +08:00
|
|
|
|
var invitationRecordId = query
|
|
|
|
|
.Where(x => x.invited_id == userId && x.status==0)
|
|
|
|
|
.OrderBy(t => t.create_time)
|
|
|
|
|
.Skip((page - 1) * limit)
|
|
|
|
|
.Take(limit)
|
|
|
|
|
.ToList();
|
|
|
|
|
List<BeInviteForUsers> invitationRecord = new List<BeInviteForUsers>();
|
|
|
|
|
foreach (var record in invitationRecordId)
|
2024-10-13 20:07:08 +08:00
|
|
|
|
{
|
2024-10-13 12:22:08 +08:00
|
|
|
|
var invitor = await userManager.Users.FirstOrDefaultAsync(u => u.Id == record.user_id);
|
2024-10-13 20:07:08 +08:00
|
|
|
|
var theGame = sub.team_Games.FirstOrDefault(i => i.id == record.match_id);
|
2024-10-13 21:19:05 +08:00
|
|
|
|
if (invitor == null) return Ok(new { code = 200, message = "被邀请者不存在了" });
|
|
|
|
|
if (theGame == null) return Ok(new { code = 200, message = "没有比赛资料" });
|
2024-10-13 12:22:08 +08:00
|
|
|
|
var addData = new BeInviteForUsers
|
|
|
|
|
{
|
2024-10-13 20:07:08 +08:00
|
|
|
|
id = record.id,
|
2024-10-13 12:22:08 +08:00
|
|
|
|
invitorChinaname = invitor.chinaname,
|
2024-10-13 20:07:08 +08:00
|
|
|
|
match = theGame,
|
2024-10-13 12:22:08 +08:00
|
|
|
|
create_time = record.create_time,
|
|
|
|
|
};
|
2024-10-13 14:13:44 +08:00
|
|
|
|
invitationRecord.Add(addData);
|
2024-10-13 20:07:08 +08:00
|
|
|
|
TotalRecords++;
|
2024-10-13 12:22:08 +08:00
|
|
|
|
}
|
|
|
|
|
var data = new
|
|
|
|
|
{
|
|
|
|
|
rows = invitationRecord,
|
|
|
|
|
total = TotalRecords,
|
|
|
|
|
};
|
|
|
|
|
return Ok(new { code = 200, message = "收到的未处理的邀请如下", data });
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
return Ok(new { code = 500, message = "服务器错误", details = ex });
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class msg2
|
|
|
|
|
{
|
|
|
|
|
public int id { get; set; }
|
|
|
|
|
public int status { get; set; }
|
|
|
|
|
}
|
|
|
|
|
[Route("api/v1/recordAgreeOrDisagree")]
|
|
|
|
|
[HttpPost]
|
|
|
|
|
[Authorize]
|
|
|
|
|
public async Task<ActionResult<object>> PassAssign([FromBody] msg2 askMsg)
|
|
|
|
|
{
|
|
|
|
|
using (TestDbContext sub = new TestDbContext())
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var query = sub.T_Invitation.FirstOrDefault(n => n.id == askMsg.id);
|
|
|
|
|
if (query != null)
|
|
|
|
|
{
|
|
|
|
|
string message = "无效操作";
|
|
|
|
|
query.status = askMsg.status;
|
|
|
|
|
if(askMsg.status == 1)
|
|
|
|
|
{
|
|
|
|
|
message = "你同意了邀请,记得及时到位哦~";
|
|
|
|
|
}else if (askMsg.status == 2)
|
|
|
|
|
{
|
|
|
|
|
message = "你拒绝了邀请";
|
|
|
|
|
}
|
|
|
|
|
sub.SaveChanges();
|
|
|
|
|
return Ok(new { code = 200, message});
|
|
|
|
|
}
|
|
|
|
|
return Ok(new { code = 404, message = "没有对应记录" });
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
return Ok(new { code = 500, message = "服务器错误", details = ex });
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-10-11 21:28:37 +08:00
|
|
|
|
}
|
2024-10-13 20:07:08 +08:00
|
|
|
|
|
|
|
|
|
[Route("api/v1/delRecord")]
|
|
|
|
|
[HttpDelete]
|
|
|
|
|
[Authorize]
|
|
|
|
|
public async Task<ActionResult<object>> DelAssign([FromQuery] int id)
|
|
|
|
|
{
|
|
|
|
|
using (TestDbContext sub = new TestDbContext())
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
string Myid = this.User.FindFirst(ClaimTypes.NameIdentifier)!.Value;
|
|
|
|
|
var user = await userManager.FindByIdAsync(Myid);
|
|
|
|
|
long userId = user.Id;
|
|
|
|
|
var query = sub.T_Invitation.Where(n => n.id == id).FirstOrDefault();
|
|
|
|
|
if(query.user_id != (int)userId) return Ok(new error_mb { code = 200, message = "非法操作!" });
|
|
|
|
|
sub.T_Invitation.Remove(query);
|
|
|
|
|
await sub.SaveChangesAsync();
|
|
|
|
|
return Ok(new error_mb { code = 200, message = "成功删除" });
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
return Ok(new { code = 500, message = "服务器错误", details = ex });
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-08-17 15:38:44 +08:00
|
|
|
|
}
|
|
|
|
|
}
|