From 61f67118af277d3c331664d07d9726e0c27620af Mon Sep 17 00:00:00 2001 From: zhaoxiang <756958008@qq.com> Date: Fri, 11 Nov 2016 18:53:10 +0800 Subject: [PATCH] =?UTF-8?q?added=20=E5=AE=8C=E6=88=90=E8=B8=A2=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E5=87=BA=E7=BB=84=E7=9A=84=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/admin/controller/Auth.php | 78 +++++++++++++++++++++++++++ application/admin/controller/User.php | 2 + 2 files changed, 80 insertions(+) diff --git a/application/admin/controller/Auth.php b/application/admin/controller/Auth.php index 814d6eb..db834ac 100644 --- a/application/admin/controller/Auth.php +++ b/application/admin/controller/Auth.php @@ -11,6 +11,8 @@ namespace app\admin\controller; use app\admin\model\AuthGroup; use app\admin\model\AuthGroupAccess; use app\admin\model\AuthRule; +use app\admin\model\User; +use app\admin\model\UserData; use think\Validate; class Auth extends Base { @@ -378,5 +380,81 @@ class Auth extends Base { } } + /** + * 权限组用户维护 + */ + public function userAuth(){ + if( $this->request->isDelete() ){ + $key = $this->request->delete($this->primaryKey); + AuthGroupAccess::destroy([$this->primaryKey => $key]); + $this->success('操作成功', url('Auth/index')); + }else{ + $data = []; + $dataArrObj = AuthGroupAccess::where(['group_id' => $this->request->get($this->primaryKey)])->select(); + if( !empty($dataArrObj) ){ + foreach ( $dataArrObj as $dataObj ){ + $userObj = User::get([$this->primaryKey => $dataObj->uid]); + $userDataObj = UserData::get(['uid' => $dataObj->uid]); + $_data['id'] = $dataObj->id; + $_data['username'] = $userObj->username; + $_data['nickname'] = $userObj->nickname; + if( !is_null($userDataObj) ){ + $userDataObj->toArray(); + $_data['loginTimes'] = $userDataObj['loginTimes']; + $_data['lastLoginTime'] = $userDataObj['lastLoginTime']; + $_data['lastLoginIp'] = $userDataObj['lastLoginIp']; + }else{ + $_data['loginTimes'] = 0; + $_data['lastLoginTime'] = 0; + $_data['lastLoginIp'] = 0; + } + $data[] = $_data; + } + } + $table = [ + 'tempType' => 'table', + 'header' => [ + [ + 'field' => 'username', + 'info' => '用户账号' + ], + [ + 'field' => 'nickname', + 'info' => '用户昵称' + ], + [ + 'field' => 'loginTimes', + 'info' => '登录次数' + ], + [ + 'field' => 'lastLoginTime', + 'info' => '最后登录时间' + ], + [ + 'field' => 'lastLoginIp', + 'info' => '最后登录IP' + ] + ], + 'rightButton' => [ + [ + 'info' => '删除', + 'href' => url('Auth/userAuth'), + 'class'=> 'btn-danger ajax-delete', + 'param'=> [$this->primaryKey], + 'icon' => 'fa fa-trash', + 'confirm' => 1, + ] + ], + 'typeRule' => [ + 'lastLoginTime' => [ + 'module' => 'date', + ] + ], + 'data' => $data + ]; + $this->result($table, ReturnCode::GET_TEMPLATE_SUCCESS); + } + } + } \ No newline at end of file diff --git a/application/admin/controller/User.php b/application/admin/controller/User.php index b555b54..34ae035 100644 --- a/application/admin/controller/User.php +++ b/application/admin/controller/User.php @@ -8,6 +8,7 @@ namespace app\admin\controller; +use app\admin\model\AuthGroupAccess; use app\admin\model\UserData; class User extends Base { @@ -270,6 +271,7 @@ class User extends Base { $delNum = \app\admin\model\User::destroy($key); if( $delNum ){ UserData::destroy(['uid' => $key]); + AuthGroupAccess::destroy(['uid' => $key]); $this->success('操作成功!', url('User/index')); } }else{