mirror of
https://gitee.com/apiadmin/ApiAdmin.git
synced 2025-04-06 03:58:00 +08:00
modified 优化细节
This commit is contained in:
parent
01bba5ac20
commit
27f9c4fd45
@ -27,7 +27,7 @@ class User extends Base {
|
|||||||
|
|
||||||
$limit = $this->request->get('size', config('apiadmin.ADMIN_LIST_DEFAULT'));
|
$limit = $this->request->get('size', config('apiadmin.ADMIN_LIST_DEFAULT'));
|
||||||
$start = $this->request->get('page', 1);
|
$start = $this->request->get('page', 1);
|
||||||
$type = $this->request->get('type', '');
|
$type = $this->request->get('type', '', 'intval');
|
||||||
$keywords = $this->request->get('keywords', '');
|
$keywords = $this->request->get('keywords', '');
|
||||||
$status = $this->request->get('status', '');
|
$status = $this->request->get('status', '');
|
||||||
|
|
||||||
@ -87,20 +87,19 @@ class User extends Base {
|
|||||||
public function add() {
|
public function add() {
|
||||||
$groups = '';
|
$groups = '';
|
||||||
$postData = $this->request->post();
|
$postData = $this->request->post();
|
||||||
$postData['regIp'] = request()->ip(1);
|
$postData['create_ip'] = request()->ip(1);
|
||||||
$postData['regTime'] = time();
|
|
||||||
$postData['password'] = Tools::userMd5($postData['password']);
|
$postData['password'] = Tools::userMd5($postData['password']);
|
||||||
if ($postData['groupId']) {
|
if (isset($postData['group_id']) && $postData['group_id']) {
|
||||||
$groups = trim(implode(',', $postData['groupId']), ',');
|
$groups = trim(implode(',', $postData['group_id']), ',');
|
||||||
|
unset($postData['group_id']);
|
||||||
}
|
}
|
||||||
unset($postData['groupId']);
|
|
||||||
$res = AdminUser::create($postData);
|
$res = AdminUser::create($postData);
|
||||||
if ($res === false) {
|
if ($res === false) {
|
||||||
return $this->buildFailed(ReturnCode::DB_SAVE_ERROR, '操作失败');
|
return $this->buildFailed(ReturnCode::DB_SAVE_ERROR, '操作失败');
|
||||||
} else {
|
} else {
|
||||||
AdminAuthGroupAccess::create([
|
AdminAuthGroupAccess::create([
|
||||||
'uid' => $res->id,
|
'uid' => $res->id,
|
||||||
'groupId' => $groups
|
'group_id' => $groups
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return $this->buildSuccess([]);
|
return $this->buildSuccess([]);
|
||||||
@ -157,9 +156,8 @@ class User extends Base {
|
|||||||
$id = $this->request->get('id');
|
$id = $this->request->get('id');
|
||||||
$status = $this->request->get('status');
|
$status = $this->request->get('status');
|
||||||
$res = AdminUser::update([
|
$res = AdminUser::update([
|
||||||
'id' => $id,
|
'id' => $id,
|
||||||
'status' => $status,
|
'status' => $status
|
||||||
'updateTime' => time()
|
|
||||||
]);
|
]);
|
||||||
if ($res === false) {
|
if ($res === false) {
|
||||||
return $this->buildFailed(ReturnCode::DB_SAVE_ERROR, '操作失败');
|
return $this->buildFailed(ReturnCode::DB_SAVE_ERROR, '操作失败');
|
||||||
@ -170,9 +168,9 @@ class User extends Base {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 编辑用户
|
* 编辑用户
|
||||||
* @author zhaoxiang <zhaoxiang051405@gmail.com>
|
|
||||||
* @return array
|
* @return array
|
||||||
* @throws \think\exception\DbException
|
* @throws \think\exception\DbException
|
||||||
|
* @author zhaoxiang <zhaoxiang051405@gmail.com>
|
||||||
*/
|
*/
|
||||||
public function edit() {
|
public function edit() {
|
||||||
$groups = '';
|
$groups = '';
|
||||||
@ -182,11 +180,10 @@ class User extends Base {
|
|||||||
} else {
|
} else {
|
||||||
$postData['password'] = Tools::userMd5($postData['password']);
|
$postData['password'] = Tools::userMd5($postData['password']);
|
||||||
}
|
}
|
||||||
if ($postData['groupId']) {
|
if (isset($postData['group_id']) && $postData['group_id']) {
|
||||||
$groups = trim(implode(',', $postData['groupId']), ',');
|
$groups = trim(implode(',', $postData['group_id']), ',');
|
||||||
|
unset($postData['group_id']);
|
||||||
}
|
}
|
||||||
$postData['updateTime'] = time();
|
|
||||||
unset($postData['groupId']);
|
|
||||||
$res = AdminUser::update($postData);
|
$res = AdminUser::update($postData);
|
||||||
if ($res === false) {
|
if ($res === false) {
|
||||||
return $this->buildFailed(ReturnCode::DB_SAVE_ERROR, '操作失败');
|
return $this->buildFailed(ReturnCode::DB_SAVE_ERROR, '操作失败');
|
||||||
@ -194,14 +191,14 @@ class User extends Base {
|
|||||||
$has = AdminAuthGroupAccess::get(['uid' => $postData['id']]);
|
$has = AdminAuthGroupAccess::get(['uid' => $postData['id']]);
|
||||||
if ($has) {
|
if ($has) {
|
||||||
AdminAuthGroupAccess::update([
|
AdminAuthGroupAccess::update([
|
||||||
'groupId' => $groups
|
'group_id' => $groups
|
||||||
], [
|
], [
|
||||||
'uid' => $postData['id'],
|
'uid' => $postData['id'],
|
||||||
]);
|
]);
|
||||||
} else {
|
} else {
|
||||||
AdminAuthGroupAccess::create([
|
AdminAuthGroupAccess::create([
|
||||||
'uid' => $postData['id'],
|
'uid' => $postData['id'],
|
||||||
'groupId' => $groups
|
'group_id' => $groups
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -211,9 +208,9 @@ class User extends Base {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 修改自己的信息
|
* 修改自己的信息
|
||||||
* @author zhaoxiang <zhaoxiang051405@gmail.com>
|
|
||||||
* @return array
|
* @return array
|
||||||
* @throws \think\exception\DbException
|
* @throws \think\exception\DbException
|
||||||
|
* @author zhaoxiang <zhaoxiang051405@gmail.com>
|
||||||
*/
|
*/
|
||||||
public function own() {
|
public function own() {
|
||||||
$postData = $this->request->post();
|
$postData = $this->request->post();
|
||||||
@ -255,6 +252,11 @@ class User extends Base {
|
|||||||
if (!$id) {
|
if (!$id) {
|
||||||
return $this->buildFailed(ReturnCode::EMPTY_PARAMS, '缺少必要参数');
|
return $this->buildFailed(ReturnCode::EMPTY_PARAMS, '缺少必要参数');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$isAdmin = Tools::isAdministrator($id);
|
||||||
|
if ($isAdmin) {
|
||||||
|
return $this->buildFailed(ReturnCode::INVALID, '超级管理员不能被删除');
|
||||||
|
}
|
||||||
AdminUser::destroy($id);
|
AdminUser::destroy($id);
|
||||||
AdminAuthGroupAccess::destroy(['uid' => $id]);
|
AdminAuthGroupAccess::destroy(['uid' => $id]);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user