diff --git a/application/admin/controller/App.php b/application/admin/controller/App.php index 902f691..7669009 100644 --- a/application/admin/controller/App.php +++ b/application/admin/controller/App.php @@ -25,7 +25,7 @@ class App extends Base { public function index() { $limit = $this->request->get('size', config('apiAdmin.ADMIN_LIST_DEFAULT')); - $start = $limit * ($this->request->get('page', 1) - 1); + $start = $this->request->get('page', 1); $keywords = $this->request->get('keywords', ''); $type = $this->request->get('type', ''); $status = $this->request->get('status', ''); @@ -44,14 +44,12 @@ class App extends Base { break; } } - - $listInfo = (new AdminApp())->where($where)->order('app_addTime', 'DESC')->limit($start, $limit)->select(); - $count = (new AdminApp())->where($where)->count(); - $listInfo = Tools::buildArrFromObj($listInfo); + $listObj = (new AdminApp())->where($where)->order('app_addTime DESC') + ->paginate($limit, false, ['page' => $start])->toArray(); return $this->buildSuccess([ - 'list' => $listInfo, - 'count' => $count + 'list' => $listObj['data'], + 'count' => $listObj['total'] ]); } diff --git a/application/admin/controller/AppGroup.php b/application/admin/controller/AppGroup.php index fff5e9c..3ee1d6f 100644 --- a/application/admin/controller/AppGroup.php +++ b/application/admin/controller/AppGroup.php @@ -16,15 +16,13 @@ use app\util\Tools; class AppGroup extends Base { /** * 获取应用组列表 - * @author zhaoxiang * @return array - * @throws \think\db\exception\DataNotFoundException - * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException + * @author zhaoxiang */ public function index() { $limit = $this->request->get('size', config('apiAdmin.ADMIN_LIST_DEFAULT')); - $start = $limit * ($this->request->get('page', 1) - 1); + $start = $this->request->get('page', 1); $keywords = $this->request->get('keywords', ''); $type = $this->request->get('type', ''); $status = $this->request->get('status', ''); @@ -43,14 +41,11 @@ class AppGroup extends Base { break; } } - - $listInfo = (new AdminAppGroup())->where($where)->limit($start, $limit)->select(); - $count = (new AdminAppGroup())->where($where)->count(); - $listInfo = Tools::buildArrFromObj($listInfo); + $listObj = (new AdminAppGroup())->where($where)->paginate($limit, false, ['page' => $start])->toArray(); return $this->buildSuccess([ - 'list' => $listInfo, - 'count' => $count + 'list' => $listObj['data'], + 'count' => $listObj['total'] ]); } diff --git a/application/admin/controller/Auth.php b/application/admin/controller/Auth.php index 398f53c..b5f3ea8 100644 --- a/application/admin/controller/Auth.php +++ b/application/admin/controller/Auth.php @@ -20,15 +20,13 @@ class Auth extends Base { /** * 获取权限组列表 * @return array - * @throws \think\db\exception\DataNotFoundException - * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException * @author zhaoxiang */ public function index() { $limit = $this->request->get('size', config('apiAdmin.ADMIN_LIST_DEFAULT')); - $start = $limit * ($this->request->get('page', 1) - 1); + $start = $this->request->get('page', 1); $keywords = $this->request->get('keywords', ''); $status = $this->request->get('status', ''); @@ -36,14 +34,12 @@ class Auth extends Base { if ($status === '1' || $status === '0') { $where['status'] = $status; } - - $listInfo = (new AdminAuthGroup())->where($where)->order('id', 'DESC')->limit($start, $limit)->select(); - $count = (new AdminAuthGroup())->where($where)->count(); - $listInfo = Tools::buildArrFromObj($listInfo); + $listObj = (new AdminAuthGroup())->where($where)->order('id DESC') + ->paginate($limit, false, ['page' => $start])->toArray(); return $this->buildSuccess([ - 'list' => $listInfo, - 'count' => $count + 'list' => $listObj['data'], + 'count' => $listObj['total'] ]); } diff --git a/application/admin/controller/Fields.php b/application/admin/controller/Fields.php index dbfea56..3f210e2 100644 --- a/application/admin/controller/Fields.php +++ b/application/admin/controller/Fields.php @@ -33,24 +33,22 @@ class Fields extends Base { /** * 获取请求参数 - * @throws \think\db\exception\DataNotFoundException - * @throws \think\db\exception\ModelNotFoundException + * @return array * @throws \think\exception\DbException * @author zhaoxiang */ public function request() { $limit = $this->request->get('size', config('apiAdmin.ADMIN_LIST_DEFAULT')); - $start = $limit * ($this->request->get('page', 1) - 1); + $start = $this->request->get('page', 1); $hash = $this->request->get('hash', ''); if (!empty($hash)) { - $listInfo = (new AdminFields())->where(['hash' => $hash, 'type' => 0])->limit($start, $limit)->select(); - $count = (new AdminFields())->where(['hash' => $hash, 'type' => 0])->count(); - $listInfo = Tools::buildArrFromObj($listInfo); + $listObj = (new AdminFields())->where(['hash' => $hash, 'type' => 0]) + ->paginate($limit, false, ['page' => $start])->toArray(); return $this->buildSuccess([ - 'list' => $listInfo, - 'count' => $count, + 'list' => $listObj['data'], + 'count' => $listObj['total'], 'dataType' => $this->dataType ]); } else { @@ -61,24 +59,21 @@ class Fields extends Base { /** * 获取返回参数 * @return array - * @throws \think\db\exception\DataNotFoundException - * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException * @author zhaoxiang */ public function response() { $limit = $this->request->get('size', config('apiAdmin.ADMIN_LIST_DEFAULT')); - $start = $limit * ($this->request->get('page', 1) - 1); + $start = $this->request->get('page', 1); $hash = $this->request->get('hash', ''); if (!empty($hash)) { - $listInfo = (new AdminFields())->where(['hash' => $hash, 'type' => 1])->limit($start, $limit)->select(); - $count = (new AdminFields())->where(['hash' => $hash, 'type' => 1])->count(); - $listInfo = Tools::buildArrFromObj($listInfo); + $listObj = (new AdminFields())->where(['hash' => $hash, 'type' => 1]) + ->paginate($limit, false, ['page' => $start])->toArray(); return $this->buildSuccess([ - 'list' => $listInfo, - 'count' => $count, + 'list' => $listObj['data'], + 'count' => $listObj['total'], 'dataType' => $this->dataType ]); } else { diff --git a/application/admin/controller/InterfaceGroup.php b/application/admin/controller/InterfaceGroup.php index 32f71cc..69357c5 100644 --- a/application/admin/controller/InterfaceGroup.php +++ b/application/admin/controller/InterfaceGroup.php @@ -17,15 +17,13 @@ use app\util\Tools; class InterfaceGroup extends Base { /** * 获取接口组列表 - * @author zhaoxiang * @return array - * @throws \think\db\exception\DataNotFoundException - * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException + * @author zhaoxiang */ public function index() { $limit = $this->request->get('size', config('apiAdmin.ADMIN_LIST_DEFAULT')); - $start = $limit * ($this->request->get('page', 1) - 1); + $start = $this->request->get('page', 1); $keywords = $this->request->get('keywords', ''); $type = $this->request->get('type', ''); $status = $this->request->get('status', ''); @@ -44,14 +42,11 @@ class InterfaceGroup extends Base { break; } } - - $listInfo = (new AdminGroup())->where($where)->limit($start, $limit)->select(); - $count = (new AdminGroup())->where($where)->count(); - $listInfo = Tools::buildArrFromObj($listInfo); + $listObj = (new AdminGroup())->where($where)->paginate($limit, false, ['page' => $start])->toArray(); return $this->buildSuccess([ - 'list' => $listInfo, - 'count' => $count + 'list' => $listObj['data'], + 'count' => $listObj['total'] ]); } diff --git a/application/admin/controller/InterfaceList.php b/application/admin/controller/InterfaceList.php index 852b9aa..7002f3d 100644 --- a/application/admin/controller/InterfaceList.php +++ b/application/admin/controller/InterfaceList.php @@ -17,16 +17,14 @@ use app\util\Tools; class InterfaceList extends Base { /** * 获取接口列表 - * @author zhaoxiang * @return array - * @throws \think\db\exception\DataNotFoundException - * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException + * @author zhaoxiang */ public function index() { $limit = $this->request->get('size', config('apiAdmin.ADMIN_LIST_DEFAULT')); - $start = $limit * ($this->request->get('page', 1) - 1); + $start = $this->request->get('page', 1); $keywords = $this->request->get('keywords', ''); $type = $this->request->get('type', ''); $status = $this->request->get('status', ''); @@ -48,14 +46,12 @@ class InterfaceList extends Base { break; } } - - $listInfo = (new AdminList())->where($where)->order('id', 'DESC')->limit($start, $limit)->select(); - $count = (new AdminList())->where($where)->count(); - $listInfo = Tools::buildArrFromObj($listInfo); + $listObj = (new AdminList())->where($where)->order('id', 'DESC') + ->paginate($limit, false, ['page' => $start])->toArray(); return $this->buildSuccess([ - 'list' => $listInfo, - 'count' => $count + 'list' => $listObj['data'], + 'count' => $listObj['total'] ]); } diff --git a/application/admin/controller/Log.php b/application/admin/controller/Log.php index 6837972..8f03461 100644 --- a/application/admin/controller/Log.php +++ b/application/admin/controller/Log.php @@ -20,15 +20,13 @@ class Log extends Base { /** * 获取操作日志列表 * @return array - * @throws \think\db\exception\DataNotFoundException - * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException * @author zhaoxiang */ public function index() { $limit = $this->request->get('size', config('apiAdmin.ADMIN_LIST_DEFAULT')); - $start = $limit * ($this->request->get('page', 1) - 1); + $start = $this->request->get('page', 1); $type = $this->request->get('type', ''); $keywords = $this->request->get('keywords', ''); @@ -46,14 +44,12 @@ class Log extends Base { break; } } - - $listInfo = (new AdminUserAction())->where($where)->order('addTime', 'DESC')->limit($start, $limit)->select(); - $count = (new AdminUserAction())->where($where)->count(); - $listInfo = Tools::buildArrFromObj($listInfo); + $listObj = (new AdminUserAction())->where($where)->order('addTime DESC') + ->paginate($limit, false, ['page' => $start])->toArray(); return $this->buildSuccess([ - 'list' => $listInfo, - 'count' => $count + 'list' => $listObj['data'], + 'count' => $listObj['total'] ]); } diff --git a/application/admin/controller/User.php b/application/admin/controller/User.php index bec87ae..83008b5 100644 --- a/application/admin/controller/User.php +++ b/application/admin/controller/User.php @@ -19,15 +19,13 @@ class User extends Base { /** * 获取用户列表 * @return array - * @throws \think\db\exception\DataNotFoundException - * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException * @author zhaoxiang */ public function index() { $limit = $this->request->get('size', config('apiAdmin.ADMIN_LIST_DEFAULT')); - $start = $limit * ($this->request->get('page', 1) - 1); + $start = $this->request->get('page', 1); $type = $this->request->get('type', ''); $keywords = $this->request->get('keywords', ''); $status = $this->request->get('status', ''); @@ -47,9 +45,9 @@ class User extends Base { } } - $listInfo = (new AdminUser())->where($where)->order('regTime', 'DESC')->limit($start, $limit)->select(); - $count = (new AdminUser())->where($where)->count(); - $listInfo = Tools::buildArrFromObj($listInfo); + $listObj = (new AdminUser())->where($where)->order('regTime DESC') + ->paginate($limit, false, ['page' => $start])->toArray(); + $listInfo = $listObj['data']; $idArr = array_column($listInfo, 'id'); $userData = AdminUserData::all(function($query) use ($idArr) { @@ -80,7 +78,7 @@ class User extends Base { return $this->buildSuccess([ 'list' => $listInfo, - 'count' => $count + 'count' => $listObj['total'] ]); } @@ -122,7 +120,7 @@ class User extends Base { */ public function getUsers() { $limit = $this->request->get('size', config('apiAdmin.ADMIN_LIST_DEFAULT')); - $start = $limit * ($this->request->get('page', 1) - 1); + $start = $this->request->get('page', 1); $gid = $this->request->get('gid', 0); if (!$gid) { return $this->buildFailed(ReturnCode::PARAM_INVALID, '非法操作'); @@ -132,9 +130,9 @@ class User extends Base { $listInfo = Tools::buildArrFromObj($listInfo); $uidArr = array_column($listInfo, 'uid'); - $userInfo = (new AdminUser())->whereIn('id', $uidArr)->order('regTime', 'DESC')->limit($start, $limit)->select(); - $count = (new AdminUser())->whereIn('id', $uidArr)->count(); - $userInfo = Tools::buildArrFromObj($userInfo); + $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); @@ -153,7 +151,7 @@ class User extends Base { return $this->buildSuccess([ 'list' => $userInfo, - 'count' => $count + 'count' => $listObj['total'] ]); }