185 lines
8.4 KiB
PHP
185 lines
8.4 KiB
PHP
<?php
|
|
|
|
namespace Database\Seeders;
|
|
|
|
use Dcat\Admin\Models\Permission;
|
|
use Illuminate\Database\Seeder;
|
|
|
|
class EndpointPermissionSeeder extends Seeder
|
|
{
|
|
/**
|
|
* Run the database seeds.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function run()
|
|
{
|
|
$permissions = [
|
|
'endpoint' => [
|
|
'name' => '系统权限',
|
|
'curd' => false,
|
|
'in_path' => true,
|
|
'children' => [
|
|
'data_dashboard' => [
|
|
'name' => '数据看板',
|
|
'curd' => false,
|
|
],
|
|
'monitor_data' => [
|
|
'name' => '监测数据管理',
|
|
'curd' => false,
|
|
'children' => [
|
|
'weather' => ['name' => '气象管理', 'curd' => ['index']],
|
|
'camera' => ['name' => '智能监控', 'curd' => ['index']],
|
|
'soil' => [
|
|
'name' => '土壤监控',
|
|
'curd' => ['index'],
|
|
'children' => [
|
|
'setting' => '设置',
|
|
'setting_edit' => '更新设置'
|
|
],
|
|
],
|
|
'water' => [
|
|
'name' => '水质监控',
|
|
'curd' => ['index'],
|
|
'children' => [
|
|
'setting' => '设置',
|
|
'setting_edit' => '更新设置',
|
|
],
|
|
],
|
|
'insect' => ['name' => '昆虫性诱监测', 'curd' => ['index']],
|
|
'worm_statics' => ['name' => '虫情监测', 'curd' => ['index']],
|
|
'insecticidal_lamp' => ['name' => '杀虫灯监测', 'curd' => ['index']],
|
|
],
|
|
],
|
|
'base_data' => [
|
|
'name' => '基础数据管理',
|
|
'curd' => false,
|
|
'children' => [
|
|
'citydata_statistics' => [
|
|
'name' => '全市基础数据',
|
|
'curd' => false,
|
|
'children'=>[
|
|
'town_street' => [
|
|
'name' => '城镇数据',
|
|
'curd' => ['index', 'edit'],
|
|
'children'=>[
|
|
'base_statistics'=>'市基础数据',
|
|
'base_statistics_edit'=>'修改市基础数据'
|
|
]
|
|
],
|
|
// 全市基础数据
|
|
'agricultural_basic' => ['name' => '基地数据', 'curd' => true],
|
|
'agricultural_base_overview' => [
|
|
'name' => '基地概况',
|
|
'curd' => ['index'],
|
|
'children' => [],
|
|
],
|
|
],
|
|
],
|
|
//农作物数据
|
|
'citydata_crops' =>['name'=>'农作物数据','curd'=>false, 'children'=>[
|
|
'town_crops' => ['name' => '城镇农作物', 'curd' => true],
|
|
'crops' => ['name' => '基地农作物', 'curd' => true],
|
|
]],
|
|
//农作物产量
|
|
'citydata_output'=>['name'=>'农作物产量','curd'=>false, 'children'=>[
|
|
'town_crops_output' => ['name' => '城镇产量', 'curd' => true],
|
|
'crops_output' => ['name' => '基地产量', 'curd' => true],
|
|
]],
|
|
// 重点产业
|
|
'industry_data' => [
|
|
'name' => '重点产业',
|
|
'curd' => false,
|
|
'children' => [
|
|
'rice_shrimp_prices' => ['name' => '稻虾价格', 'curd' => true],
|
|
'rice_shrimp_weekly_prices' => ['name' => '稻虾每周价格', 'curd' => true],
|
|
'rice_shrimp_industries' => ['name' => '稻虾产业', 'curd' => true],
|
|
'rice_shrimp_flows' => ['name' => '稻虾走向', 'curd' => true],
|
|
'materiels' => ['name' => '大宗物资', 'curd' => true],
|
|
],
|
|
],
|
|
],
|
|
],
|
|
'device_data' => [
|
|
'name' => '设备管理',
|
|
'curd' => false,
|
|
'children' => [
|
|
'device' => ['name' => '设备管理', 'curd' => true],
|
|
'warnings' => [
|
|
'name' => '警报明细',
|
|
'curd' => ['index'],
|
|
'children' => [
|
|
'mark'=>'标记',
|
|
],
|
|
],
|
|
],
|
|
],
|
|
'manage' => [
|
|
'name' => '系统管理',
|
|
'curd' => false,
|
|
'children' => [
|
|
'admin_roles' => ['name' => '角色管理', 'curd' => true],
|
|
'admin_users' => [
|
|
'name' => '账号管理',
|
|
'curd' => true,
|
|
'children' => [
|
|
'edit_password' => '修改密码', 'enable' => '启用/禁用',
|
|
]
|
|
],
|
|
'operation_log' => ['name' => '系统日志', 'curd' => ['index']],
|
|
'friend_links' => ['name' => '友情链接', 'curd' => true],
|
|
],
|
|
],
|
|
],
|
|
],
|
|
];
|
|
$this->createPermissionData($permissions);
|
|
}
|
|
|
|
/**
|
|
* 插入权限
|
|
*
|
|
* @param array $permissions
|
|
* @param string $key
|
|
* @param int $pId
|
|
*/
|
|
public function createPermissionData(array $permissions, string $key = '', int $pId = 0)
|
|
{
|
|
$curdArr = [
|
|
'index' => '列表',
|
|
'create' => '新增',
|
|
'edit' => '修改',
|
|
'destroy' => '删除',
|
|
'show' => '详情',
|
|
];
|
|
foreach ($permissions as $slug => $permission) {
|
|
//是否已存在该权限
|
|
$slugKey = ($key ? $key.'.'.$slug : $slug);
|
|
|
|
$pper = Permission::updateOrCreate(['slug' => $slugKey], ['name' => is_string($permission) ? $permission : $permission['name'], 'parent_id' => $pId]);
|
|
|
|
if (! is_string($permission)) {
|
|
if (! isset($permission['children'])) {
|
|
$permission['children'] = [];
|
|
}
|
|
//判断是否默认插入curd权限
|
|
if (isset($permission['curd']) && $permission['curd']) {
|
|
if (is_array($permission['curd'])) {
|
|
$permission['curd'] = array_reverse($permission['curd']);
|
|
foreach ($permission['curd'] as $value) {
|
|
$permission['children'] = array_merge([$value => $curdArr[$value]], $permission['children']);
|
|
}
|
|
} else {
|
|
$permission['children'] = array_merge($curdArr, $permission['children']);
|
|
}
|
|
}
|
|
|
|
if (count($permission['children']) > 0) {
|
|
$_key = ($permission['curd'] !== false || ($permission['in_path'] ?? false)) ? ($key ? $key.'.'.$slug : $slug) : $key;
|
|
$this->createPermissionData($permission['children'], $_key ?? $slug, $pper->id);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|