From b3c046e1c7c18358379d9ba476ec88febc2db1c2 Mon Sep 17 00:00:00 2001 From: augushong Date: Thu, 10 Oct 2019 21:26:16 +0800 Subject: [PATCH] =?UTF-8?q?=E6=89=80=E6=9C=89=E5=BE=85=E5=8A=9E=E5=AE=8C?= =?UTF-8?q?=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/admin/controller/Common.php | 22 ++ app/admin/middleware.php | 1 - app/middleware/PermissionAuth.php | 11 - app/middleware/PermissionRecord.php | 4 + composer.lock | 8 +- config/database.php | 40 ++- ...190728015455_create_table_upload_files.php | 4 +- ...90822043653_create_table_system_config.php | 6 +- ...0191010123655_create_table_admin_group.php | 43 +++ .../20191010124107_create_table_admin_log.php | 53 ++++ ...10125828_create_table_admin_permission.php | 47 ++++ .../20191010130811_create_table_user.php | 46 +++ database/seeds/InitAdminPermission.php | 262 ++++++++++++++++++ view/admin/file/index.html | 4 - 14 files changed, 525 insertions(+), 26 deletions(-) delete mode 100644 app/middleware/PermissionAuth.php create mode 100644 database/migrations/20191010123655_create_table_admin_group.php create mode 100644 database/migrations/20191010124107_create_table_admin_log.php create mode 100644 database/migrations/20191010125828_create_table_admin_permission.php create mode 100644 database/migrations/20191010130811_create_table_user.php create mode 100644 database/seeds/InitAdminPermission.php diff --git a/app/admin/controller/Common.php b/app/admin/controller/Common.php index d88b893..bac9c5c 100644 --- a/app/admin/controller/Common.php +++ b/app/admin/controller/Common.php @@ -4,6 +4,7 @@ namespace app\admin\controller; use app\BaseController; use think\facade\Session; use app\model\Admin; +use app\model\AdminPermission; use think\exception\HttpResponseException; use think\facade\View; @@ -14,6 +15,7 @@ class Common extends BaseController{ public function initialize() { + $admin_id = Session::get('admin_id'); if($this->request->controller() !== 'Login'){ @@ -29,6 +31,26 @@ class Common extends BaseController{ throw new HttpResponseException(redirect('admin/Login/index')); } } + + if(!empty($this->adminInfo['group'])){ + + $current_access_info = [ + 'app'=>app('http')->getName(), + 'controller'=>request()->controller(), + 'action'=>request()->action() + ]; + + $model_permission = AdminPermission::where($current_access_info)->find(); + + if(!empty($model_permission)){ + if(!in_array($model_permission->id,$this->adminInfo->group->permissions)){ + return $this->error('您没有访问权限'); + } + } + } + + + } View::assign('admin',$this->adminInfo); diff --git a/app/admin/middleware.php b/app/admin/middleware.php index 7c703c7..a01674a 100644 --- a/app/admin/middleware.php +++ b/app/admin/middleware.php @@ -1,7 +1,6 @@ $request->action() ]; + if(in_array('',$current_access_info)){ + return $next($request); + } + $model_permission = AdminPermission::where($current_access_info)->find(); if(empty($model_permission)){ diff --git a/composer.lock b/composer.lock index d030ee5..0cc31d3 100644 --- a/composer.lock +++ b/composer.lock @@ -436,12 +436,12 @@ "source": { "type": "git", "url": "https://github.com/top-think/framework.git", - "reference": "cb8817c29981c2f735ee352a9432f22d6765839e" + "reference": "411736c6e8d36ab5e43303cbe08d5d1e369dedf7" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/top-think/framework/zipball/cb8817c29981c2f735ee352a9432f22d6765839e", - "reference": "cb8817c29981c2f735ee352a9432f22d6765839e", + "url": "https://api.github.com/repos/top-think/framework/zipball/411736c6e8d36ab5e43303cbe08d5d1e369dedf7", + "reference": "411736c6e8d36ab5e43303cbe08d5d1e369dedf7", "shasum": "", "mirrors": [ { @@ -496,7 +496,7 @@ "orm", "thinkphp" ], - "time": "2019-10-09T07:30:48+00:00" + "time": "2019-10-10T07:59:58+00:00" }, { "name": "topthink/think-captcha", diff --git a/config/database.php b/config/database.php index 5b667dc..9756ad1 100644 --- a/config/database.php +++ b/config/database.php @@ -3,7 +3,7 @@ use think\facade\Env; return [ // 默认使用的数据库连接配置 - 'default' => Env::get('database.driver', 'mysql'), + 'default' => Env::get('database.driver', 'sqlite'), // 自定义时间查询规则 'time_query_rule' => [], @@ -57,7 +57,43 @@ return [ // 字段缓存路径 'schema_cache_path' => app()->getRuntimePath() . 'schema' . DIRECTORY_SEPARATOR, ], - + 'sqlite' => [ + // 数据库类型 + 'type' => 'sqlite', + + // 服务器地址 + 'hostname' => Env::get('root_path').'ul.db', + // 数据库名 + 'database' => App::getRootPath().'ul.db', + // 用户名 + 'username' => Env::get('database.username', 'root'), + // 密码 + 'password' => Env::get('database.password', ''), + // 端口 + 'hostport' => Env::get('database.hostport', '3306'), + // 数据库连接参数 + 'params' => [], + // 数据库编码默认采用utf8 + 'charset' => Env::get('database.charset', 'utf8'), + // 数据库表前缀 + 'prefix' => Env::get('database.prefix', ''), + // 数据库调试模式 + 'debug' => Env::get('database.debug', true), + // 数据库部署方式:0 集中式(单一服务器),1 分布式(主从服务器) + 'deploy' => 0, + // 数据库读写是否分离 主从式有效 + 'rw_separate' => false, + // 读写分离后 主服务器数量 + 'master_num' => 1, + // 指定从服务器序号 + 'slave_no' => '', + // 是否严格检查字段是否存在 + 'fields_strict' => true, + // 是否需要进行SQL性能分析 + 'sql_explain' => false, + // 是否需要断线重连 + 'break_reconnect' => false, + ], // 更多的数据库配置信息 ], ]; diff --git a/database/migrations/20190728015455_create_table_upload_files.php b/database/migrations/20190728015455_create_table_upload_files.php index 52fbae9..55e1753 100644 --- a/database/migrations/20190728015455_create_table_upload_files.php +++ b/database/migrations/20190728015455_create_table_upload_files.php @@ -28,7 +28,7 @@ class CreateTableUploadFiles extends Migrator */ public function change() { - $table = $this->table('upload_files',['comment'=>'上传的文件']); + $table = $this->table('upload_files',['comment'=>'上传的文件','signed'=>false]); $table->addColumn('save_name','string',['limit'=>100,'comment'=>'文件存储地址']); $table->addColumn('file_name','string',['limit'=>100,'comment'=>'文件原始名称']); $table->addColumn('mime_type','string',['limit'=>30,'comment'=>'mime type 类型']); @@ -41,12 +41,14 @@ class CreateTableUploadFiles extends Migrator $table->addColumn('delete_time','integer',['limit'=>10,'comment'=>'删除时间']); $table->addColumn('clear_time','integer',['limit'=>10,'comment'=>'清空时间']); $table->addColumn('type','integer',['limit'=>2,'default'=>1,'comment'=>'文件类型,1:系统logo;2:管理员头像']); + $table->addColumn('status','integer',['limit'=>2,'default'=>0,'comment'=>'文件状态:0,上传未使用,1:已使用,2:已删除,3已清除']); $table->addIndex('save_name'); $table->addIndex('create_time'); $table->addIndex('used_time'); $table->addIndex('delete_time'); $table->addIndex('clear_time'); $table->addIndex('type'); + $table->addIndex('status'); $table->create(); diff --git a/database/migrations/20190822043653_create_table_system_config.php b/database/migrations/20190822043653_create_table_system_config.php index 8b45fce..0723fe1 100644 --- a/database/migrations/20190822043653_create_table_system_config.php +++ b/database/migrations/20190822043653_create_table_system_config.php @@ -28,10 +28,10 @@ class CreateTableSystemConfig extends Migrator */ public function change() { - $table = $this->table('system_config',['comment'=>'系统配置表']); + $table = $this->table('system_config',['comment'=>'系统配置表','signed'=>false]); $table->addColumn('name','string',['limit'=>30,'comment'=>'配置名称']); - $table->addColumn('value','string',['limit'=>500,'comment'=>'值']); + $table->addColumn('value','text',['comment'=>'值']); $table->addIndex('name'); - $table->save(); + $table->create(); } } diff --git a/database/migrations/20191010123655_create_table_admin_group.php b/database/migrations/20191010123655_create_table_admin_group.php new file mode 100644 index 0000000..4e5abbe --- /dev/null +++ b/database/migrations/20191010123655_create_table_admin_group.php @@ -0,0 +1,43 @@ +table('admin_group',[ + 'comment'=>'管理员组', + 'signed'=>false + ]); + + $table->addColumn('name','string',['limit'=>20,'comment'=>'组名']); + $table->addColumn('create_time','integer',['limit'=>11,'default'=>0,'comment'=>'添加时间']); + $table->addColumn('update_time','integer',['limit'=>11,'default'=>0,'comment'=>'更新时间']); + $table->addColumn('delete_time','integer',['limit'=>11,'default'=>0,'comment'=>'删除时间']); + $table->addColumn('permissions','text',['comment'=>'拥有权限']); + $table->create(); + } +} diff --git a/database/migrations/20191010124107_create_table_admin_log.php b/database/migrations/20191010124107_create_table_admin_log.php new file mode 100644 index 0000000..7e30173 --- /dev/null +++ b/database/migrations/20191010124107_create_table_admin_log.php @@ -0,0 +1,53 @@ +table('admin_log',[ + 'comment'=>'管理员日志', + 'signed'=>false + ]); + + $table->addColumn('app','string',['limit'=>50,'comment'=>'应用名']); + $table->addColumn('controller','string',['limit'=>50,'comment'=>'控制器名']); + $table->addColumn('action','string',['limit'=>50,'comment'=>'方法名']); + $table->addColumn('param','text',['comment'=>'参数']); + $table->addColumn('create_time','integer',['limit'=>11,'default'=>0,'comment'=>'添加时间']); + $table->addColumn('delete_time','integer',['limit'=>11,'default'=>0,'comment'=>'删除时间']); + $table->addColumn('admin_id','integer',['limit'=>20,'default'=>0,'comment'=>'管理员id']); + $table->addColumn('ip','string',['limit'=>30,'default'=>'','comment'=>'客户端ip']); + $table->addIndex('app'); + $table->addIndex('controller'); + $table->addIndex('action'); + $table->addIndex('delete_time'); + $table->addIndex('admin_id'); + $table->create(); + + + } +} diff --git a/database/migrations/20191010125828_create_table_admin_permission.php b/database/migrations/20191010125828_create_table_admin_permission.php new file mode 100644 index 0000000..b3b1157 --- /dev/null +++ b/database/migrations/20191010125828_create_table_admin_permission.php @@ -0,0 +1,47 @@ +table('admin_permission',[ + 'comment'=>'后台权限记录', + 'signed'=>false + ]); + + $table->addColumn('name','string',['limit'=>20,'default'=>'0','comment'=>'权限名称']); + $table->addColumn('app','string',['limit'=>50,'comment'=>'应用名']); + $table->addColumn('controller','string',['limit'=>50,'comment'=>'控制器名']); + $table->addColumn('action','string',['limit'=>50,'comment'=>'方法名']); + $table->addColumn('is_log','integer',['limit'=>1,'default'=>0,'comment'=>'是否把这个访问记录下来']); + $table->addIndex('app'); + $table->addIndex('controller'); + $table->addIndex('action'); + $table->addIndex('is_log'); + $table->create(); + } +} diff --git a/database/migrations/20191010130811_create_table_user.php b/database/migrations/20191010130811_create_table_user.php new file mode 100644 index 0000000..1f9d705 --- /dev/null +++ b/database/migrations/20191010130811_create_table_user.php @@ -0,0 +1,46 @@ +table('user',['comment'=>'用户表','signed'=>false]); + $table->addColumn('account','string',['limit'=>20,'comment'=>'用户帐号']); + $table->addColumn('password','string',['limit'=>32,'comment'=>'密码']); + $table->addColumn('salt','string',['limit'=>6,'comment'=>'密码盐']); + $table->addColumn('nickname','string',['limit'=>10,'comment'=>'昵称']); + $table->addColumn('avatar','string',['limit'=>40,'comment'=>'头像地址']); + $table->addColumn('create_time','integer',['limit'=>10,'default'=>0,'comment'=>'添加时间']); + $table->addColumn('update_time','integer',['limit'=>10,'default'=>0,'comment'=>'更新时间']); + $table->addColumn('delete_time','integer',['limit'=>10,'default'=>0,'comment'=>'删除时间']); + $table->addColumn('last_login_time','integer',['limit'=>10,'default'=>0,'comment'=>'最后一次登陆时间']); + $table->addColumn('status','integer',['limit'=>1,'default'=>0,'comment'=>'状态']); + $table->addIndex('account'); + $table->addIndex('delete_time'); + $table->create(); + } +} diff --git a/database/seeds/InitAdminPermission.php b/database/seeds/InitAdminPermission.php new file mode 100644 index 0000000..08c8631 --- /dev/null +++ b/database/seeds/InitAdminPermission.php @@ -0,0 +1,262 @@ +$permission['app'], + 'controller'=>$permission['controller'], + 'action'=>$permission['action'], + ]; + $model_permission = AdminPermission::where($current_access_info)->find(); + + if(empty($model_permission)){ + $current_access_info['name'] = $permissions['name']; + AdminPermission::create($current_access_info); + } + } + } +} \ No newline at end of file diff --git a/view/admin/file/index.html b/view/admin/file/index.html index c71020b..410c48e 100644 --- a/view/admin/file/index.html +++ b/view/admin/file/index.html @@ -62,7 +62,6 @@ ID 预览 - 名称 文件信息 状态时间 操作 @@ -89,9 +88,6 @@

保存名称:{$vo->getData('save_name')}

文件名:{$vo->getData('file_name')}

- - -

文件类型: {$vo.mime_type}

文件用途: {$vo.type}

文件大小: {$vo.file_size}