mirror of
https://gitee.com/apiadmin/ApiAdmin.git
synced 2025-04-06 03:58:00 +08:00
added 删除用户的实现
This commit is contained in:
parent
33603d89b3
commit
064fa2ff19
@ -204,8 +204,8 @@ class User extends Base {
|
||||
|
||||
public function add(){
|
||||
if( $this->request->isPost() ){
|
||||
$menuModel = new \app\admin\model\User();
|
||||
$result = $menuModel->allowField(true)->validate(
|
||||
$userModel = new \app\admin\model\User();
|
||||
$result = $userModel->allowField(true)->validate(
|
||||
[
|
||||
'username' => 'require',
|
||||
],[
|
||||
@ -213,7 +213,7 @@ class User extends Base {
|
||||
]
|
||||
)->save($this->request->post());
|
||||
if(false === $result){
|
||||
$this->error($menuModel->getError());
|
||||
$this->error($userModel->getError());
|
||||
}else{
|
||||
$this->success('操作成功!', url('User/index'));
|
||||
}
|
||||
@ -262,4 +262,20 @@ class User extends Base {
|
||||
$this->result($form, ReturnCode::GET_TEMPLATE_SUCCESS);
|
||||
}
|
||||
}
|
||||
|
||||
public function del(){
|
||||
if( $this->request->isDelete() ){
|
||||
$key = $this->request->delete($this->primaryKey);
|
||||
if(!isAdministrator($key)){
|
||||
$delNum = \app\admin\model\User::destroy($key);
|
||||
if( $delNum ){
|
||||
UserData::destroy(['uid' => $key]);
|
||||
$this->success('操作成功!', url('User/index'));
|
||||
}
|
||||
}else{
|
||||
$this->error('管理员不能被删除!');
|
||||
}
|
||||
}
|
||||
$this->error('操作失败!');
|
||||
}
|
||||
}
|
@ -9,6 +9,38 @@
|
||||
// | Author: 流年 <liu21st@gmail.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* 判断是否是系统管理员
|
||||
* @param mixed $uid
|
||||
* @return bool
|
||||
*/
|
||||
function isAdministrator( $uid = '' ){
|
||||
$uid = empty($uid) ? session('uid') : $uid;
|
||||
if( is_array(config('USER_ADMINISTRATOR')) ){
|
||||
if( is_array( $uid ) ){
|
||||
$m = array_intersect( config('USER_ADMINISTRATOR'), $uid );
|
||||
if( count($m) ){
|
||||
return TRUE;
|
||||
}
|
||||
}else{
|
||||
if( in_array( $uid, config('USER_ADMINISTRATOR') ) ){
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
}else{
|
||||
if( is_array( $uid ) ){
|
||||
if( in_array(config('USER_ADMINISTRATOR'),$uid) ){
|
||||
return TRUE;
|
||||
}
|
||||
}else{
|
||||
if( $uid == config('USER_ADMINISTRATOR')){
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* CURL post数据
|
||||
* @param $url
|
||||
|
@ -15,6 +15,7 @@ return [
|
||||
'WEBSITE_DOMAIN' => 'http://www.7d-vision.com', //官方网址
|
||||
'COMPANY_NAME' => '北京七维视觉科技有限公司', //公司名称
|
||||
'SQL_PRIMARY_KEY' => 'id',
|
||||
'USER_ADMINISTRATOR' => 1,
|
||||
|
||||
// +----------------------------------------------------------------------
|
||||
// | 应用设置
|
||||
|
Loading…
x
Reference in New Issue
Block a user