From 064fa2ff191e167b7665a0ef4755c5b0f6386ef0 Mon Sep 17 00:00:00 2001 From: zhaoxiang <756958008@qq.com> Date: Fri, 11 Nov 2016 13:51:36 +0800 Subject: [PATCH] =?UTF-8?q?added=20=E5=88=A0=E9=99=A4=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E7=9A=84=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/admin/controller/User.php | 22 +++++++++++++++--- application/common.php | 32 +++++++++++++++++++++++++++ application/config.php | 1 + 3 files changed, 52 insertions(+), 3 deletions(-) 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, // +---------------------------------------------------------------------- // | 应用设置