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() {
$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']
]);
}

View File

@ -16,15 +16,13 @@ use app\util\Tools;
class AppGroup extends Base {
/**
* 获取应用组列表
* @author zhaoxiang <zhaoxiang051405@gmail.com>
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
* @author zhaoxiang <zhaoxiang051405@gmail.com>
*/
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']
]);
}

View File

@ -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 <zhaoxiang051405@gmail.com>
*/
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']
]);
}

View File

@ -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 <zhaoxiang051405@gmail.com>
*/
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 <zhaoxiang051405@gmail.com>
*/
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 {

View File

@ -17,15 +17,13 @@ use app\util\Tools;
class InterfaceGroup extends Base {
/**
* 获取接口组列表
* @author zhaoxiang <zhaoxiang051405@gmail.com>
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
* @author zhaoxiang <zhaoxiang051405@gmail.com>
*/
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']
]);
}

View File

@ -17,16 +17,14 @@ use app\util\Tools;
class InterfaceList extends Base {
/**
* 获取接口列表
* @author zhaoxiang <zhaoxiang051405@gmail.com>
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
* @author zhaoxiang <zhaoxiang051405@gmail.com>
*/
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']
]);
}

View File

@ -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 <zhaoxiang051405@gmail.com>
*/
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']
]);
}

View File

@ -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 <zhaoxiang051405@gmail.com>
*/
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']
]);
}