feat(游戏模块): 重构比赛逻辑并添加赛制支持
- 移除了原有的比赛时间检查逻辑 - 引入了赛制类文件,实现了比赛自动编排功能 - 新增了 GameMatch 模型用于存储比赛对阵信息 - 优化了数据库事务处理逻辑 - 更新了 Composer 自动加载配置,添加 format 命名空间
This commit is contained in:
@@ -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 (Default:8)
|
||||
// 轮数 3 ≦ m<n (Default:7) 报名费 0 ≦ m ≦ 10 元 (Default: 5)
|
||||
// 由前几名按比例瓜分 (可调 Default:40%/30%/20%/10%)
|
||||
// 混双转 4-32
|
||||
// (偶数) 每男与每女各搭档1次,分别决出男女排名 人数 4 ≦ n ≦ 32 (Default:16)
|
||||
// 轮数2 ≦ m ≦ n/2 (Default:8) 报名费 0 ≦ m ≦ 10 元 (Default: 5)
|
||||
// 由前几名按比例瓜分 (可调 Default:40%/30%/20%/10%)
|
||||
// 固搭转 4-32
|
||||
// (偶数) 固定组合,分别与其他组合对战一次,决出组合排名 人数 4 ≦ n ≦ 32 (Default:16)
|
||||
// 轮数 2 ≦ m ≦ n/2-1 (Default:7) 报名费 0 ≦ m ≦ 10 元 (Default: 5)
|
||||
// 由前几名按比例瓜分 (可调 Default:40%/30%/20%/10%)
|
||||
// 分区转 4-32
|
||||
// (偶数) 分为AB两区,A区与B区各搭档1次,分别决出AB区排名 人数 4 ≦ n ≦ 32 (Default:16)
|
||||
// 轮数2 ≦ m ≦ n/2 (Default:8) 报名费 0 ≦ m ≦ 10 元 (Default: 5)
|
||||
// 由前几名按比例瓜分 (可调 Default:40%/30%/20%/10%)
|
||||
// 擂台赛 8-44 由擂主决定出战组合,攻擂者按组合报名(不重复报名,但可兼项) 擂主人数 2 ≦ k ≦ 4 (Default:2)
|
||||
// 总攻擂数4 ≦ n ≦ 5k(Default:8) 攻擂报名费 0 ≦ m ≦ 10 (Default:5)
|
||||
// 擂主报名费 2n/k (不可调)
|
||||
// 攻擂者赢局获得2m元(不可调)
|
||||
// 由擂主分摊盈亏
|
||||
// 守擂赛 4-32
|
||||
// (偶数) 选手组合报名(不可重复报名),抽签决定对战顺序,相邻顺序对战,连赢m局进入决赛,决赛为淘汰赛,决出冠亚季 人数 4 ≦ n ≦ 32 (Default:16)
|
||||
// 连赢 1 ≦ m ≦ 3 (Default:2) 报名费0 ≦ k ≦ 10 (Default:5)
|
||||
// 由前几名按比例瓜分 (可调 Default:40%/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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user