backstage seeds upload

This commit is contained in:
yanwenwu
2018-11-21 11:10:25 +08:00
parent 0e0492978c
commit a38ec53d1d
8 changed files with 313 additions and 3 deletions

View File

@@ -0,0 +1,200 @@
<?php
use think\migration\Seeder;
class Permissions 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()
{
$data = [
[
'id' => 1,
'name' => '权限管理',
'icon' => '',
'pid' => 0,
'module' => '',
'controller' => '',
'action' => '',
'is_show' => 1,
],
[
'id' => 2,
'name' => '用户管理',
'icon' => '',
'pid' => 1,
'module' => 'admin',
'controller' => 'user',
'action' => 'index',
'is_show' => 1,
],
[
'id' => 3,
'name' => '角色管理',
'icon' => '',
'pid' => 1,
'module' => 'admin',
'controller' => 'role',
'action' => 'index',
'is_show' => 1,
],
[
'id' => 4,
'name' => '菜单管理',
'icon' => '',
'pid' => 1,
'module' => 'admin',
'controller' => 'permission',
'action' => 'index',
'is_show' => 1,
],
[
'id' => 5,
'name' => '创建用户',
'icon' => '',
'pid' => 2,
'module' => 'admin',
'controller' => 'user',
'action' => 'create',
'is_show' => 2,
],
[
'id' => 6,
'name' => '编辑用户',
'icon' => '',
'pid' => 2,
'module' => 'admin',
'controller' => 'user',
'action' => 'edit',
'is_show' => 2,
],
[
'id' => 7,
'name' => '删除用户',
'icon' => '',
'pid' => 2,
'module' => 'admin',
'controller' => 'user',
'action' => 'delete',
'is_show' => 2,
],
[
'id' => 8,
'name' => '创建角色',
'icon' => '',
'pid' => 3,
'module' => 'admin',
'controller' => 'role',
'action' => 'create',
'is_show' => 2,
],
[
'id' => 9,
'name' => '编辑角色',
'icon' => '',
'pid' => 3,
'module' => 'admin',
'controller' => 'role',
'action' => 'edit',
'is_show' => 2,
],
[
'id' => 10,
'name' => '删除角色',
'icon' => '',
'pid' => 3,
'module' => 'admin',
'controller' => 'role',
'action' => 'delete',
'is_show' => 2,
],
[
'id' => 11,
'name' => '获取角色权限',
'icon' => '',
'pid' => 3,
'module' => 'admin',
'controller' => 'role',
'action' => 'getPermissionsOfRole',
'is_show' => 2,
],
[
'id' => 12,
'name' => '分配权限',
'icon' => '',
'pid' => 3,
'module' => 'admin',
'controller' => 'role',
'action' => 'givePermissions',
'is_show' => 2,
],
[
'id' => 13,
'name' => '分配角色',
'icon' => '',
'pid' => 2,
'module' => 'admin',
'controller' => 'user',
'action' => 'giveRoles',
'is_show' => 2,
],
[
'id' => 14,
'name' => '创建菜单',
'icon' => '',
'pid' => 4,
'module' => 'admin',
'controller' => 'permission',
'action' => 'create',
'is_show' => 2,
],
[
'id' => 15,
'name' => '编辑菜单',
'icon' => '',
'pid' => 4,
'module' => 'admin',
'controller' => 'permission',
'action' => 'edit',
'is_show' => 2,
],
[
'id' => 16,
'name' => '删除菜单',
'icon' => '',
'pid' => 4,
'module' => 'admin',
'controller' => 'permission',
'action' => 'delete',
'is_show' => 2,
],
];
$this->table(config('permissions.table.permission'))->insert($data)->save();
}
}

View File

@@ -0,0 +1,28 @@
<?php
use think\migration\Seeder;
class RoleHasPermissions 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()
{
$p = \think\permissions\facade\Permissions::all();
$data = [];
foreach ($p as $v) {
$data[] = [
'role_id' => 1,
'permission_id' => $v->id,
];
}
$this->table(config('permissions.table.role_has_permissions'))->insert($data)->save();
}
}

24
database/seeds/Roles.php Normal file
View File

@@ -0,0 +1,24 @@
<?php
use think\migration\Seeder;
class Roles 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()
{
$data = [
'name' => '超级管理员',
];
$this->table(config('permissions.table.role'))->insert($data)->save();
}
}

View File

@@ -0,0 +1,24 @@
<?php
use think\migration\Seeder;
class UserHasRoles 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()
{
$data = [
'uid' => 1,
'role_id' => 1,
];
$this->table(config('permissions.table.user_has_roles'))->insert($data)->save();
}
}

25
database/seeds/Users.php Normal file
View File

@@ -0,0 +1,25 @@
<?php
use think\migration\Seeder;
class Users 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()
{
$data = [
'name' => 'admin',
'email' => 'admin@gmail.com',
'password' => password_hash('admin', PASSWORD_DEFAULT),
];
$this->table('users')->insert([$data])->save();
}
}