diff --git a/addons/shopro/controller/zy/Activity.php b/addons/shopro/controller/zy/Activity.php index 1fcc2b3..008488d 100644 --- a/addons/shopro/controller/zy/Activity.php +++ b/addons/shopro/controller/zy/Activity.php @@ -5,6 +5,8 @@ namespace addons\shopro\controller\zy; use think\Db; use think\Cache; use think\Exception; +use app\admin\model\zy\Club; +use app\admin\model\zy\Stadium; use app\admin\model\zy\game\Game; use think\exception\PDOException; use app\admin\model\zy\game\GameJoin; @@ -24,23 +26,33 @@ class Activity extends Base public function index() { $params = $this->request->param(); - $model = $this->model; + $query = $this->model->alias('a') + ->join([Stadium::$tableName => 's'], 's.id = a.gym_id', 'LEFT') + ->join([Club::$tableName => 'c'], 'c.id = a.club_id', 'LEFT') + ->field('a.*, s.name as gym_name, c.name as club_name'); if (isset($params['name'])) { - $model->where('name', 'like', '%' . $params['name'] . '%'); + $query->where('a.name', 'like', '%' . $params['name'] . '%'); + } + if (isset($params['gym_id'])) { + $query->where('a.gym_id', $params['gym_id']); } if (isset($params['club_id'])) { - $model->where('club_id', $params['club_id']); + $query->where('a.club_id', $params['club_id']); } if (isset($params['week'])) { - $model->where('week', $params['week']); + $query->where('week', $params['week']); } if (isset($params['pid'])) { - $model->where('pid', $params['pid']); + $query->where('pid', $params['pid']); } else { - $model->where('pid', 0); + $query->where('pid', 0); } - - $res = $model->select(); + if (isset($params['page'])) { + $pageSize = intval($params['pageSize'] ?? 10); + $offeset = (intval($params['page']) - 1) * $pageSize; + $query->limit($offeset, $pageSize); + } + $res = $query->select(); foreach ($res as &$v) { $v['public_time'] = json_decode($v['public_time'] ?? '[]', true); $v['join_start_time'] = json_decode($v['join_start_time'] ?? '[]', true); @@ -50,7 +62,7 @@ class Activity extends Base $v['referee'] = explode(',', $v['referee']); } - $this->success('Success', $res); + $this->success('Success', ['list' => $res, 'count' => $query->count()]); } public function view() diff --git a/addons/shopro/controller/zy/Base.php b/addons/shopro/controller/zy/Base.php index 04bb181..691aca1 100644 --- a/addons/shopro/controller/zy/Base.php +++ b/addons/shopro/controller/zy/Base.php @@ -22,19 +22,6 @@ class Base extends Common $this->user = auth_user(); } - - public function index() - { - $params = $this->request->param(); - if (isset($params['name'])) { - $this->model->where('name', 'like', '%' . $params['name'] . '%'); - } - $res = $this->model->select(); - - - $this->success('Success', $res); - } - public function add() { $result = false; diff --git a/addons/shopro/controller/zy/Circle.php b/addons/shopro/controller/zy/Circle.php index fe09349..16237f9 100644 --- a/addons/shopro/controller/zy/Circle.php +++ b/addons/shopro/controller/zy/Circle.php @@ -22,17 +22,17 @@ class Circle extends Base $sub = CircleModel::alias('c') ->join([Likes::$tableName => 'l'], 'c.id = l.circle_id', 'LEFT') - ->field("c.*,CONCAT('[',GROUP_CONCAT(JSON_OBJECT( + ->field("c.*,JSON_ARRAYAGG(JSON_OBJECT( 'id', l.id, 'user_id', l.user_id, 'nickname', l.nickname, 'avatar', l.avatar, 'gender', l.gender - )), ']') AS likes")->group('c.id')->buildSql(); + )) AS likes")->group('c.id')->buildSql(); $query = Comment::alias('m') ->join([$sub => 'c'], 'c.id = m.circle_id', 'RIGHT') ->field("c.*, - CONCAT('[',GROUP_CONCAT(JSON_OBJECT( + JSON_ARRAYAGG(JSON_OBJECT( 'id', m.id, 'pid', m.pid, 'puser_id', m.puser_id, @@ -43,7 +43,7 @@ class Circle extends Base 'gender', m.gender, 'content', m.content, 'create_time', m.create_time - )), ']') AS comment")->group('c.id'); + )) AS comment")->group('c.id'); if (isset($params['club_id'])) { $query->where('c.club_id', $params['club_id']); } @@ -54,6 +54,11 @@ class Circle extends Base $friend = Relation::where('user_id', $this->auth->id)->where('status', 'IN', explode(',', $params['friend']))->column('target_id'); $query->where('c.user_id', 'IN', $friend); } + if (isset($params['page'])) { + $pageSize = intval($params['pageSize'] ?? 10); + $offeset = (intval($params['page']) - 1) * $pageSize; + $query->limit($offeset, $pageSize); + } $res = $query->select(); foreach ($res as &$r) { $r['likes'] = json_decode($r['likes'], true); @@ -61,7 +66,7 @@ class Circle extends Base $r['comment'] = buildTree(json_decode($r['comment'], true)); } - $this->success('Success', $res); + $this->success('Success', ['list' => $res, 'count' => $query->count()]); } public function view() diff --git a/addons/shopro/controller/zy/Club.php b/addons/shopro/controller/zy/Club.php index 750e6ed..38d22a0 100644 --- a/addons/shopro/controller/zy/Club.php +++ b/addons/shopro/controller/zy/Club.php @@ -5,6 +5,7 @@ namespace addons\shopro\controller\zy; use think\Db; use think\Exception; use app\admin\model\zy\Menber; +use app\admin\model\zy\Stadium; use think\exception\PDOException; use app\admin\model\zy\link\Apply; use app\admin\model\zy\link\Message; @@ -23,16 +24,23 @@ class Club extends Base public function index() { $params = $this->request->param(); - $model = $this->model; + $query = $this->model->alias('c') + ->join([Stadium::$tableName => 's'], 's.id = c.gym_id', 'LEFT') + ->field('c.*, s.name as gym_name'); if (isset($params['name'])) { - $model->where('name', 'like', '%' . $params['name'] . '%'); + $query->where('c.name', 'like', '%' . $params['name'] . '%'); } if (isset($params['gym_id'])) { - $model->where('gym_id', $params['gym_id']); + $query->where('c.gym_id', $params['gym_id']); } - $res = $model->select(); + if (isset($params['page'])) { + $pageSize = intval($params['pageSize'] ?? 10); + $offeset = (intval($params['page']) - 1) * $pageSize; + $query->limit($offeset, $pageSize); + } + $res = $query->select(); - $this->success('Success', $res); + $this->success('Success', ['list' => $res, 'count' => $query->count()]); } public function add() diff --git a/addons/shopro/controller/zy/Game.php b/addons/shopro/controller/zy/Game.php index 249f735..6744f0f 100644 --- a/addons/shopro/controller/zy/Game.php +++ b/addons/shopro/controller/zy/Game.php @@ -2,6 +2,9 @@ namespace addons\shopro\controller\zy; +use app\admin\model\zy\Club; +use app\admin\model\zy\Stadium; + class Game extends Base { @@ -14,35 +17,41 @@ class Game extends Base public function index() { $params = $this->request->param(); - $model = $this->model; + $query = $this->model->alias('g') + ->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'); if (isset($params['name'])) { - $model->where('name', 'like', '%' . $params['name'] . '%'); + $query->where('g.name', 'like', '%' . $params['name'] . '%'); } if (isset($params['club_id'])) { - $model->where('club_id', $params['club_id']); + $query->where('g.club_id', $params['club_id']); } if (isset($params['week'])) { - $model->where('week', $params['week']); + $query->where('g.week', $params['week']); } if (isset($params['pid'])) { - $model->where('pid', $params['pid']); + $query->where('pid', $params['pid']); } else { - $model->where('pid', 0); + $query->where('pid', 0); } if (isset($params['public_time'])) { - $model->where('public_time', $params['public_time']); + $query->where('public_time', $params['public_time']); } else { - $model->where('public_time', '<=', date('Y-m-d H:i:s')); + $query->where('public_time', '<=', date('Y-m-d H:i:s')); } - - $res = $model->select(); + if (isset($params['page'])) { + $pageSize = intval($params['pageSize'] ?? 10); + $offeset = (intval($params['page']) - 1) * $pageSize; + $query->limit($offeset, $pageSize); + } + $res = $query->select(); foreach ($res as &$v) { - $v['cost'] = json_decode($v['cost'] ?? '[]', true); $v['referee'] = explode(',', $v['referee']); } - $this->success('Success', $res); + $this->success('Success', ['list' => $res, 'count' => $query->count()]); } public function view() diff --git a/addons/shopro/controller/zy/Gym.php b/addons/shopro/controller/zy/Gym.php index b0f2c6e..75b7efd 100644 --- a/addons/shopro/controller/zy/Gym.php +++ b/addons/shopro/controller/zy/Gym.php @@ -17,13 +17,18 @@ class Gym extends Base public function index() { $params = $this->request->param(); - $model = $this->model->where('status', 1); + $query = $this->model->where('status', 1); if (isset($params['name'])) { - $model->where('name', 'like', '%' . $params['name'] . '%'); + $query->where('name', 'like', '%' . $params['name'] . '%'); } - $res = $model->select(); + if (isset($params['page'])) { + $pageSize = intval($params['pageSize'] ?? 10); + $offeset = (intval($params['page']) - 1) * $pageSize; + $query->limit($offeset, $pageSize); + } + $res = $query->select(); - $this->success('Success', $res); + $this->success('Success', ['list' => $res, 'count' => $query->count()]); } } diff --git a/application/admin/model/zy/Stadium.php b/application/admin/model/zy/Stadium.php index 264421a..beb76d1 100644 --- a/application/admin/model/zy/Stadium.php +++ b/application/admin/model/zy/Stadium.php @@ -13,6 +13,7 @@ class Stadium extends Model // 表名 + public static $tableName = 'zy_stadium'; protected $table = 'zy_stadium'; // 自动写入时间戳字段