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

View File

@@ -8,12 +8,14 @@ use app\admin\model\zy\Club;
use app\admin\model\zy\Stadium;
use think\exception\PDOException;
use app\admin\model\zy\game\GameJoin;
use app\admin\model\zy\game\GameMatch;
use think\exception\ValidateException;
use app\admin\model\zy\game\Participant;
class Game extends Base
{
public function __construct()
{
$this->model = new \app\admin\model\zy\game\Game;
@@ -84,15 +86,15 @@ class Game extends Base
if (empty($game)) {
$this->error('比赛不存在');
}
$dataTime = date('Y-m-d H:i:s');
$startTime = $game['date'] . ' ' . $game['start_time'];
if ($dataTime < $startTime) {
$this->error('比赛时间未开始');
}
$endTime = $game['date'] . ' ' . $game['end_time'];
if ($dataTime > $endTime) {
$this->error('比赛时间已结束');
}
// $dataTime = date('Y-m-d H:i:s');
// $startTime = $game['date'] . ' ' . $game['start_time'];
// if ($dataTime < $startTime) {
// $this->error('比赛时间未开始');
// }
// $endTime = $game['date'] . ' ' . $game['end_time'];
// if ($dataTime > $endTime) {
// $this->error('比赛时间已结束');
// }
$participant = Participant::where('game_id', $game['id'])->where('status', 1)->select();
if (empty($participant)) {
$join = GameJoin::where('game_id', $game['id'])->where('status', 1)->select();
@@ -114,48 +116,26 @@ class Game extends Base
$order++;
}
}
$this->model->saveAll($participant);
$this->model->allowField(true)->save($participant);
}
if ($game['team_type'] == 1) { //双打
// 转转 4-16 每个人与其他人各搭档1次决出个人排名 人数 4 ≦ n ≦ 16 (Default8)
// 轮数 3 ≦ mn (Default7) 报名费 0 ≦ m ≦ 10 元 (Default: 5)
// 由前几名按比例瓜分 (可调 Default40%/30%/20%/10%)
// 混双转 4-32
// (偶数) 每男与每女各搭档1次分别决出男女排名 人数 4 ≦ n ≦ 32 (Default16)
// 轮数2 ≦ m ≦ n/2 (Default8) 报名费 0 ≦ m ≦ 10 元 (Default: 5)
// 由前几名按比例瓜分 (可调 Default40%/30%/20%/10%)
// 固搭转 4-32
// (偶数) 固定组合,分别与其他组合对战一次,决出组合排名 人数 4 ≦ n ≦ 32 (Default16)
// 轮数 2 ≦ m ≦ n/2-1 (Default7) 报名费 0 ≦ m ≦ 10 元 (Default: 5)
// 由前几名按比例瓜分 (可调 Default40%/30%/20%/10%)
// 分区转 4-32
// (偶数) 分为AB两区A区与B区各搭档1次分别决出AB区排名 人数 4 ≦ n ≦ 32 (Default16)
// 轮数2 ≦ m ≦ n/2 (Default8) 报名费 0 ≦ m ≦ 10 元 (Default: 5)
// 由前几名按比例瓜分 (可调 Default40%/30%/20%/10%)
// 擂台赛 8-44 由擂主决定出战组合,攻擂者按组合报名(不重复报名,但可兼项) 擂主人数 2 ≦ k ≦ 4 (Default2)
// 总攻擂数4 ≦ n ≦ 5k(Default8) 攻擂报名费 0 ≦ m ≦ 10 (Default5)
// 擂主报名费 2n/k (不可调)
// 攻擂者赢局获得2m元(不可调)
// 由擂主分摊盈亏
// 守擂赛 4-32
// (偶数) 选手组合报名不可重复报名抽签决定对战顺序相邻顺序对战连赢m局进入决赛决赛为淘汰赛决出冠亚季 人数 4 ≦ n ≦ 32 (Default16)
// 连赢 1 ≦ m ≦ 3 (Default2) 报名费0 ≦ k ≦ 10 (Default5)
// 由前几名按比例瓜分 (可调 Default40%/30%/20%/10%)
if ($game['rule_type'] == 1) { //转转
foreach ($participant as $key => $value) {
}
}
} elseif ($game['team_type'] == 2) { //单打
} elseif ($game['team_type'] == 3) { //团队
$gameClass = 'format\\Game' . $game['team_type'] . $game['rule_type'];
if (!class_exists($gameClass)) {
throw new Exception("赛制文件不存在,请联系管理人员: {$gameClass}");
}
$format = new $gameClass;
if (!$format instanceof \format\GameInterface) {
throw new Exception("赛制配置错误,请联系管理人员: {$gameClass}");
}
$matchs = $format->match($game, $participant);
$res = (new GameMatch)->insertAll($matchs);
Db::commit();
} catch (ValidateException | PDOException | Exception $e) {
Db::rollback();
$this->error($e->getMessage(), $e);
}
$this->success('Success', ['list' => $participant]);
// print_r($res);
$this->success('Success', $res);
}
}