feat(zy): 实现比赛报名和自动分组功能

- 新增比赛报名逻辑,支持单双打和团队赛
- 实现自动分组算法,根据比赛规则生成对阵表
- 添加下一轮对阵安排功能,支持淘汰赛制
- 优化比赛结果处理,自动计算排名和得分
- 新增参赛人员列表接口,支持多种查询条件
This commit is contained in:
2025-05-30 16:29:57 +08:00
parent 6e655c6121
commit be7ee40690
8 changed files with 328 additions and 135 deletions

View File

@@ -2,6 +2,8 @@
namespace format;
use app\admin\model\zy\game\Game;
class Game17 implements GameInterface
{
// 赛制说明
@@ -16,7 +18,7 @@ class Game17 implements GameInterface
}
// 首轮对阵安排
public function match($game, $users): array
public function match(Game $game, array $users): array
{
$math = $team = [];
$utotal = count($users);
@@ -24,7 +26,6 @@ class Game17 implements GameInterface
for ($i = 0; $i < $utotal; $i++) {
for ($j = $i + 1; $j < $utotal; $j++) {
$teamName = 'team' . $i . $j;
// $team[] = json_encode([
$team[] = ([
'name' => $teamName,
'user' => [
@@ -45,15 +46,14 @@ class Game17 implements GameInterface
$users[$i]['team'] = $users[$j]['team'] = $teamName;
}
}
// dd($team);
// 对阵分配
$ttotal = count($team);
df("$utotal 人:");
// df("共 $utotal 人:");
$n = 1;
for ($i = 0; $i < $ttotal; $i++) {
for ($j = $i + 1; $j < $ttotal; $j++) {
if (array_intersect(array_column($team[$i]['user'], 'user_id'), array_column($team[$j]['user'], 'user_id'))) {
continue;//一个人不能同时在两边队伍
continue; //一个人不能同时在两边队伍
}
$math[] = [
'gym_id' => $game['gym_id'],
@@ -71,20 +71,44 @@ class Game17 implements GameInterface
$n++;
}
}
// dd($math);
$this->next($game, $math);
return $math;
}
// 下一轮对阵安排
public function next($game, $math): array
public function nextLevel(Game $game, array $maths, $level): array
{
$math = [];
return $math;
if ($game['rule_type'] < 15) { //15战队淘汰赛16单项淘汰赛17分区循环淘汰赛
return []; //只有淘汰赛才有下一轮对阵安排,其他类型比赛只有一轮
}
$winner = $next = [];
foreach ($maths as $m) {
$winner[] = json_decode($m['winner'], true);
}
$total = count($winner);
$n = 1;
for ($i = 0; $i < $total; $i++) {
for ($j = $i + 1; $j < $total; $j++) {
if (array_intersect(array_column($winner[$i]['user'], 'user_id'), array_column($winner[$j]['user'], 'user_id'))) {
continue;
}
$next[] = [
'gym_id' => $game['gym_id'],
'club_id' => $game['club_id'],
'act_id' => $game['act_id'],
'game_id' => $game['id'],
'level' => $level, //轮次
'turn' => $n, //场次
'teamA' => json_encode($winner[$i]), //队伍A
'teamB' => json_encode($winner[$j]), //队伍B
];
$n++;
}
}
return $next;
}
// 奖金分配
public function prize($rank): array
public function prize(array $rank): array
{
return $rank;
}