"用户管理","url"=>"/","pid"=>0,"created_at"=>date('Y-m-d H:i:s',time()),"updated_at"=>date('Y-m-d H:i:s',time())], ["name"=>"MetaMask","url"=>"/","pid"=>0,"created_at"=>date('Y-m-d H:i:s',time()),"updated_at"=>date('Y-m-d H:i:s',time())], ["name"=>"CEBG","url"=>"/","pid"=>0,"created_at"=>date('Y-m-d H:i:s',time()),"updated_at"=>date('Y-m-d H:i:s',time())] ]; $res1 = MenuModel::insert($menuList); if ($res1){ $menu = MenuModel::where('pid',0)->get(); foreach ($menu as $val){ $_dataMenu = $this->getMenuChildren($val->id,$val->name); $_res1 = MenuModel::insert($_dataMenu); if (! $_res1){ Log::error($val->name.'------二级菜单插入失败'); return ; } Log::info($val->name.'------菜单插入成功'); } }else{ Log::error('顶级菜单插入失败'); return ; } //初始化权限表的数据 Node::truncate(); $nodeList = [ ["name"=>"用户管理","controller"=>"*","action"=>"*","route_uri"=>"*","pid"=>0,"created_at"=>date('Y-m-d H:i:s',time()),"updated_at"=>date('Y-m-d H:i:s',time())], ["name"=>"MetaMask","controller"=>"*","action"=>"*","route_uri"=>"*","pid"=>0,"created_at"=>date('Y-m-d H:i:s',time()),"updated_at"=>date('Y-m-d H:i:s',time())], ["name"=>"CEBG","controller"=>"*","action"=>"*","route_uri"=>"*","pid"=>0,"created_at"=>date('Y-m-d H:i:s',time()),"updated_at"=>date('Y-m-d H:i:s',time())] ]; $res2 = Node::insert($nodeList); if ($res2){ $node = Node::where('pid',0)->get(); foreach ($node as $val){ $_dataNode = $this->getNodeChildren($val->id,$val->name); $_res2 = Node::insert($_dataNode); if (! $_res2){ Log::error($val->name.'------二级权限插入失败'); return ; } Log::info($val->name.'------权限插入成功'); } }else{ Log::error('顶级权限插入失败'); return ; } //初始化超级管理员 $nodeGroupList = ["name"=>"超级管理员","node_ids"=>"all","created_at"=>date('Y-m-d H:i:s',time()),"updated_at"=>date('Y-m-d H:i:s',time())]; $admin = ["nickname"=>env('ADMIN_NICKNAME'),"account"=>env('ADMIN_ACCOUNT'),"created_at"=>date('Y-m-d H:i:s',time()),"updated_at"=>date('Y-m-d H:i:s',time())]; NodeGroup::truncate(); $res3 = NodeGroup::insert($nodeGroupList); $res4 = User::insert($admin); if ($res3 && $res4){ $node_group_id = NodeGroup::where('name','超级管理员')->value('id'); $user_id = User::where('account',env('ADMIN_ACCOUNT'))->value('id'); UserNodeLine::insert(['user_id'=>$user_id,'node_group_id'=>$node_group_id]); Log::info('初始化超级管理员成功'); }else{ Log::error('初始化超级管理员失败'); return ; } } private function getMenuChildren($id,$name){ $menu = []; switch ($name){ case '用户管理' : $menu = [ ["name"=>"用户","url"=>"/user","pid"=>$id,"created_at"=>date('Y-m-d H:i:s',time()),"updated_at"=>date('Y-m-d H:i:s',time())], ["name"=>"权限","url"=>"/node","pid"=>$id,"created_at"=>date('Y-m-d H:i:s',time()),"updated_at"=>date('Y-m-d H:i:s',time())], ["name"=>"权限组","url"=>"/node-group","pid"=>$id,"created_at"=>date('Y-m-d H:i:s',time()),"updated_at"=>date('Y-m-d H:i:s',time())], ["name"=>"菜单","url"=>"/menu","pid"=>$id,"created_at"=>date('Y-m-d H:i:s',time()),"updated_at"=>date('Y-m-d H:i:s',time())], ]; break; case 'MetaMask' : $menu = [ ["name"=>"nft","url"=>"/nft","pid"=>$id,"created_at"=>date('Y-m-d H:i:s',time()),"updated_at"=>date('Y-m-d H:i:s',time())], ["name"=>"mint","url"=>"/mint","pid"=>$id,"created_at"=>date('Y-m-d H:i:s',time()),"updated_at"=>date('Y-m-d H:i:s',time())], ]; break; case 'CEBG' : $menu = [ ["name"=>"申请","url"=>"/apply","pid"=>$id,"created_at"=>date('Y-m-d H:i:s',time()),"updated_at"=>date('Y-m-d H:i:s',time())], ["name"=>"初审","url"=>"/audit","pid"=>$id,"created_at"=>date('Y-m-d H:i:s',time()),"updated_at"=>date('Y-m-d H:i:s',time())], ["name"=>"终审","url"=>"/final-audit","pid"=>$id,"created_at"=>date('Y-m-d H:i:s',time()),"updated_at"=>date('Y-m-d H:i:s',time())], ["name"=>"执行","url"=>"/execute","pid"=>$id,"created_at"=>date('Y-m-d H:i:s',time()),"updated_at"=>date('Y-m-d H:i:s',time())], ]; break; } return $menu; } private function getNodeChildren($id,$name){ $node = []; switch ($name){ case 'MetaMask' : $node = [ ["name"=>"nft列表","controller"=>"NftController","action"=>"index","pid"=>$id,"created_at"=>date('Y-m-d H:i:s',time()),"updated_at"=>date('Y-m-d H:i:s',time())], ["name"=>"nft详情","controller"=>"NftController","action"=>"show","pid"=>$id,"created_at"=>date('Y-m-d H:i:s',time()),"updated_at"=>date('Y-m-d H:i:s',time())], ["name"=>"mint列表","controller"=>"MintController","action"=>"index","pid"=>$id,"created_at"=>date('Y-m-d H:i:s',time()),"updated_at"=>date('Y-m-d H:i:s',time())], ["name"=>"导出excel","controller"=>"IndexController","action"=>"exports","pid"=>$id,"created_at"=>date('Y-m-d H:i:s',time()),"updated_at"=>date('Y-m-d H:i:s',time())], ]; break; case 'CEBG' : $node = [ ["name"=>"申请列表","controller"=>"ApplyController","action"=>"index","pid"=>$id,"created_at"=>date('Y-m-d H:i:s',time()),"updated_at"=>date('Y-m-d H:i:s',time())], ["name"=>"查看申请","controller"=>"ApplyController","action"=>"show","pid"=>$id,"created_at"=>date('Y-m-d H:i:s',time()),"updated_at"=>date('Y-m-d H:i:s',time())], ["name"=>"提交申请","controller"=>"ApplyController","action"=>"create","pid"=>$id,"created_at"=>date('Y-m-d H:i:s',time()),"updated_at"=>date('Y-m-d H:i:s',time())], ["name"=>"撤销申请","controller"=>"ApplyController","action"=>"destroy","pid"=>$id,"created_at"=>date('Y-m-d H:i:s',time()),"updated_at"=>date('Y-m-d H:i:s',time())], ["name"=>"通过初审","controller"=>"ApplyController","action"=>"pass","pid"=>$id,"created_at"=>date('Y-m-d H:i:s',time()),"updated_at"=>date('Y-m-d H:i:s',time())], ["name"=>"不通过初审","controller"=>"ApplyController","action"=>"noPass","pid"=>$id,"created_at"=>date('Y-m-d H:i:s',time()),"updated_at"=>date('Y-m-d H:i:s',time())], ["name"=>"通过终审","controller"=>"ApplyController","action"=>"passFinal","pid"=>$id,"created_at"=>date('Y-m-d H:i:s',time()),"updated_at"=>date('Y-m-d H:i:s',time())], ["name"=>"不通过终审","controller"=>"ApplyController","action"=>"noPassFinal","pid"=>$id,"created_at"=>date('Y-m-d H:i:s',time()),"updated_at"=>date('Y-m-d H:i:s',time())], ["name"=>"执行申请","controller"=>"ApplyController","action"=>"execute","pid"=>$id,"created_at"=>date('Y-m-d H:i:s',time()),"updated_at"=>date('Y-m-d H:i:s',time())], ["name"=>"驳回申请","controller"=>"ApplyController","action"=>"reject","pid"=>$id,"created_at"=>date('Y-m-d H:i:s',time()),"updated_at"=>date('Y-m-d H:i:s',time())], ]; break; case '用户管理' : $node = [ ["name"=>"用户列表","controller"=>"UserController","action"=>"index","pid"=>$id,"created_at"=>date('Y-m-d H:i:s',time()),"updated_at"=>date('Y-m-d H:i:s',time())], ["name"=>"用户所属权限组","controller"=>"UserController","action"=>"show","pid"=>$id,"created_at"=>date('Y-m-d H:i:s',time()),"updated_at"=>date('Y-m-d H:i:s',time())], ["name"=>"用户所拥有菜单","controller"=>"UserController","action"=>"showMenu","pid"=>$id,"created_at"=>date('Y-m-d H:i:s',time()),"updated_at"=>date('Y-m-d H:i:s',time())], ["name"=>"用户配权限组","controller"=>"UserController","action"=>"allotNodeGroup","pid"=>$id,"created_at"=>date('Y-m-d H:i:s',time()),"updated_at"=>date('Y-m-d H:i:s',time())], ["name"=>"用户配菜单","controller"=>"UserController","action"=>"allotMenu","pid"=>$id,"created_at"=>date('Y-m-d H:i:s',time()),"updated_at"=>date('Y-m-d H:i:s',time())], ["name"=>"修改邮箱","controller"=>"UserController","action"=>"updateEmail","pid"=>$id,"created_at"=>date('Y-m-d H:i:s',time()),"updated_at"=>date('Y-m-d H:i:s',time())], ["name"=>"权限列表","controller"=>"NodeController","action"=>"index","pid"=>$id,"created_at"=>date('Y-m-d H:i:s',time()),"updated_at"=>date('Y-m-d H:i:s',time())], ["name"=>"添加权限","controller"=>"NodeController","action"=>"store","pid"=>$id,"created_at"=>date('Y-m-d H:i:s',time()),"updated_at"=>date('Y-m-d H:i:s',time())], ["name"=>"修改权限","controller"=>"NodeController","action"=>"update","pid"=>$id,"created_at"=>date('Y-m-d H:i:s',time()),"updated_at"=>date('Y-m-d H:i:s',time())], ["name"=>"删除权限","controller"=>"NodeController","action"=>"destroy","pid"=>$id,"created_at"=>date('Y-m-d H:i:s',time()),"updated_at"=>date('Y-m-d H:i:s',time())], ["name"=>"权限组列表","controller"=>"NodeGroupController","action"=>"index","pid"=>$id,"created_at"=>date('Y-m-d H:i:s',time()),"updated_at"=>date('Y-m-d H:i:s',time())], ["name"=>"添加权限组","controller"=>"NodeGroupController","action"=>"store","pid"=>$id,"created_at"=>date('Y-m-d H:i:s',time()),"updated_at"=>date('Y-m-d H:i:s',time())], ["name"=>"该组所拥有权限","controller"=>"NodeGroupController","action"=>"show","pid"=>$id,"created_at"=>date('Y-m-d H:i:s',time()),"updated_at"=>date('Y-m-d H:i:s',time())], ["name"=>"删除权限组","controller"=>"NodeGroupController","action"=>"destroy","pid"=>$id,"created_at"=>date('Y-m-d H:i:s',time()),"updated_at"=>date('Y-m-d H:i:s',time())], ["name"=>"给权限组配权","controller"=>"NodeGroupController","action"=>"allotNode","pid"=>$id,"created_at"=>date('Y-m-d H:i:s',time()),"updated_at"=>date('Y-m-d H:i:s',time())], ["name"=>"菜单列表","controller"=>"MenuController","action"=>"index","pid"=>$id,"created_at"=>date('Y-m-d H:i:s',time()),"updated_at"=>date('Y-m-d H:i:s',time())], ["name"=>"添加菜单","controller"=>"MenuController","action"=>"store","pid"=>$id,"created_at"=>date('Y-m-d H:i:s',time()),"updated_at"=>date('Y-m-d H:i:s',time())], ["name"=>"修改菜单","controller"=>"MenuController","action"=>"update","pid"=>$id,"created_at"=>date('Y-m-d H:i:s',time()),"updated_at"=>date('Y-m-d H:i:s',time())], ["name"=>"删除菜单","controller"=>"MenuController","action"=>"destroy","pid"=>$id,"created_at"=>date('Y-m-d H:i:s',time()),"updated_at"=>date('Y-m-d H:i:s',time())], ];break; } foreach ($node as &$item) { $item['route_uri'] = strtolower($item['controller']).'/'.strtolower($item['action']); } return $node; } }