更新
This commit is contained in:
82
app/services/auth/MenuService.php
Normal file
82
app/services/auth/MenuService.php
Normal file
@@ -0,0 +1,82 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\services\auth;
|
||||
|
||||
use app\model\auth\Permissions;
|
||||
use sent\tree\Tree;
|
||||
use think\facade\Env;
|
||||
|
||||
class MenuService{
|
||||
|
||||
/**
|
||||
* @title 获取菜单
|
||||
*
|
||||
* @param boolean $is_tree
|
||||
* @return void
|
||||
*/
|
||||
public function getSystemMenu($is_menu = true, $is_tree = true){
|
||||
$rootid = Env::get('admin_root');
|
||||
$order = "sort asc, id desc";
|
||||
$map = [];
|
||||
if(request()->user['uid'] == $rootid){
|
||||
$map[] = ['name', 'IN', request()->auth()['permission']];
|
||||
}
|
||||
if($is_menu){
|
||||
$map[] = ['type', '=', 'menu'];
|
||||
$map[] = ['hidden', '=', 0];
|
||||
}
|
||||
$list = Permissions::where($map)->order($order)->append(['meta'])->select()
|
||||
->each(function($item){
|
||||
$item->hidden = (int) $item['hidden'];
|
||||
$item->hiddenBreadcrumb = (int) $item['hiddenBreadcrumb'];
|
||||
})->toArray();
|
||||
if($is_tree){
|
||||
$menu = (new Tree())->listToTree($list, 'id', 'parent_id', 'children');
|
||||
|
||||
return $menu;
|
||||
}else{
|
||||
return $list;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @title 创建数据
|
||||
*
|
||||
* @param [type] $data
|
||||
* @return void
|
||||
*/
|
||||
public function createData($data){
|
||||
return Permissions::create($data);
|
||||
}
|
||||
/**
|
||||
* @title 保存数据
|
||||
*
|
||||
* @param [type] $data
|
||||
* @return void
|
||||
*/
|
||||
public function saveData($data){
|
||||
$menu = Permissions::where('id', $data['id'])->findOrEmpty();
|
||||
//移除时间,时间自动系统
|
||||
unset($data['create_time']);
|
||||
unset($data['update_time']);
|
||||
if(!$menu->isEmpty()){
|
||||
return $menu->save($data);
|
||||
}else{
|
||||
throw new \think\Exception("未找到数据!", 0);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @title 删除菜单
|
||||
*
|
||||
* @param [type] $data
|
||||
* @return void
|
||||
*/
|
||||
public function deleteMenu($data){
|
||||
return Permissions::destroy($data);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user