feat(游戏模块): 重构比赛逻辑并添加赛制支持

- 移除了原有的比赛时间检查逻辑
- 引入了赛制类文件,实现了比赛自动编排功能
- 新增了 GameMatch 模型用于存储比赛对阵信息
- 优化了数据库事务处理逻辑
- 更新了 Composer 自动加载配置,添加 format 命名空间
This commit is contained in:
2025-05-23 17:37:48 +08:00
parent 8481d8ef0c
commit ac0777e34b
9 changed files with 140 additions and 4593 deletions

72
format/Game17.php Normal file
View File

@@ -0,0 +1,72 @@
<?php
namespace format;
class Game17 implements GameInterface
{
// 赛制说明
public function describe(): string
{
return '双打+八人转 比赛说明:
每个人与其他人各搭档1次决出个人排名
数 4 ≦ n ≦ 16 (Default8)
轮数 3 ≦ mn (Default7)
报名费 0 ≦ m ≦ 10 元 (Default: 5)
由前几名按比例瓜分 (可调 Default40%/30%/20%/10%)';
}
// 对阵安排
public function match($game, $users): array
{
$math = $team = [];
$utotal = count($users);
for ($i = 0; $i < $utotal; $i++) {
for ($j = $i + 1; $j < $utotal; $j++) {
$team[] = json_encode([
'name' => 'team' . $i . $j,
'user' => [
[
'user_id' => $users[$i]['user_id'],
'gender' => $users[$i]['gender'],
'avatar' => $users[$i]['avatar'],
'name' => $users[$i]['name'],
],
[
'user_id' => $users[$j]['user_id'],
'gender' => $users[$j]['gender'],
'avatar' => $users[$j]['avatar'],
'name' => $users[$j]['name'],
]
]
]);
}
}
// dd($team);
$ttotal = count($users);
$n = 1;
for ($i = 0; $i < $ttotal; $i++) {
for ($j = $i + 1; $j < $ttotal; $j++) {
$math[] = [
'gym_id' => $game['gym_id'],
'club_id' => $game['club_id'],
'act_id' => $game['act_id'],
'game_id' => $game['id'],
'level' => 1,
'turn' => $n,
'teamA' => $team[$i],
'teamB' => $team[$j],
];
$n++;
}
}
// dd($math);
return $math;
}
// 奖金分配
public function prize($rank): array
{
return $rank;
}
}

24
format/GameInterface.php Normal file
View File

@@ -0,0 +1,24 @@
<?php
namespace format;
/*
赛制文件
1. 团队类型1双打2单打3团队
2. 规则类型1八人转2超八转3混双转4固搭转5固定擂6活动擂7转转8分区转9擂台赛10守擂赛11追分赛12固搭追分赛13大循环群内赛14两队PK赛15战队淘汰赛16单项淘汰赛17分区循环淘汰赛
3. 需要引入新赛制请创建新的类文件,类文件需要实现GameInterface接口,并且文件名为`Game + 团队类型代码 + 规则类型代码.php`。
如:赛制为双打八人转则文件为format/Game11.php。
赛制为单打擂台赛则文件为format/Game29.php。
*/
interface GameInterface
{
// 赛制说明
public function describe(): string;
// 对阵安排
public function match($game,$users): array;
// 奖金分配
public function prize($rank): array;
}