vd/database/seeds/PermissionSeeder.php
2019-01-07 14:09:14 +08:00

198 lines
9.5 KiB
PHP

<?php
use Illuminate\Support\Str;
use App\Models\Account\Account;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
use App\Domains\Permission\Services\PermissionService;
use App\Domains\Permission\Repositories\RoleRepository;
use App\Domains\Permission\Repositories\PermissionRepository;
class PermissionSeeder extends Seeder
{
const ROLES = ['name' => '超级管理员'];
const PERMISSIONS = [
[
'name' => 'system_ctrl',
'title' => '系统设置',
'path' => '#',
'icon' => 'ios-settings',
'type' => 0,
'open' => 3,
'children' => [
[
'name' => 'permissions', 'title' => '权限管理', 'path' => '/permissions', 'icon' => 'ios-cube', 'type' => 0, 'open' => 3,
'children' => [
['name' => 'permissions.create', 'title' => '创建', 'description' => 'create', 'type' => 1],
['name' => 'permissions.update', 'title' => '编辑', 'description' => 'update', 'type' => 1],
['name' => 'permissions.destroy', 'title' => '删除', 'description' => 'destroy', 'type' => 1],
],
],
[
'name' => 'roles', 'title' => '角色管理', 'path' => '/roles', 'icon' => 'ios-appstore', 'type' => 0, 'open' => 3,
'children' => [
['name' => 'roles.show', 'title' => '查看', 'description' => 'show', 'type' => 1],
['name' => 'roles.create', 'title' => '创建', 'description' => 'create', 'type' => 1],
['name' => 'roles.update', 'title' => '编辑', 'description' => 'update', 'type' => 1],
['name' => 'roles.destroy', 'title' => '删除', 'description' => 'destroy', 'type' => 1],
['name' => 'roles.sync_permissions', 'title' => '分配权限', 'description' => 'jurisdiction', 'type' => 1],
],
],
[
'name' => 'accounts', 'title' => '账号管理', 'path' => '/accounts', 'icon' => 'ios-browsers', 'type' => 0, 'open' => 3,
'children' => [
['name' => 'accounts.show', 'title' => '查看', 'description' => 'show', 'type' => 1],
['name' => 'accounts.create', 'title' => '创建', 'description' => 'create', 'type' => 1],
['name' => 'accounts.update', 'title' => '编辑', 'description' => 'update', 'type' => 1],
['name' => 'accounts.destroy', 'title' => '删除', 'description' => 'destroy', 'type' => 1],
],
],
[
'name' => 'logs', 'title' => '日志管理', 'path' => '/logs', 'icon' => 'ios-cube', 'type' => 0, 'open' => 3,
'children' => [
['name' => 'logs.show','title' => '查看','description' => 'show','type' => 1],
['name' => 'logs.destroy','title' => '删除','description' => 'destroy','type' => 1],
],
],
],
],
[
'name' => 'virtual_company_ctrl',
'title' => '企业设置',
'path' => '#',
'icon' => 'ios-people',
'type' => 0,
'open' => 3,
'children' => [
[
'name' => 'virtual.companies.index', 'title' => '企业管理', 'path' => '/companies', 'icon' => 'ios-options', 'type' => 0, 'open' => 3,
'children' => [
['name' => 'virtual.companies.show', 'title' => '查看', 'description' => 'show', 'type' => 1],
['name' => 'virtual.companies.create', 'title' => '创建', 'description' => 'create', 'type' => 1],
['name' => 'virtual.companies.update', 'title' => '编辑', 'description' => 'update', 'type' => 1],
['name' => 'virtual.companies.destroy', 'title' => '删除', 'description' => 'destroy', 'type' => 1],
],
],
[
'name' => 'virtual.company.accounts.index', 'title' => '账号管理', 'path' => '/company/accounts', 'icon' => 'md-person', 'type' => 0, 'open' => 3,
'children' => [
['name' => 'virtual.company.accounts.create', 'title' => '创建', 'description' => 'create', 'type' => 1],
['name' => 'virtual.company.accounts.update', 'title' => '编辑', 'description' => 'update', 'type' => 1],
['name' => 'virtual.company.accounts.destroy', 'title' => '删除', 'description' => 'destroy', 'type' => 1],
],
],
[
'name' => 'virtual.products.index', 'title' => '定价管理', 'path' => '/products', 'icon' => 'md-pizza', 'type' => 0, 'open' => 3,
'children' => [
['name' => 'virtual.products.create', 'title' => '创建', 'description' => 'create', 'type' => 1],
['name' => 'virtual.products.update', 'title' => '编辑', 'description' => 'update', 'type' => 1],
['name' => 'virtual.products.destroy', 'title' => '删除', 'description' => 'destroy', 'type' => 1],
],
],
],
],
[
'name' => 'virtual_package_ctrl',
'title' => '套餐设置',
'path' => '#',
'icon' => 'ios-settings',
'type' => 0,
'open' => 3,
'children' => [
[
'name' => 'virtual.packages.index', 'title' => '基础套餐', 'path' => '/packages/0', 'icon' => 'ios-cube', 'type' => 0, 'open' => 3,
'children' => [
['name' => 'virtual.packages.create', 'title' => '创建', 'description' => 'create', 'type' => 1],
['name' => 'virtual.packages.update', 'title' => '编辑', 'description' => 'update', 'type' => 1],
['name' => 'virtual.packages.destroy', 'title' => '删除', 'description' => 'destroy', 'type' => 1],
],
],
],
],
[
'name' => 'virtual_card_ctrl',
'title' => '客户管理',
'path' => '#',
'icon' => 'ios-settings',
'type' => 0,
'open' => 3,
'children' => [
[
'name' => 'virtual.cards.index', 'title' => '客户列表', 'path' => '/cards', 'icon' => 'ios-cube', 'type' => 0, 'open' => 3,
'children' => [
['name' => 'virtual.cards.show', 'title' => '查看', 'description' => 'show', 'type' => 1],
],
],
],
],
[
'name' => 'virtual_order_ctrl',
'title' => '订单管理',
'path' => '#',
'icon' => 'md-infinite',
'type' => 0,
'open' => 3,
'children' => [
[
'name' => 'virtual.orders.index', 'title' => '销售订单', 'path' => '/orders/0', 'icon' => 'logo-yen', 'type' => 0, 'open' => 3,
'children' => [
['name' => 'virtual.orders.show', 'title' => '查看', 'description' => 'show', 'type' => 1],
['name' => 'virtual.orders.create', 'title' => '创建', 'description' => 'create', 'type' => 1],
['name' => 'virtual.orders.update', 'title' => '编辑', 'description' => 'update', 'type' => 1],
['name' => 'virtual.orders.destroy', 'title' => '删除', 'description' => 'destroy', 'type' => 1],
],
],
],
],
[
'name' => 'stats_ctrl',
'title' => '数据统计',
'path' => '#',
'icon' => 'md-planet',
'type' => 0,
'open' => 3,
'children' => [
[
'name' => 'stats.company-index', 'title' => '企业统计', 'path' => '/stats/company-count', 'icon' => 'md-pulse', 'type' => 0, 'open' => 3
],
],
],
[
'name' => 'export.index',
'title' => '导出记录',
'path' => '/exports',
'icon' => 'ios-download',
'type' => 0,
'open' => 3,
'children' => [
['name' => 'exports.destroy', 'title' => '删除', 'description' => 'destroy', 'type' => 1],
],
],
];
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
if (!DB::table('roles')->count()) {
app(RoleRepository::class)->create(self::ROLES);
$rootRole = app(RoleRepository::class)->where('name', '超级管理员')->first();
Account::where('username', 'root')->first()->assignRole($rootRole);
}
if (!DB::table('permissions')->count()) {
foreach (self::PERMISSIONS as $permissions) {
app(PermissionRepository::class)->create($permissions);
}
$rootRole = app(RoleRepository::class)->where('name', '超级管理员')->first();
$permissions = app(PermissionService::class)->getPermissions();
$rootRole->syncPermissions($permissions);
}
}
}