vd/database/seeds/PermissionSeeder.php
2019-04-15 17:13:33 +08:00

328 lines
19 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_package_ctrl',
'title' => '套餐设置',
'path' => '#',
'icon' => 'md-pie',
'type' => 0,
'open' => 3,
'children' => [
[
'name' => 'virtual.packages.0.index', 'title' => '基础套餐', 'path' => '/packages/0', 'icon' => 'md-card', 'type' => 0, 'open' => 3,
'children' => [
['name' => 'virtual.packages.0.create', 'title' => '创建', 'description' => 'create', 'type' => 1],
['name' => 'virtual.packages.0.update', 'title' => '编辑', 'description' => 'update', 'type' => 1],
['name' => 'virtual.packages.0.destroy', 'title' => '删除', 'description' => 'destroy', 'type' => 1],
],
],
[
'name' => 'virtual.packages.2.index', 'title' => '续费包套餐', 'path' => '/packages/2', 'icon' => 'md-bonfire', 'type' => 0, 'open' => 3,
'children' => [
['name' => 'virtual.packages.2.create', 'title' => '创建', 'description' => 'create', 'type' => 1],
['name' => 'virtual.packages.2.update', 'title' => '编辑', 'description' => 'update', 'type' => 1],
['name' => 'virtual.packages.2.destroy', 'title' => '删除', 'description' => 'destroy', 'type' => 1],
],
],
[
'name' => 'virtual.packages.3.index', 'title' => '加油包套餐', 'path' => '/packages/3', 'icon' => 'md-color-fill', 'type' => 0, 'open' => 3,
'children' => [
['name' => 'virtual.packages.3.create', 'title' => '创建', 'description' => 'create', 'type' => 1],
['name' => 'virtual.packages.3.update', 'title' => '编辑', 'description' => 'update', 'type' => 1],
['name' => 'virtual.packages.3.destroy', 'title' => '删除', 'description' => 'destroy', 'type' => 1],
],
],
],
],
[
'name' => 'virtual_product_ctrl',
'title' => '定价管理',
'path' => '#',
'icon' => 'ios-pizza',
'type' => 0,
'open' => 3,
'children' => [
[
'name' => 'virtual.products.0.index', 'title' => '基础定价', 'path' => '/products/0', 'icon' => 'md-card', 'type' => 0, 'open' => 3,
'children' => [
['name' => 'virtual.products.0.create', 'title' => '创建', 'description' => 'create', 'type' => 1],
['name' => 'virtual.products.0.update', 'title' => '编辑', 'description' => 'update', 'type' => 1],
['name' => 'virtual.products.0.destroy', 'title' => '删除', 'description' => 'destroy', 'type' => 1],
],
],
[
'name' => 'virtual.products.2.index', 'title' => '续费包定价', 'path' => '/products/2', 'icon' => 'md-bonfire', 'type' => 0, 'open' => 3,
'children' => [
['name' => 'virtual.products.2.create', 'title' => '创建', 'description' => 'create', 'type' => 1],
['name' => 'virtual.products.2.update', 'title' => '编辑', 'description' => 'update', 'type' => 1],
['name' => 'virtual.products.2.destroy', 'title' => '删除', 'description' => 'destroy', 'type' => 1],
],
],
[
'name' => 'virtual.products.3.index', 'title' => '加油包定价', 'path' => '/products/3', 'icon' => 'md-color-fill', 'type' => 0, 'open' => 3,
'children' => [
['name' => 'virtual.products.3.create', 'title' => '创建', 'description' => 'create', 'type' => 1],
['name' => 'virtual.products.3.update', 'title' => '编辑', 'description' => 'update', 'type' => 1],
['name' => 'virtual.products.3.destroy', 'title' => '删除', 'description' => 'destroy', 'type' => 1],
],
],
[
'name' => 'virtual.properties.index', 'title' => '属性管理', 'path' => '/properties', 'icon' => 'md-cube', 'type' => 0, 'open' => 3,
'children' => [
['name' => 'virtual.properties.create', 'title' => '设置', 'description' => 'create', 'type' => 1],
['name' => 'virtual.properties.update', 'title' => '修改', 'description' => 'update', 'type' => 1],
['name' => 'virtual.properties.export', 'title' => '导出', 'description' => 'output', 'type' => 1],
['name' => 'virtual.properties.import', 'title' => '导入', 'description' => 'input', '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.0.index', 'title' => '销售订单', 'path' => '/orders/0', 'icon' => 'md-card', 'type' => 0, 'open' => 3,
'children' => [
['name' => 'virtual.orders.0.show', 'title' => '查看', 'description' => 'show', 'type' => 1],
['name' => 'virtual.orders.0.create', 'title' => '创建', 'description' => 'create', 'type' => 1],
['name' => 'virtual.orders.0.update', 'title' => '编辑', 'description' => 'update', 'type' => 1],
['name' => 'virtual.orders.0.destroy', 'title' => '删除', 'description' => 'destroy', 'type' => 1],
['name' => 'virtual.orders.0.output', 'title' => '导出', 'description' => 'output', 'type' => 1],
['name' => 'virtual.orders.0.locked', 'title' => '解锁', 'description' => 'locked', 'type' => 1],
],
],
[
'name' => 'virtual.orders.1.index', 'title' => '续费订单', 'path' => '/orders/1', 'icon' => 'md-medal', 'type' => 0, 'open' => 3,
'children' => [
['name' => 'virtual.orders.1.show', 'title' => '查看', 'description' => 'show', 'type' => 1],
['name' => 'virtual.orders.1.create', 'title' => '创建', 'description' => 'create', 'type' => 1],
['name' => 'virtual.orders.1.update', 'title' => '编辑', 'description' => 'update', 'type' => 1],
['name' => 'virtual.orders.1.destroy', 'title' => '删除', 'description' => 'destroy', 'type' => 1],
['name' => 'virtual.orders.1.output', 'title' => '导出', 'description' => 'output', 'type' => 1],
['name' => 'virtual.orders.1.locked', 'title' => '解锁', 'description' => 'locked', 'type' => 1],
],
],
[
'name' => 'virtual.orders.2.index', 'title' => '续费包订单', 'path' => '/orders/2', 'icon' => 'md-bonfire', 'type' => 0, 'open' => 3,
'children' => [
['name' => 'virtual.orders.2.show', 'title' => '查看', 'description' => 'show', 'type' => 1],
['name' => 'virtual.orders.2.create', 'title' => '创建', 'description' => 'create', 'type' => 1],
['name' => 'virtual.orders.2.update', 'title' => '编辑', 'description' => 'update', 'type' => 1],
['name' => 'virtual.orders.2.destroy', 'title' => '删除', 'description' => 'destroy', 'type' => 1],
['name' => 'virtual.orders.2.output', 'title' => '导出', 'description' => 'output', 'type' => 1],
['name' => 'virtual.orders.2.locked', 'title' => '解锁', 'description' => 'locked', 'type' => 1],
],
],
[
'name' => 'virtual.orders.3.index', 'title' => '加油包订单', 'path' => '/orders/3', 'icon' => 'md-color-fill', 'type' => 0, 'open' => 3,
'children' => [
['name' => 'virtual.orders.3.show', 'title' => '查看', 'description' => 'show', 'type' => 1],
['name' => 'virtual.orders.3.create', 'title' => '创建', 'description' => 'create', 'type' => 1],
['name' => 'virtual.orders.3.update', 'title' => '编辑', 'description' => 'update', 'type' => 1],
['name' => 'virtual.orders.3.destroy', 'title' => '删除', 'description' => 'destroy', 'type' => 1],
['name' => 'virtual.orders.3.output', 'title' => '导出', 'description' => 'output', 'type' => 1],
['name' => 'virtual.orders.3.locked', 'title' => '解锁', 'description' => 'locked', 'type' => 1],
],
],
],
],
[
'name' => 'virtual_flow_pool_ctrl',
'title' => '流量池',
'path' => '#',
'icon' => 'md-wifi',
'type' => 0,
'open' => 3,
'children' => [
[
'name' => 'virtual.flow-pools.index', 'title' => '流量池管理', 'path' => '/flow-pools', 'icon' => 'md-swap', 'type' => 0, 'open' => 3,
'children' => [
['name' => 'virtual.flow-pools.show', 'title' => '查看', 'description' => 'show', 'type' => 1],
['name' => 'virtual.flow-pools.create', 'title' => '创建', 'description' => 'create', 'type' => 1],
['name' => 'virtual.flow-pools.update', 'title' => '编辑', 'description' => 'update', 'type' => 1],
['name' => 'virtual.flow-pools.destroy', 'title' => '删除', 'description' => 'destroy', 'type' => 1],
['name' => 'virtual.flow-pools.import', 'title' => '导入', 'description' => 'input', 'type' => 1],
['name' => 'virtual.flow-pools.export', 'title' => '导出', 'description' => 'output', '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-git-merge', 'type' => 0, 'open' => 3],
['name' => 'stats.order.0', 'title' => '销售订单统计', 'path' => '/stats/order/0', 'icon' => 'md-card', 'type' => 0, 'open' => 3],
['name' => 'stats.order.1', 'title' => '续费订单统计', 'path' => '/stats/order/1', 'icon' => 'md-medal', 'type' => 0, 'open' => 3],
['name' => 'stats.order.2', 'title' => '续费包订单统计', 'path' => '/stats/order/2', 'icon' => 'md-bonfire', 'type' => 0, 'open' => 3],
['name' => 'stats.order.3', 'title' => '加油包订单统计', 'path' => '/stats/order/3', 'icon' => 'md-color-fill', 'type' => 0, 'open' => 3],
['name' => 'stats.company-report.1', 'title' => '用户月报表', 'path' => '/stats/company-report/1', 'icon' => 'ios-contacts', 'type' => 0, 'open' => 3],
['name' => 'stats.company-report.2', 'title' => '增值包月报表', 'path' => '/stats/company-report/2', 'icon' => 'md-bonfire', 'type' => 0, 'open' => 3],
['name' => 'stats.sold-activated', 'title' => '销售激活统计', 'path' => '/stats/sold-activated', 'icon' => 'md-timer', 'type' => 0, 'open' => 3],
[
'name' => 'stats.flow-pools', 'title' => '流量池统计', 'path' => '/flow-pools', 'icon' => 'md-swap', 'type' => 0, 'open' => 3,
'children' => [
['name' => 'stats.flow-pools.show', 'title' => '明细', 'description' => 'show', 'type' => 1],
]
],
],
],
[
'name' => 'export.index',
'title' => '导出记录',
'path' => '/exports',
'icon' => 'ios-download',
'type' => 0,
'open' => 3,
'children' => [
['name' => 'exports.destroy', 'title' => '删除', 'description' => 'destroy', 'type' => 1],
],
],
[
'name' => 'artisan_ctrl',
'title' => '任务管理',
'path' => '#',
'icon' => 'ios-locate',
'type' => 0,
'open' => 3,
'children' => [
['name' => 'artisan.real-sync', 'title' => 'RD数据同步', 'path' => '/artisan/real-sync', 'icon' => 'ios-color-filter', 'type' => 0, 'open' => 3],
],
],
];
/**
* 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);
}
DB::table('permissions')->truncate();
DB::table('role_has_permissions')->truncate();
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);
}
}