diff --git a/application/admin/controller/User.php b/application/admin/controller/User.php index 60a4341..b555b54 100644 --- a/application/admin/controller/User.php +++ b/application/admin/controller/User.php @@ -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('操作失败!'); + } } \ No newline at end of file diff --git a/application/common.php b/application/common.php index 0377b2d..6ae36b1 100644 --- a/application/common.php +++ b/application/common.php @@ -9,6 +9,38 @@ // | Author: 流年 // +---------------------------------------------------------------------- +/** + * 判断是否是系统管理员 + * @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 diff --git a/application/config.php b/application/config.php index 29e09a2..673d25e 100644 --- a/application/config.php +++ b/application/config.php @@ -15,6 +15,7 @@ return [ 'WEBSITE_DOMAIN' => 'http://www.7d-vision.com', //官方网址 'COMPANY_NAME' => '北京七维视觉科技有限公司', //公司名称 'SQL_PRIMARY_KEY' => 'id', + 'USER_ADMINISTRATOR' => 1, // +---------------------------------------------------------------------- // | 应用设置