added 删除用户的实现

This commit is contained in:
zhaoxiang 2016-11-11 13:51:36 +08:00
parent 33603d89b3
commit 064fa2ff19
3 changed files with 52 additions and 3 deletions

View File

@ -204,8 +204,8 @@ class User extends Base {
public function add(){ public function add(){
if( $this->request->isPost() ){ if( $this->request->isPost() ){
$menuModel = new \app\admin\model\User(); $userModel = new \app\admin\model\User();
$result = $menuModel->allowField(true)->validate( $result = $userModel->allowField(true)->validate(
[ [
'username' => 'require', 'username' => 'require',
],[ ],[
@ -213,7 +213,7 @@ class User extends Base {
] ]
)->save($this->request->post()); )->save($this->request->post());
if(false === $result){ if(false === $result){
$this->error($menuModel->getError()); $this->error($userModel->getError());
}else{ }else{
$this->success('操作成功!', url('User/index')); $this->success('操作成功!', url('User/index'));
} }
@ -262,4 +262,20 @@ class User extends Base {
$this->result($form, ReturnCode::GET_TEMPLATE_SUCCESS); $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('操作失败!');
}
} }

View File

@ -9,6 +9,38 @@
// | Author: 流年 <liu21st@gmail.com> // | 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数据 * CURL post数据
* @param $url * @param $url

View File

@ -15,6 +15,7 @@ return [
'WEBSITE_DOMAIN' => 'http://www.7d-vision.com', //官方网址 'WEBSITE_DOMAIN' => 'http://www.7d-vision.com', //官方网址
'COMPANY_NAME' => '北京七维视觉科技有限公司', //公司名称 'COMPANY_NAME' => '北京七维视觉科技有限公司', //公司名称
'SQL_PRIMARY_KEY' => 'id', 'SQL_PRIMARY_KEY' => 'id',
'USER_ADMINISTRATOR' => 1,
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | 应用设置 // | 应用设置