所有待办完成

This commit is contained in:
augushong
2019-10-10 21:26:16 +08:00
parent 44da234f53
commit b3c046e1c7
14 changed files with 525 additions and 26 deletions

View File

@@ -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);

View File

@@ -1,7 +1,6 @@
<?php
return [
'\app\middleware\PermissionAuth',
'\app\middleware\PermissionRecord',
'\app\middleware\AdminLog',
];

View File

@@ -1,11 +0,0 @@
<?php
namespace app\middleware;
class PermissionAuth
{
public function handle($request, \Closure $next)
{
return $next($request);
}
}

View File

@@ -16,6 +16,10 @@ class PermissionRecord
'action'=>$request->action()
];
if(in_array('',$current_access_info)){
return $next($request);
}
$model_permission = AdminPermission::where($current_access_info)->find();
if(empty($model_permission)){

8
composer.lock generated
View File

@@ -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",

View File

@@ -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,
],
// 更多的数据库配置信息
],
];

View File

@@ -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();

View File

@@ -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();
}
}

View File

@@ -0,0 +1,43 @@
<?php
use think\migration\Migrator;
use think\migration\db\Column;
class CreateTableAdminGroup extends Migrator
{
/**
* Change Method.
*
* Write your reversible migrations using this method.
*
* More information on writing migrations is available here:
* http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
*
* The following commands can be used in this method and Phinx will
* automatically reverse them when rolling back:
*
* createTable
* renameTable
* addColumn
* renameColumn
* addIndex
* addForeignKey
*
* Remember to call "create()" or "update()" and NOT "save()" when working
* with the Table class.
*/
public function change()
{
$table = $this->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();
}
}

View File

@@ -0,0 +1,53 @@
<?php
use think\migration\Migrator;
use think\migration\db\Column;
class CreateTableAdminLog extends Migrator
{
/**
* Change Method.
*
* Write your reversible migrations using this method.
*
* More information on writing migrations is available here:
* http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
*
* The following commands can be used in this method and Phinx will
* automatically reverse them when rolling back:
*
* createTable
* renameTable
* addColumn
* renameColumn
* addIndex
* addForeignKey
*
* Remember to call "create()" or "update()" and NOT "save()" when working
* with the Table class.
*/
public function change()
{
$table = $this->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();
}
}

View File

@@ -0,0 +1,47 @@
<?php
use think\migration\Migrator;
use think\migration\db\Column;
class CreateTableAdminPermission extends Migrator
{
/**
* Change Method.
*
* Write your reversible migrations using this method.
*
* More information on writing migrations is available here:
* http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
*
* The following commands can be used in this method and Phinx will
* automatically reverse them when rolling back:
*
* createTable
* renameTable
* addColumn
* renameColumn
* addIndex
* addForeignKey
*
* Remember to call "create()" or "update()" and NOT "save()" when working
* with the Table class.
*/
public function change()
{
$table = $this->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();
}
}

View File

@@ -0,0 +1,46 @@
<?php
use think\migration\Migrator;
use think\migration\db\Column;
class CreateTableUser extends Migrator
{
/**
* Change Method.
*
* Write your reversible migrations using this method.
*
* More information on writing migrations is available here:
* http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
*
* The following commands can be used in this method and Phinx will
* automatically reverse them when rolling back:
*
* createTable
* renameTable
* addColumn
* renameColumn
* addIndex
* addForeignKey
*
* Remember to call "create()" or "update()" and NOT "save()" when working
* with the Table class.
*/
public function change()
{
$table = $this->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();
}
}

View File

@@ -0,0 +1,262 @@
<?php
use think\migration\Seeder;
class InitAdminPermission extends Seeder
{
/**
* Run Method.
*
* Write your database seeder using this method.
*
* More information on writing seeders is available here:
* http://docs.phinx.org/en/latest/seeding.html
*/
public function run()
{
$permission_content = '
[
{
"id" : 3,
"name" : "系统设置",
"app" : "admin",
"controller" : "System",
"action" : "index",
"is_log" : 1
},
{
"id" : 9,
"name" : "系统第三方设置",
"app" : "admin",
"controller" : "System",
"action" : "others",
"is_log" : 1
},
{
"id" : 12,
"name" : "登录页面",
"app" : "admin",
"controller" : "Login",
"action" : "index",
"is_log" : 1
},
{
"id" : 13,
"name" : "登录验证",
"app" : "admin",
"controller" : "Login",
"action" : "auth",
"is_log" : 1
},
{
"id" : 18,
"name" : "退出",
"app" : "admin",
"controller" : "Login",
"action" : "logout",
"is_log" : 1
},
{
"id" : 21,
"name" : "系统设置更新",
"app" : "admin",
"controller" : "System",
"action" : "update",
"is_log" : 1
},
{
"id" : 24,
"name" : "管理员权限-删除",
"app" : "admin",
"controller" : "AdminPermission",
"action" : "delete",
"is_log" : 0
},
{
"id" : 25,
"name" : "管理员权限-列表",
"app" : "admin",
"controller" : "AdminPermission",
"action" : "index",
"is_log" : 0
},
{
"id" : 26,
"name" : "后台首页",
"app" : "admin",
"controller" : "Index",
"action" : "index",
"is_log" : 0
},
{
"id" : 27,
"name" : "管理员分组-列表",
"app" : "admin",
"controller" : "AdminGroup",
"action" : "index",
"is_log" : 0
},
{
"id" : 29,
"name" : "文件-列表",
"app" : "admin",
"controller" : "File",
"action" : "index",
"is_log" : 0
},
{
"id" : 30,
"name" : "管理员帐号-列表",
"app" : "admin",
"controller" : "Admin",
"action" : "index",
"is_log" : 1
},
{
"id" : 31,
"name" : "管理员权限-保存编辑",
"app" : "admin",
"controller" : "AdminPermission",
"action" : "update",
"is_log" : 0
},
{
"id" : 32,
"name" : "管理员-编辑(登陆的人自己改自己)",
"app" : "admin",
"controller" : "Admin",
"action" : "edit",
"is_log" : 0
},
{
"id" : 33,
"name" : "管理员日志-列表",
"app" : "admin",
"controller" : "Admin",
"action" : "adminLog",
"is_log" : 0
},
{
"id" : 34,
"name" : "管理员-改密码(自己改自己)",
"app" : "admin",
"controller" : "Admin",
"action" : "password",
"is_log" : 0
},
{
"id" : 35,
"name" : "管理员分组-添加",
"app" : "admin",
"controller" : "AdminGroup",
"action" : "create",
"is_log" : 0
},
{
"id" : 36,
"name" : "管理员分组-保存添加",
"app" : "admin",
"controller" : "AdminGroup",
"action" : "save",
"is_log" : 0
},
{
"id" : 37,
"name" : "管理员分组-删除",
"app" : "admin",
"controller" : "AdminGroup",
"action" : "delete",
"is_log" : 0
},
{
"id" : 38,
"name" : "管理员分组-编辑",
"app" : "admin",
"controller" : "AdminGroup",
"action" : "edit",
"is_log" : 0
},
{
"id" : 39,
"name" : "管理员分组-保存编辑",
"app" : "admin",
"controller" : "AdminGroup",
"action" : "update",
"is_log" : 0
},
{
"id" : 40,
"name" : "管理员-保存更新",
"app" : "admin",
"controller" : "Admin",
"action" : "update",
"is_log" : 0
},
{
"id" : 41,
"name" : "文件-磁盘清空",
"app" : "admin",
"controller" : "File",
"action" : "clear",
"is_log" : 0
},
{
"id" : 42,
"name" : "管理员帐号-添加",
"app" : "admin",
"controller" : "Admin",
"action" : "create",
"is_log" : 0
},
{
"id" : 43,
"name" : "管理员帐号-保存添加",
"app" : "admin",
"controller" : "Admin",
"action" : "save",
"is_log" : 0
},
{
"id" : 45,
"name" : "管理员帐号-编辑",
"app" : "admin",
"controller" : "Admin",
"action" : "editAccount",
"is_log" : 0
},
{
"id" : 46,
"name" : "管理员帐号-删除",
"app" : "admin",
"controller" : "Admin",
"action" : "delete",
"is_log" : 0
},
{
"id" : 47,
"name" : "管理员帐号-保存编辑",
"app" : "admin",
"controller" : "Admin",
"action" : "updateAccount",
"is_log" : 0
}
]
';
$permissions = json_decode($permission_content);
foreach ($permissions as $permission) {
$current_access_info = [
'app'=>$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);
}
}
}
}

View File

@@ -62,7 +62,6 @@
<tr>
<th>ID</th>
<th>预览</th>
<th>名称</th>
<th>文件信息</th>
<th>状态时间</th>
<th>操作</th>
@@ -89,9 +88,6 @@
<td>
<p>保存名称:{$vo->getData('save_name')}</p>
<p>文件名:{$vo->getData('file_name')}</p>
</td>
<td>
<p>文件类型: {$vo.mime_type}</p>
<p>文件用途: <span style="color: red">{$vo.type}</span> </p>
<p>文件大小: {$vo.file_size}</p>