修改文件、类型显示
This commit is contained in:
1 parent
6f5ffeb8d7
commit
7e9310e4dd
254 files changed
+5412
-4872
No files matched your search
@@ -11,67 +11,106 @@ class AuthRule extends BaseModel
|
||||
// 父级菜单数据模型关联
|
||||
public function authPid()
|
||||
{
|
||||
return $this->belongsTo('AuthRule','pid','id');
|
||||
return $this->belongsTo('AuthRule', 'pid', 'id');
|
||||
}
|
||||
|
||||
|
||||
// 子菜单数据模型关联
|
||||
public function authCid()
|
||||
{
|
||||
return $this->hasMany('AuthRule','pid','id');
|
||||
return $this->hasMany('AuthRule', 'pid', 'id');
|
||||
}
|
||||
|
||||
|
||||
// 查询所有角色
|
||||
public function search($src)
|
||||
public function search($srcfrom)
|
||||
{
|
||||
// 整理变量
|
||||
$searchval = $src['searchval'];
|
||||
$src = [
|
||||
'searchval' => ''
|
||||
,'status' => ''
|
||||
];
|
||||
$src = array_cover($srcfrom, $src);
|
||||
|
||||
// 查询数据
|
||||
$data = $this
|
||||
->order([$src['field'] =>$src['order']])
|
||||
->when(strlen($searchval)>0,function($query) use($searchval){
|
||||
$query->where('title|name','like','%'.$searchval.'%');
|
||||
->when(strlen($src['searchval']) > 0, function($query) use($src){
|
||||
$query->where('title|name', 'like', '%' . $src['searchval'] . '%');
|
||||
})
|
||||
->with(['authPid'=>function($query){
|
||||
$query->field('id,title');
|
||||
}])
|
||||
->when(strlen($src['status']) > 0, function($query) use($src){
|
||||
$query->where('status', $src['status']);
|
||||
})
|
||||
->with([
|
||||
'authPid' => function($query){
|
||||
$query->field('id, title');
|
||||
}
|
||||
])
|
||||
->field('id, name, title, condition, paixu, ismenu, url, pid, type, status')
|
||||
->select();
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
// 查询状态正常的类别
|
||||
public function srcStatus()
|
||||
// 查询菜单
|
||||
public function menu($user_id)
|
||||
{
|
||||
$data = $this->where('status',1)
|
||||
->order(['paixu'=>'desc'])
|
||||
->field('id,name,title,condition,paixu,ismenu,url,pid,type')
|
||||
->select()
|
||||
->toArray();
|
||||
if($user_id == 1 || $user_id ==2)
|
||||
{
|
||||
$auth = array();
|
||||
}else{
|
||||
$admin = new \app\admin\model\Admin;
|
||||
$auth = $admin->srcAuth($user_id);
|
||||
}
|
||||
|
||||
$data = self::where('pid', 0)
|
||||
->where('status&ismenu', 1)
|
||||
->when(count($auth) > 0, function($query) use($auth){
|
||||
$query->where('id', 'in', $auth);
|
||||
})
|
||||
->field('id, title, font')
|
||||
->with([
|
||||
'authCid' => function($query){
|
||||
$query->order(['paixu'])
|
||||
->field('id, pid, title, url');
|
||||
}
|
||||
])
|
||||
->order(['paixu'])
|
||||
->select();
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
// 递归权限类别
|
||||
public function digui($arrAll=array(),$arrSelected=array(),$pid=0)
|
||||
public function digui($arrAll = array(), $arrSelected = array(), $pid = 0)
|
||||
{
|
||||
// 声明子权限
|
||||
$child = array();
|
||||
count($arrSelected) == 0 ? $e = false : $e = true;
|
||||
// 循环所有权限
|
||||
foreach ($arrAll as $key => $value) {
|
||||
# 获取当前子权限
|
||||
if($value['pid'] == $pid)
|
||||
{
|
||||
# 判断当前权限是否被选中
|
||||
// array_search($value['id'], $arrSelected) == '' ? $value['select'] = false : $value['select'] = true;
|
||||
$value['select'] = in_array($value['id'],$arrSelected);
|
||||
// dump($value['id']);
|
||||
// halt($a);
|
||||
if($e == true)
|
||||
{
|
||||
$selk = array_search($value['id'], $arrSelected);
|
||||
if(false === $selk)
|
||||
{
|
||||
$value['select'] = false;
|
||||
} else {
|
||||
$value['select'] = true;
|
||||
unset($arrSelected[$selk]);
|
||||
}
|
||||
}else{
|
||||
$value['select'] = false;
|
||||
}
|
||||
|
||||
$child[$value['id']] = $value;
|
||||
unset($arrAll[$key]);
|
||||
$child[$value['id']]['child'] = $this->digui($arrAll,$arrSelected,$value['id']);
|
||||
$child[$value['id']]['child'] = $this->digui($arrAll, $arrSelected, $value['id']);
|
||||
}
|
||||
}
|
||||
return $child;
|
||||
|
||||
Reference in new issue
Block a user