From 3bb28c738f867413611a0ba7e5a8a6f61bbfcd52 Mon Sep 17 00:00:00 2001 From: zhaoxiang Date: Wed, 30 Jan 2019 14:58:15 +0800 Subject: [PATCH] =?UTF-8?q?modified=20=E6=80=A7=E8=83=BD=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E6=8F=90=E5=8D=87=E6=9F=A5=E8=AF=A2=E9=80=9F=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/admin/controller/User.php | 29 ++++++++++++--------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/application/admin/controller/User.php b/application/admin/controller/User.php index 83008b5..867b31b 100644 --- a/application/admin/controller/User.php +++ b/application/admin/controller/User.php @@ -13,6 +13,7 @@ use app\model\AdminUser; use app\model\AdminUserData; use app\util\ReturnCode; use app\util\Tools; +use think\Db; class User extends Base { @@ -112,32 +113,28 @@ class User extends Base { /** * 获取当前组的全部用户 - * @author zhaoxiang * @return array - * @throws \think\db\exception\DataNotFoundException - * @throws \think\db\exception\ModelNotFoundException + * @throws \think\Exception * @throws \think\exception\DbException + * @author zhaoxiang */ public function getUsers() { $limit = $this->request->get('size', config('apiAdmin.ADMIN_LIST_DEFAULT')); - $start = $this->request->get('page', 1); + $page = $this->request->get('page', 1); $gid = $this->request->get('gid', 0); if (!$gid) { return $this->buildFailed(ReturnCode::PARAM_INVALID, '非法操作'); } - $listInfo = (new AdminAuthGroupAccess())->where(['groupId' => ['like', "%{$gid}%"]])->select(); - $listInfo = Tools::buildArrFromObj($listInfo); - $uidArr = array_column($listInfo, 'uid'); + $totalNum = (new AdminAuthGroupAccess())->where('find_in_set("' . $gid . '", `groupId`)')->count(); + $start = $limit * ($page - 1); + $sql = "SELECT au.* FROM admin_user as au LEFT JOIN admin_auth_group_access as aaga " . + " ON aaga.`uid` = au.`id` WHERE find_in_set('{$gid}', aaga.`groupId`) " . + " ORDER BY au.regTime DESC LIMIT {$start}, {$limit}"; + $userInfo = Db::query($sql); - $listObj = (new AdminUser())->whereIn('id', $uidArr)->order('regTime DESC') - ->paginate($limit, false, ['page' => $start])->toArray(); - $userInfo = $listObj['data']; - - $userData = AdminUserData::all(function($query) use ($uidArr) { - $query->whereIn('uid', $uidArr); - }); - $userData = Tools::buildArrFromObj($userData); + $uidArr = array_column($userInfo, 'id'); + $userData = (new AdminUserData())->whereIn('uid', $uidArr)->select(); $userData = Tools::buildArrByNewKey($userData, 'uid'); foreach ($userInfo as $key => $value) { @@ -151,7 +148,7 @@ class User extends Base { return $this->buildSuccess([ 'list' => $userInfo, - 'count' => $listObj['total'] + 'count' => $totalNum ]); }