diff --git a/addons/shopro/controller/zy/Club.php b/addons/shopro/controller/zy/Club.php index 4815fe8..29598cd 100644 --- a/addons/shopro/controller/zy/Club.php +++ b/addons/shopro/controller/zy/Club.php @@ -6,12 +6,14 @@ use think\Db; use think\Exception; use app\admin\model\zy\Menber; use app\admin\model\zy\Stadium; +use app\admin\model\zy\game\Game; use think\exception\PDOException; use app\admin\model\zy\link\Apply; use app\admin\model\zy\link\Message; use app\admin\model\shopro\user\User; use app\admin\model\zy\game\Activity; use think\exception\ValidateException; +use app\admin\model\zy\game\Participant; class Club extends Base { @@ -24,17 +26,49 @@ class Club extends Base public function index() { $params = $this->request->param(); + $sub = Game::alias('g') + ->join([Participant::$tableName => 'p'], 'p.game_id=g.id', 'LEFT') + ->field('g.id,g.pid,g.club_id,g.act_id,g.date,g.name,g.start_time,g.end_time,g.cost,JSON_ARRAYAGG(p.avatar) as avatar,count(p.id) as join_num') + ->where('g.date', '>=', date('Y-m-d')) + ->order('g.date', 'asc')->group('g.id')->buildSql(); $query = $this->model->alias('c') ->join([Stadium::$tableName => 's'], 's.id = c.gym_id', 'LEFT') - ->field('c.*, s.name as gym_name'); + ->join([$sub => 'g'], 'g.club_id = c.id', 'LEFT') + ->field("c.*, s.position,s.name as gym_name,JSON_ARRAYAGG(JSON_OBJECT( + 'id', g.id, + 'pid', g.pid, + 'act_id', g.act_id, + 'date', g.date, + 'name', g.name, + 'start_time', g.start_time, + 'end_time', g.end_time, + 'join_num', g.join_num, + 'avatar', g.avatar, + 'cost', g.cost + )) AS games")->group('c.id'); if (isset($params['name'])) { $query->where('c.name', 'like', '%' . $params['name'] . '%'); } + if (isset($params['tag'])) { + $query->where('c.tags', 'like', '%' . $params['tag'] . '%'); + } if (isset($params['gym_id'])) { $query->where('c.gym_id', $params['gym_id']); } + if (isset($params['order'])) { + $query->order($params['order'], $params['sort'] ?? NULL); + } $res = $query->paginate($params['pageSize'] ?? 10); - $this->success('Success', ['list' => $res->items(), 'count' => $res->total()]); + $list = $res->items(); + foreach ($list as &$l) { + $games = json_decode($l['games'], true); + if (count($games) == 1 && empty($games[0]['id'])) $games = []; + foreach ($games as &$g) { + $g['cost'] = json_decode($g['cost'], true); + } + $l['games'] = $games; + } + $this->success('Success', ['list' => $list, 'count' => $res->total()]); } public function add() diff --git a/addons/shopro/controller/zy/Game.php b/addons/shopro/controller/zy/Game.php index 7f36cd1..76dd7f3 100644 --- a/addons/shopro/controller/zy/Game.php +++ b/addons/shopro/controller/zy/Game.php @@ -4,6 +4,7 @@ namespace addons\shopro\controller\zy; use app\admin\model\zy\Club; use app\admin\model\zy\Stadium; +use app\admin\model\zy\game\Participant; class Game extends Base @@ -18,9 +19,10 @@ class Game extends Base { $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'); + ->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'] . '%'); } @@ -49,6 +51,7 @@ class Game extends Base $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()]); } @@ -59,7 +62,7 @@ class Game extends Base if (empty($model)) { $this->error(__('No rows were found')); } - + $model['cost'] = json_decode($model['cost'] ?? '[]', true); $model['referee'] = explode(',', $model['referee']); diff --git a/application/admin/model/zy/game/Game.php b/application/admin/model/zy/game/Game.php index 1ea5b50..bfe7c19 100644 --- a/application/admin/model/zy/game/Game.php +++ b/application/admin/model/zy/game/Game.php @@ -13,6 +13,7 @@ class Game extends Model // 表名 + public static $tableName = 'zy_game'; protected $table = 'zy_game'; // 自动写入时间戳字段 diff --git a/application/admin/model/zy/game/GameJoin.php b/application/admin/model/zy/game/GameJoin.php index c1ed418..96f7e8d 100644 --- a/application/admin/model/zy/game/GameJoin.php +++ b/application/admin/model/zy/game/GameJoin.php @@ -13,6 +13,7 @@ class GameJoin extends Model // 表名 + public static $tableName = 'zy_game_join'; protected $table = 'zy_game_join'; // 自动写入时间戳字段 diff --git a/application/admin/model/zy/game/Participant.php b/application/admin/model/zy/game/Participant.php index a980757..220d8ca 100644 --- a/application/admin/model/zy/game/Participant.php +++ b/application/admin/model/zy/game/Participant.php @@ -13,6 +13,7 @@ class Participant extends Model // 表名 + public static $tableName = 'zy_participant'; protected $table = 'zy_participant'; // 自动写入时间戳字段