modified 新增加用户列表查询

This commit is contained in:
zhaoxiang 2018-02-07 17:22:42 +08:00
parent 40eab59c39
commit 3b8cdc684a
4 changed files with 57 additions and 7 deletions

View File

@ -58,6 +58,27 @@ class Base extends Controller {
return $list; return $list;
} }
/**
* 将查询的二维对象转换成二维数组
* @param Object $res
* @param string $key
* @return array
* @author zhaoxiang <zhaoxiang051405@gmail.com>
*/
protected function buildArrFromObj($res, $key = '') {
$arr = [];
foreach ($res as $value) {
$value = $value->toArray();
if ($key) {
$arr[$value[$key]] = $value;
} else {
$arr[] = $value;
}
}
return $arr;
}
protected function debug($data) { protected function debug($data) {
if ($data) { if ($data) {
$this->debug[] = $data; $this->debug[] = $data;

View File

@ -16,25 +16,45 @@ class User extends Base {
/** /**
* 获取用户列表 * 获取用户列表
* @return array * @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
* @author zhaoxiang <zhaoxiang051405@gmail.com> * @author zhaoxiang <zhaoxiang051405@gmail.com>
*/ */
public function index() { public function index() {
$listInfo = ApiUser::all();
$userData = ApiUserData::all(); $limit = $this->request->get('size', config('apiAdmin.ADMIN_LIST_DEFAULT'));
$start = $limit * ($this->request->get('page', 1) - 1);
$key = $this->request->get('key', '');
$order = $this->request->get('order', '');
$listModel = (new ApiUser())->where([])->order('regTime', 'DESC');
$listInfo = $listModel->limit($start, $limit)->select();
$count = $listModel->count();
$listInfo = $this->buildArrFromObj($listInfo);
$idArr = array_column($listInfo, 'id');
$userData = ApiUserData::all(function($query) use($idArr) {
$query->whereIn('uid', $idArr);
});
$userData = $this->buildArrFromObj($userData);
$userData = $this->buildArrByNewKey($userData, 'uid'); $userData = $this->buildArrByNewKey($userData, 'uid');
foreach ($listInfo as $key => $value) { foreach ($listInfo as $key => $value) {
if ($userData) { if (isset($userData[$value['id']])) {
$listInfo[$key]['lastLoginIp'] = long2ip($userData[$value['id']]['lastLoginIp']); $listInfo[$key]['lastLoginIp'] = long2ip($userData[$value['id']]['lastLoginIp']);
$listInfo[$key]['loginTimes'] = $userData[$value['id']]['loginTimes']; $listInfo[$key]['loginTimes'] = $userData[$value['id']]['loginTimes'];
$listInfo[$key]['lastLoginTime'] = date('Y-m-d H:i:s', $userData[$value['id']]['lastLoginTime']); $listInfo[$key]['lastLoginTime'] = date('Y-m-d H:i:s', $userData[$value['id']]['lastLoginTime']);
} }
$listInfo[$key]['regIp'] = long2ip($listInfo[$key]['regIp']);
} }
return $this->buildSuccess([ return $this->buildSuccess([
'list' => $listInfo, 'list' => $listInfo,
'count' => $count 'count' => $count
], '登录成功'); ]);
} }
/** /**

View File

@ -32,7 +32,7 @@ class BuildToken extends Base {
if ($sign !== $signature) { if ($sign !== $signature) {
return $this->buildFailed(ReturnCode::INVALID, '身份令牌验证失败'); return $this->buildFailed(ReturnCode::INVALID, '身份令牌验证失败');
} }
$expires = config('apiAdmin.ONLINE_TIME'); $expires = config('apiAdmin.ACCESS_TOKEN_TIME_OUT');
$accessToken = cache($param['device_id']); $accessToken = cache($param['device_id']);
if ($accessToken) { if ($accessToken) {
cache($accessToken, null); cache($accessToken, null);
@ -77,4 +77,4 @@ class BuildToken extends Base {
return md5($preStr); return md5($preStr);
} }
} }

View File

@ -13,10 +13,16 @@ return [
'APP_VERSION' => 'v3.0', 'APP_VERSION' => 'v3.0',
'APP_NAME' => 'ApiAdmin', 'APP_NAME' => 'ApiAdmin',
'USER_ADMINISTRATOR' => array(1, 2), //鉴权相关
'USER_ADMINISTRATOR' => [1, 2],
//安全秘钥
'AUTH_KEY' => 'I&TC{pft>L,C`wFQ>&#ROW>k{Kxlt1>ryW(>r<#R', 'AUTH_KEY' => 'I&TC{pft>L,C`wFQ>&#ROW>k{Kxlt1>ryW(>r<#R',
//后台登录状态维持时间[目前只有登录和解锁会重置登录时间]
'ONLINE_TIME' => 7200, 'ONLINE_TIME' => 7200,
//AccessToken失效时间
'ACCESS_TOKEN_TIME_OUT' => 7200,
'COMPANY_NAME' => 'ApiAdmin开发维护团队', 'COMPANY_NAME' => 'ApiAdmin开发维护团队',
//跨域配置 //跨域配置
@ -26,4 +32,7 @@ return [
'Access-Control-Allow-Headers' => 'Authorization, User-Agent, Keep-Alive, Origin, No-Cache, X-Requested-With, If-Modified-Since, Pragma, Last-Modified, Cache-Control, Expires, Content-Type, X-E4M-With', 'Access-Control-Allow-Headers' => 'Authorization, User-Agent, Keep-Alive, Origin, No-Cache, X-Requested-With, If-Modified-Since, Pragma, Last-Modified, Cache-Control, Expires, Content-Type, X-E4M-With',
'Access-Control-Allow-Credentials' => 'true' 'Access-Control-Allow-Credentials' => 'true'
], ],
//后台列表默认一页显示数量
'ADMIN_LIST_DEFAULT' => 20,
]; ];