modified 更新分页查询方式

This commit is contained in:
zhaoxiang 2018-05-08 18:10:02 +08:00
parent 882a9e8676
commit e390991a75
8 changed files with 52 additions and 83 deletions

View File

@ -25,7 +25,7 @@ class App extends Base {
public function index() { public function index() {
$limit = $this->request->get('size', config('apiAdmin.ADMIN_LIST_DEFAULT')); $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', ''); $keywords = $this->request->get('keywords', '');
$type = $this->request->get('type', ''); $type = $this->request->get('type', '');
$status = $this->request->get('status', ''); $status = $this->request->get('status', '');
@ -44,14 +44,12 @@ class App extends Base {
break; break;
} }
} }
$listObj = (new AdminApp())->where($where)->order('app_addTime DESC')
$listInfo = (new AdminApp())->where($where)->order('app_addTime', 'DESC')->limit($start, $limit)->select(); ->paginate($limit, false, ['page' => $start])->toArray();
$count = (new AdminApp())->where($where)->count();
$listInfo = Tools::buildArrFromObj($listInfo);
return $this->buildSuccess([ return $this->buildSuccess([
'list' => $listInfo, 'list' => $listObj['data'],
'count' => $count 'count' => $listObj['total']
]); ]);
} }

View File

@ -16,15 +16,13 @@ use app\util\Tools;
class AppGroup extends Base { class AppGroup extends Base {
/** /**
* 获取应用组列表 * 获取应用组列表
* @author zhaoxiang <zhaoxiang051405@gmail.com>
* @return array * @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException * @throws \think\exception\DbException
* @author zhaoxiang <zhaoxiang051405@gmail.com>
*/ */
public function index() { public function index() {
$limit = $this->request->get('size', config('apiAdmin.ADMIN_LIST_DEFAULT')); $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', ''); $keywords = $this->request->get('keywords', '');
$type = $this->request->get('type', ''); $type = $this->request->get('type', '');
$status = $this->request->get('status', ''); $status = $this->request->get('status', '');
@ -43,14 +41,11 @@ class AppGroup extends Base {
break; break;
} }
} }
$listObj = (new AdminAppGroup())->where($where)->paginate($limit, false, ['page' => $start])->toArray();
$listInfo = (new AdminAppGroup())->where($where)->limit($start, $limit)->select();
$count = (new AdminAppGroup())->where($where)->count();
$listInfo = Tools::buildArrFromObj($listInfo);
return $this->buildSuccess([ return $this->buildSuccess([
'list' => $listInfo, 'list' => $listObj['data'],
'count' => $count 'count' => $listObj['total']
]); ]);
} }

View File

@ -20,15 +20,13 @@ class Auth extends Base {
/** /**
* 获取权限组列表 * 获取权限组列表
* @return array * @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException * @throws \think\exception\DbException
* @author zhaoxiang <zhaoxiang051405@gmail.com> * @author zhaoxiang <zhaoxiang051405@gmail.com>
*/ */
public function index() { public function index() {
$limit = $this->request->get('size', config('apiAdmin.ADMIN_LIST_DEFAULT')); $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', ''); $keywords = $this->request->get('keywords', '');
$status = $this->request->get('status', ''); $status = $this->request->get('status', '');
@ -36,14 +34,12 @@ class Auth extends Base {
if ($status === '1' || $status === '0') { if ($status === '1' || $status === '0') {
$where['status'] = $status; $where['status'] = $status;
} }
$listObj = (new AdminAuthGroup())->where($where)->order('id DESC')
$listInfo = (new AdminAuthGroup())->where($where)->order('id', 'DESC')->limit($start, $limit)->select(); ->paginate($limit, false, ['page' => $start])->toArray();
$count = (new AdminAuthGroup())->where($where)->count();
$listInfo = Tools::buildArrFromObj($listInfo);
return $this->buildSuccess([ return $this->buildSuccess([
'list' => $listInfo, 'list' => $listObj['data'],
'count' => $count 'count' => $listObj['total']
]); ]);
} }

View File

@ -33,24 +33,22 @@ class Fields extends Base {
/** /**
* 获取请求参数 * 获取请求参数
* @throws \think\db\exception\DataNotFoundException * @return array
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException * @throws \think\exception\DbException
* @author zhaoxiang <zhaoxiang051405@gmail.com> * @author zhaoxiang <zhaoxiang051405@gmail.com>
*/ */
public function request() { public function request() {
$limit = $this->request->get('size', config('apiAdmin.ADMIN_LIST_DEFAULT')); $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', ''); $hash = $this->request->get('hash', '');
if (!empty($hash)) { if (!empty($hash)) {
$listInfo = (new AdminFields())->where(['hash' => $hash, 'type' => 0])->limit($start, $limit)->select(); $listObj = (new AdminFields())->where(['hash' => $hash, 'type' => 0])
$count = (new AdminFields())->where(['hash' => $hash, 'type' => 0])->count(); ->paginate($limit, false, ['page' => $start])->toArray();
$listInfo = Tools::buildArrFromObj($listInfo);
return $this->buildSuccess([ return $this->buildSuccess([
'list' => $listInfo, 'list' => $listObj['data'],
'count' => $count, 'count' => $listObj['total'],
'dataType' => $this->dataType 'dataType' => $this->dataType
]); ]);
} else { } else {
@ -61,24 +59,21 @@ class Fields extends Base {
/** /**
* 获取返回参数 * 获取返回参数
* @return array * @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException * @throws \think\exception\DbException
* @author zhaoxiang <zhaoxiang051405@gmail.com> * @author zhaoxiang <zhaoxiang051405@gmail.com>
*/ */
public function response() { public function response() {
$limit = $this->request->get('size', config('apiAdmin.ADMIN_LIST_DEFAULT')); $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', ''); $hash = $this->request->get('hash', '');
if (!empty($hash)) { if (!empty($hash)) {
$listInfo = (new AdminFields())->where(['hash' => $hash, 'type' => 1])->limit($start, $limit)->select(); $listObj = (new AdminFields())->where(['hash' => $hash, 'type' => 1])
$count = (new AdminFields())->where(['hash' => $hash, 'type' => 1])->count(); ->paginate($limit, false, ['page' => $start])->toArray();
$listInfo = Tools::buildArrFromObj($listInfo);
return $this->buildSuccess([ return $this->buildSuccess([
'list' => $listInfo, 'list' => $listObj['data'],
'count' => $count, 'count' => $listObj['total'],
'dataType' => $this->dataType 'dataType' => $this->dataType
]); ]);
} else { } else {

View File

@ -17,15 +17,13 @@ use app\util\Tools;
class InterfaceGroup extends Base { class InterfaceGroup extends Base {
/** /**
* 获取接口组列表 * 获取接口组列表
* @author zhaoxiang <zhaoxiang051405@gmail.com>
* @return array * @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException * @throws \think\exception\DbException
* @author zhaoxiang <zhaoxiang051405@gmail.com>
*/ */
public function index() { public function index() {
$limit = $this->request->get('size', config('apiAdmin.ADMIN_LIST_DEFAULT')); $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', ''); $keywords = $this->request->get('keywords', '');
$type = $this->request->get('type', ''); $type = $this->request->get('type', '');
$status = $this->request->get('status', ''); $status = $this->request->get('status', '');
@ -44,14 +42,11 @@ class InterfaceGroup extends Base {
break; break;
} }
} }
$listObj = (new AdminGroup())->where($where)->paginate($limit, false, ['page' => $start])->toArray();
$listInfo = (new AdminGroup())->where($where)->limit($start, $limit)->select();
$count = (new AdminGroup())->where($where)->count();
$listInfo = Tools::buildArrFromObj($listInfo);
return $this->buildSuccess([ return $this->buildSuccess([
'list' => $listInfo, 'list' => $listObj['data'],
'count' => $count 'count' => $listObj['total']
]); ]);
} }

View File

@ -17,16 +17,14 @@ use app\util\Tools;
class InterfaceList extends Base { class InterfaceList extends Base {
/** /**
* 获取接口列表 * 获取接口列表
* @author zhaoxiang <zhaoxiang051405@gmail.com>
* @return array * @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException * @throws \think\exception\DbException
* @author zhaoxiang <zhaoxiang051405@gmail.com>
*/ */
public function index() { public function index() {
$limit = $this->request->get('size', config('apiAdmin.ADMIN_LIST_DEFAULT')); $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', ''); $keywords = $this->request->get('keywords', '');
$type = $this->request->get('type', ''); $type = $this->request->get('type', '');
$status = $this->request->get('status', ''); $status = $this->request->get('status', '');
@ -48,14 +46,12 @@ class InterfaceList extends Base {
break; break;
} }
} }
$listObj = (new AdminList())->where($where)->order('id', 'DESC')
$listInfo = (new AdminList())->where($where)->order('id', 'DESC')->limit($start, $limit)->select(); ->paginate($limit, false, ['page' => $start])->toArray();
$count = (new AdminList())->where($where)->count();
$listInfo = Tools::buildArrFromObj($listInfo);
return $this->buildSuccess([ return $this->buildSuccess([
'list' => $listInfo, 'list' => $listObj['data'],
'count' => $count 'count' => $listObj['total']
]); ]);
} }

View File

@ -20,15 +20,13 @@ class Log extends Base {
/** /**
* 获取操作日志列表 * 获取操作日志列表
* @return array * @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException * @throws \think\exception\DbException
* @author zhaoxiang <zhaoxiang051405@gmail.com> * @author zhaoxiang <zhaoxiang051405@gmail.com>
*/ */
public function index() { public function index() {
$limit = $this->request->get('size', config('apiAdmin.ADMIN_LIST_DEFAULT')); $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', ''); $type = $this->request->get('type', '');
$keywords = $this->request->get('keywords', ''); $keywords = $this->request->get('keywords', '');
@ -46,14 +44,12 @@ class Log extends Base {
break; break;
} }
} }
$listObj = (new AdminUserAction())->where($where)->order('addTime DESC')
$listInfo = (new AdminUserAction())->where($where)->order('addTime', 'DESC')->limit($start, $limit)->select(); ->paginate($limit, false, ['page' => $start])->toArray();
$count = (new AdminUserAction())->where($where)->count();
$listInfo = Tools::buildArrFromObj($listInfo);
return $this->buildSuccess([ return $this->buildSuccess([
'list' => $listInfo, 'list' => $listObj['data'],
'count' => $count 'count' => $listObj['total']
]); ]);
} }

View File

@ -19,15 +19,13 @@ class User extends Base {
/** /**
* 获取用户列表 * 获取用户列表
* @return array * @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException * @throws \think\exception\DbException
* @author zhaoxiang <zhaoxiang051405@gmail.com> * @author zhaoxiang <zhaoxiang051405@gmail.com>
*/ */
public function index() { public function index() {
$limit = $this->request->get('size', config('apiAdmin.ADMIN_LIST_DEFAULT')); $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', ''); $type = $this->request->get('type', '');
$keywords = $this->request->get('keywords', ''); $keywords = $this->request->get('keywords', '');
$status = $this->request->get('status', ''); $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(); $listObj = (new AdminUser())->where($where)->order('regTime DESC')
$count = (new AdminUser())->where($where)->count(); ->paginate($limit, false, ['page' => $start])->toArray();
$listInfo = Tools::buildArrFromObj($listInfo); $listInfo = $listObj['data'];
$idArr = array_column($listInfo, 'id'); $idArr = array_column($listInfo, 'id');
$userData = AdminUserData::all(function($query) use ($idArr) { $userData = AdminUserData::all(function($query) use ($idArr) {
@ -80,7 +78,7 @@ class User extends Base {
return $this->buildSuccess([ return $this->buildSuccess([
'list' => $listInfo, 'list' => $listInfo,
'count' => $count 'count' => $listObj['total']
]); ]);
} }
@ -122,7 +120,7 @@ class User extends Base {
*/ */
public function getUsers() { public function getUsers() {
$limit = $this->request->get('size', config('apiAdmin.ADMIN_LIST_DEFAULT')); $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); $gid = $this->request->get('gid', 0);
if (!$gid) { if (!$gid) {
return $this->buildFailed(ReturnCode::PARAM_INVALID, '非法操作'); return $this->buildFailed(ReturnCode::PARAM_INVALID, '非法操作');
@ -132,9 +130,9 @@ class User extends Base {
$listInfo = Tools::buildArrFromObj($listInfo); $listInfo = Tools::buildArrFromObj($listInfo);
$uidArr = array_column($listInfo, 'uid'); $uidArr = array_column($listInfo, 'uid');
$userInfo = (new AdminUser())->whereIn('id', $uidArr)->order('regTime', 'DESC')->limit($start, $limit)->select(); $listObj = (new AdminUser())->whereIn('id', $uidArr)->order('regTime DESC')
$count = (new AdminUser())->whereIn('id', $uidArr)->count(); ->paginate($limit, false, ['page' => $start])->toArray();
$userInfo = Tools::buildArrFromObj($userInfo); $userInfo = $listObj['data'];
$userData = AdminUserData::all(function($query) use ($uidArr) { $userData = AdminUserData::all(function($query) use ($uidArr) {
$query->whereIn('uid', $uidArr); $query->whereIn('uid', $uidArr);
@ -153,7 +151,7 @@ class User extends Base {
return $this->buildSuccess([ return $this->buildSuccess([
'list' => $userInfo, 'list' => $userInfo,
'count' => $count 'count' => $listObj['total']
]); ]);
} }