Merge branch 'master' of https://dev.azure.com/luolan/ASG/_git/asg_backend
This commit is contained in:
		
						commit
						d8402bdeb1
					
				@ -178,6 +178,7 @@ namespace asg_form.Controllers
 | 
				
			|||||||
                    if (teamgame.isAllowChoose == 0) return Ok(new error_mb { code = 401, message = "存在无法选择的比赛" });
 | 
					                    if (teamgame.isAllowChoose == 0) return Ok(new error_mb { code = 401, message = "存在无法选择的比赛" });
 | 
				
			||||||
                    if (teamgame != null)
 | 
					                    if (teamgame != null)
 | 
				
			||||||
                    {
 | 
					                    {
 | 
				
			||||||
 | 
					                       
 | 
				
			||||||
                        teamgame.referee = chinaname;
 | 
					                        teamgame.referee = chinaname;
 | 
				
			||||||
                        teamgame.referee_Id = (int)(user.Id);
 | 
					                        teamgame.referee_Id = (int)(user.Id);
 | 
				
			||||||
                        await testDb.SaveChangesAsync();
 | 
					                        await testDb.SaveChangesAsync();
 | 
				
			||||||
@ -250,6 +251,119 @@ namespace asg_form.Controllers
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /// <summary>
 | 
				
			||||||
 | 
					        /// 导播选定场次
 | 
				
			||||||
 | 
					        /// </summary>
 | 
				
			||||||
 | 
					        [Route("api/v1/judge")]
 | 
				
			||||||
 | 
					        [HttpPost]
 | 
				
			||||||
 | 
					        [Authorize]
 | 
				
			||||||
 | 
					        public async Task<ActionResult<object>> judgePost(string gameIds)
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            string id = this.User.FindFirst(ClaimTypes.NameIdentifier)!.Value;
 | 
				
			||||||
 | 
					            var user = await userManager.FindByIdAsync(id);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            if (user.officium != "Judge")
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                return Ok(new error_mb { code = 401, message = $"你是{user.officium},你不是裁判,无法操作" });
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            else
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                if (user.Integral == null)
 | 
				
			||||||
 | 
					                {
 | 
				
			||||||
 | 
					                    user.Integral = 0;
 | 
				
			||||||
 | 
					                    await userManager.UpdateAsync(user);
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                TestDbContext testDb = new TestDbContext();
 | 
				
			||||||
 | 
					                string chinaname = user.chinaname;
 | 
				
			||||||
 | 
					                int[] gameIdArray = ConvertStringToIntArray(gameIds);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                var message = $"导播:\r\n{chinaname}\r\n选择了比赛:";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                foreach (var gameId in gameIdArray)
 | 
				
			||||||
 | 
					                {
 | 
				
			||||||
 | 
					                    var teamgame = await testDb.team_Games.FirstOrDefaultAsync(a => a.id == gameId);
 | 
				
			||||||
 | 
					                    if (teamgame.isAllowChoose == 0) return Ok(new error_mb { code = 401, message = "存在无法选择的比赛" });
 | 
				
			||||||
 | 
					                    if (teamgame != null)
 | 
				
			||||||
 | 
					                    {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                        teamgame.judge = chinaname;
 | 
				
			||||||
 | 
					                        teamgame.judge_Id = (int)(user.Id);
 | 
				
			||||||
 | 
					                        await testDb.SaveChangesAsync();
 | 
				
			||||||
 | 
					                        user.Integral += 5;
 | 
				
			||||||
 | 
					                        await userManager.UpdateAsync(user);
 | 
				
			||||||
 | 
					                        message += $"\r\n{teamgame.team1_name} VS {teamgame.team2_name}";
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					                try
 | 
				
			||||||
 | 
					                {
 | 
				
			||||||
 | 
					                    var msg = new MessageBuilder().Add(new AtSegment(user.qqnumber ?? "2667210109")).Text(message).Build();
 | 
				
			||||||
 | 
					                    await runbot.runbotr.SendMessageAsync(MessageEnvironment.Channel, "925510646", null, msg, "925510646");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					                catch (Exception ex)
 | 
				
			||||||
 | 
					                {
 | 
				
			||||||
 | 
					                    return Ok(new { code = 500, message = "服务器错误", ex });
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                return Ok(new { code = 200, message = "报名成功" }); ;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /// <summary>
 | 
				
			||||||
 | 
					        /// 删除导播选择的比赛
 | 
				
			||||||
 | 
					        /// </summary>
 | 
				
			||||||
 | 
					        [Route("api/v1/judge")]
 | 
				
			||||||
 | 
					        [HttpDelete]
 | 
				
			||||||
 | 
					        [Authorize]
 | 
				
			||||||
 | 
					        public async Task<ActionResult<object>> DeletejudgeSelectedGame(int gameId, string reason)
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            string userId = this.User.FindFirst(ClaimTypes.NameIdentifier)!.Value;
 | 
				
			||||||
 | 
					            var user = await userManager.FindByIdAsync(userId);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            if (user.officium != "Judge")
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                return Ok(new error_mb { code = 401, message = $"你是{user.officium},你不是裁判,无法操作" });
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            TestDbContext testDb = new TestDbContext();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            var teamGame = await testDb.team_Games.FirstOrDefaultAsync(a => a.id == gameId);
 | 
				
			||||||
 | 
					            if (teamGame == null)
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                return NotFound(new { code = 404, message = "比赛未找到" });
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            teamGame.judge = null;
 | 
				
			||||||
 | 
					            teamGame.judge_Id = null;
 | 
				
			||||||
 | 
					            await testDb.SaveChangesAsync();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            user.Integral = user.Integral - 5 > 0 ? user.Integral - 5 : 0; // 确保积分不会减少到负数
 | 
				
			||||||
 | 
					            await userManager.UpdateAsync(user);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            try
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                var message = new MessageBuilder()
 | 
				
			||||||
 | 
					                    .Add(new AtSegment(user.qqnumber ?? "2667210109"))
 | 
				
			||||||
 | 
					                    .Text($"裁判 {user.chinaname} 已取消比赛 {teamGame.team1_name} VS {teamGame.team2_name} 的选择,\n原因是{reason}")
 | 
				
			||||||
 | 
					                    .Build();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                await runbot.runbotr.SendMessageAsync(MessageEnvironment.Channel, "925510646", null, message, "925510646");
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            catch (Exception ex)
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                return StatusCode(500, new { code = 500, message = "服务器错误", ex });
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            return Ok(new { code = 200, message = "删除成功" });
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        public class com_json
 | 
					        public class com_json
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            /// <summary>
 | 
					            /// <summary>
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user