refactor(shopro): game
This commit is contained in:
@@ -2,8 +2,13 @@
|
|||||||
|
|
||||||
namespace addons\shopro\controller\zy;
|
namespace addons\shopro\controller\zy;
|
||||||
|
|
||||||
|
use think\Db;
|
||||||
|
use think\Exception;
|
||||||
use app\admin\model\zy\Club;
|
use app\admin\model\zy\Club;
|
||||||
use app\admin\model\zy\Stadium;
|
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;
|
use app\admin\model\zy\game\Participant;
|
||||||
|
|
||||||
|
|
||||||
@@ -73,13 +78,44 @@ class Game extends Base
|
|||||||
public function getMacth()
|
public function getMacth()
|
||||||
{
|
{
|
||||||
$params = $this->request->param();
|
$params = $this->request->param();
|
||||||
|
Db::startTrans();
|
||||||
|
try {
|
||||||
$game = $this->model->get($params['id'] ?? NULL);
|
$game = $this->model->get($params['id'] ?? NULL);
|
||||||
if (empty($game)) {
|
if (empty($game)) {
|
||||||
$this->error('比赛不存在');
|
$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();
|
$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) { //双打
|
if ($game['team_type'] == 1) { //双打
|
||||||
// 转转 4-16 每个人与其他人各搭档1次,决出个人排名 人数 4 ≦ n ≦ 16 (Default:8)
|
// 转转 4-16 每个人与其他人各搭档1次,决出个人排名 人数 4 ≦ n ≦ 16 (Default:8)
|
||||||
// 轮数 3 ≦ m<n (Default:7) 报名费 0 ≦ m ≦ 10 元 (Default: 5)
|
// 轮数 3 ≦ m<n (Default:7) 报名费 0 ≦ m ≦ 10 元 (Default: 5)
|
||||||
@@ -107,7 +143,6 @@ class Game extends Base
|
|||||||
// 由前几名按比例瓜分 (可调 Default:40%/30%/20%/10%)
|
// 由前几名按比例瓜分 (可调 Default:40%/30%/20%/10%)
|
||||||
if ($game['rule_type'] == 1) { //转转
|
if ($game['rule_type'] == 1) { //转转
|
||||||
foreach ($participant as $key => $value) {
|
foreach ($participant as $key => $value) {
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} elseif ($game['team_type'] == 2) { //单打
|
} elseif ($game['team_type'] == 2) { //单打
|
||||||
@@ -115,6 +150,11 @@ class Game extends Base
|
|||||||
} elseif ($game['team_type'] == 3) { //团队
|
} elseif ($game['team_type'] == 3) { //团队
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Db::commit();
|
||||||
|
} catch (ValidateException | PDOException | Exception $e) {
|
||||||
|
Db::rollback();
|
||||||
|
$this->error($e->getMessage(), $e);
|
||||||
|
}
|
||||||
|
|
||||||
$this->success('Success', ['list' => $participant]);
|
$this->success('Success', ['list' => $participant]);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user