From 19bfe5e992c3ed7173db359d21ea6f4b22f4d09e Mon Sep 17 00:00:00 2001 From: xiadc <251308692@qq.com> Date: Sun, 1 Jun 2025 18:46:12 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E6=AF=94=E8=B5=9B):=20=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E5=9B=A2=E9=98=9F=E6=8E=92=E5=90=8D=E7=AE=97=E6=B3=95=E5=B9=B6?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=E4=B8=AA=E4=BA=BA=E6=8E=92=E5=90=8D=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增团队排名算法,根据比赛得分和胜负情况计算排名 - 更新个人排名查询条件,排除 status 为 -1 的参与者 --- addons/shopro/controller/zy/Game.php | 31 ++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/addons/shopro/controller/zy/Game.php b/addons/shopro/controller/zy/Game.php index 2d14363..29ea5f4 100644 --- a/addons/shopro/controller/zy/Game.php +++ b/addons/shopro/controller/zy/Game.php @@ -440,7 +440,34 @@ class Game extends Base $this->error('比赛不存在'); } $match = GameMatch::field('*,GREATEST(scoreA,scoreB) as score')->where('game_id', $game['id'])->order(['level' => 'desc', 'score' => 'desc'])->select(); - $this->success('Success', $match); + $teams = []; + $rank = 1; + foreach ($match as $m) { + $win = json_decode($m['winner'] ?? '', true); + if (empty($win)) { // 未决出胜负的按暂时得分 高的队伍排名靠前 + $teamA = json_decode($m['teamA'] ?? '', true); + $teamB = json_decode($m['teamB'] ?? '', true); + if (($m['scoreA'] >= $m['scoreB'])) { + $teamA['rank'] = $rank; + $teamB['rank'] = $rank + 1; + $teams[] = $teamA; + $teams[] = $teamB; + $rank += 2; + } else { + $teamB['rank'] = $rank; + $teamA['rank'] = $rank + 1; + $teams[] = $teamB; + $teams[] = $teamA; + $rank += 2; + } + } else { + $win['rank'] = $rank; + $rank++; + $teams[] = $win; + } + } + + $this->success('Success', $teams); } // 个人排名 @@ -452,7 +479,7 @@ class Game extends Base $this->error('比赛不存在'); } - $list = Participant::where('game_id', $game['id'])->order('score', 'desc')->select(); + $list = Participant::where('game_id', $game['id'])->where('status', '>', -1)->order('score', 'desc')->select(); $rank = 1; foreach ($list as &$l) { $l['rank'] = $rank;