162 lines
7.0 KiB
PHP
162 lines
7.0 KiB
PHP
<?php
|
||
|
||
namespace addons\shopro\controller\zy;
|
||
|
||
use think\Db;
|
||
use think\Exception;
|
||
use app\admin\model\zy\Club;
|
||
use app\admin\model\zy\Stadium;
|
||
use think\exception\PDOException;
|
||
use app\admin\model\zy\game\GameJoin;
|
||
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;
|
||
parent::__construct();
|
||
}
|
||
|
||
public function index()
|
||
{
|
||
$params = $this->request->param();
|
||
$query = $this->model->alias('g')
|
||
->join([Participant::$tableName => 'p'], 'p.game_id=g.id', 'LEFT')
|
||
->join([Stadium::$tableName => 's'], 's.id = g.gym_id', 'LEFT')
|
||
->join([Club::$tableName => 'c'], 'c.id = g.club_id', 'LEFT')
|
||
->field('g.*, s.name as gym_name, c.name as club_name,JSON_ARRAYAGG(p.avatar) as avatar,count(p.id) as join_num');
|
||
if (isset($params['name'])) {
|
||
$query->where('g.name', 'like', '%' . $params['name'] . '%');
|
||
}
|
||
if (isset($params['club_id'])) {
|
||
$query->where('g.club_id', $params['club_id']);
|
||
}
|
||
if (isset($params['week'])) {
|
||
$query->where('g.week', $params['week']);
|
||
}
|
||
if (isset($params['pid'])) {
|
||
$query->where('pid', $params['pid']);
|
||
} else {
|
||
$query->where('pid', 0);
|
||
}
|
||
if (isset($params['public_time'])) {
|
||
$query->where('public_time', $params['public_time']);
|
||
} else {
|
||
$query->where('public_time', '<=', date('Y-m-d H:i:s'));
|
||
}
|
||
if (isset($params['page'])) {
|
||
$pageSize = intval($params['pageSize'] ?? 10);
|
||
$offeset = (intval($params['page']) - 1) * $pageSize;
|
||
$query->limit($offeset, $pageSize);
|
||
}
|
||
$res = $query->paginate($params['pageSize'] ?? 10);
|
||
$list = $res->items();
|
||
foreach ($list as &$v) {
|
||
$v['cost'] = json_decode($v['cost'] ?? '[]', true);
|
||
$v['avatar'] = json_decode($v['avatar'] ?? '[]', true);
|
||
}
|
||
$this->success('Success', ['list' => $list, 'count' => $res->total()]);
|
||
}
|
||
|
||
public function view()
|
||
{
|
||
$model = $this->model->get($this->request->param('id'));
|
||
if (empty($model)) {
|
||
$this->error(__('No rows were found'));
|
||
}
|
||
|
||
$this->model->where('id', $model['id'])->setInc('attention');
|
||
$model['cost'] = json_decode($model['cost'] ?? '[]', true);
|
||
$model['referee'] = explode(',', $model['referee']);
|
||
|
||
$this->success('Success', $model);
|
||
}
|
||
|
||
public function getMacth()
|
||
{
|
||
$params = $this->request->param();
|
||
Db::startTrans();
|
||
try {
|
||
$game = $this->model->get($params['id'] ?? NULL);
|
||
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('比赛时间已结束');
|
||
}
|
||
$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();
|
||
$order = 1;
|
||
$participant = [];
|
||
foreach ($join as $j) {
|
||
$users = json($j['users'], true);
|
||
foreach ($users as $u) {
|
||
$participant[] = [
|
||
'user_id' => $u['user_id'],
|
||
'gender' => $u['gender'],
|
||
'avatar' => $u['avatar'],
|
||
'name' => $u['name'],
|
||
'game_join_id' => $j['id'],
|
||
'game_id' => $game['id'],
|
||
'order' => $order,
|
||
'status' => 1,
|
||
];
|
||
$order++;
|
||
}
|
||
}
|
||
$this->model->saveAll($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) { //团队
|
||
|
||
}
|
||
Db::commit();
|
||
} catch (ValidateException | PDOException | Exception $e) {
|
||
Db::rollback();
|
||
$this->error($e->getMessage(), $e);
|
||
}
|
||
|
||
$this->success('Success', ['list' => $participant]);
|
||
}
|
||
}
|