mirror of
https://gitee.com/apiadmin/ApiAdmin.git
synced 2025-04-06 03:58:00 +08:00
modified 新增加用户列表查询
This commit is contained in:
parent
40eab59c39
commit
3b8cdc684a
@ -58,6 +58,27 @@ class Base extends Controller {
|
||||
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) {
|
||||
if ($data) {
|
||||
$this->debug[] = $data;
|
||||
|
@ -16,25 +16,45 @@ 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() {
|
||||
$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');
|
||||
|
||||
foreach ($listInfo as $key => $value) {
|
||||
if ($userData) {
|
||||
if (isset($userData[$value['id']])) {
|
||||
$listInfo[$key]['lastLoginIp'] = long2ip($userData[$value['id']]['lastLoginIp']);
|
||||
$listInfo[$key]['loginTimes'] = $userData[$value['id']]['loginTimes'];
|
||||
$listInfo[$key]['lastLoginTime'] = date('Y-m-d H:i:s', $userData[$value['id']]['lastLoginTime']);
|
||||
}
|
||||
$listInfo[$key]['regIp'] = long2ip($listInfo[$key]['regIp']);
|
||||
}
|
||||
|
||||
return $this->buildSuccess([
|
||||
'list' => $listInfo,
|
||||
'count' => $count
|
||||
], '登录成功');
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -32,7 +32,7 @@ class BuildToken extends Base {
|
||||
if ($sign !== $signature) {
|
||||
return $this->buildFailed(ReturnCode::INVALID, '身份令牌验证失败');
|
||||
}
|
||||
$expires = config('apiAdmin.ONLINE_TIME');
|
||||
$expires = config('apiAdmin.ACCESS_TOKEN_TIME_OUT');
|
||||
$accessToken = cache($param['device_id']);
|
||||
if ($accessToken) {
|
||||
cache($accessToken, null);
|
||||
|
@ -13,10 +13,16 @@ return [
|
||||
'APP_VERSION' => 'v3.0',
|
||||
'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',
|
||||
|
||||
//后台登录状态维持时间[目前只有登录和解锁会重置登录时间]
|
||||
'ONLINE_TIME' => 7200,
|
||||
//AccessToken失效时间
|
||||
'ACCESS_TOKEN_TIME_OUT' => 7200,
|
||||
'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-Credentials' => 'true'
|
||||
],
|
||||
|
||||
//后台列表默认一页显示数量
|
||||
'ADMIN_LIST_DEFAULT' => 20,
|
||||
];
|
||||
|
Loading…
x
Reference in New Issue
Block a user