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

@@ -12,6 +12,7 @@ use app\admin\model\shopro\Category;
use app\admin\model\zy\game\GameJoin;
use think\exception\ValidateException;
use app\admin\model\shopro\goods\Goods;
use app\admin\model\zy\game\Participant;
use addons\shopro\service\order\OrderCreate;
use app\admin\controller\shopro\traits\SkuPrice;
@@ -206,6 +207,32 @@ class Activity extends Base
if (GameJoin::get(['game_id' => $game['id'], 'act_id' => $game['act_id'], 'user_id' => $this->auth->id])) {
$this->error('您已报名此活动');
}
$order = GameJoin::where('game_id', $game['id'])->count();
$gender = ['man' => 0, 'woman' => 0];
$participant = [];
foreach ($params['users'] as $u) {
$order++;
$participant[] = [
'user_id' => $u['user_id'],
'gender' => $u['gender'],
'avatar' => $u['avatar'],
'name' => $u['nickname'],
'game_id' => $game['id'],
'signin' => 0,
'order' => $order,
'status' => 1,
];
if ($u['gender'] == 0) {
$gender['woman'] += 1;
} else {
$gender['man'] += 1;
}
}
foreach ($gender as $k => $v) {
if ($params['goods_list'][$k]['goods_num'] != $v) {
$this->error('报名人数错误');
}
}
$orderCreate = new OrderCreate($params);
$result = $orderCreate->calc('create');
$order = $orderCreate->create($result);
@@ -215,9 +242,13 @@ class Activity extends Base
'game_id' => $game['id'],
'user_id' => $this->auth->id,
'orer_id' => $order['id'],
'status' => 1,
'status' => 0,//待支付
'users' => json_encode($params['users'] ?? [])
]);
foreach ($participant as &$p) {
$p['game_join_id'] = $join->id;
}
(new Participant)->insertAll($participant);
Db::commit();
} catch (ValidateException | PDOException | Exception $e) {