You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
83 lines
1.9 KiB
PHP
83 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace app\admin\controller;
|
|
use app\admin\model\AuthRule as AuthRuleModel;
|
|
use app\admin\controller\Common;
|
|
class AuthRule extends Common
|
|
{
|
|
public function lst(){
|
|
$authRule=new AuthRuleModel();
|
|
if(request()->isPost()){
|
|
$sorts=input('post.');
|
|
foreach ($sorts as $k =>$v) {
|
|
$authRule->update(['id'=>$k,'sort'=>$v]);
|
|
}
|
|
$this->success('更新排序成功!',url('lst'));
|
|
return;
|
|
}
|
|
$authRuleRes=$authRule->authRuleTree();
|
|
$this->assign('authRuleRes',$authRuleRes);
|
|
return view();
|
|
}
|
|
public function add(){
|
|
if(request()->isPost()){
|
|
$data=input('post.');
|
|
$plevel=db('auth_rule')->where('id',$data['pid'])->field('level')->find();
|
|
if($plevel){
|
|
$data['level']=$plevel['level']+1;
|
|
}else{
|
|
$data['level']=0;
|
|
}
|
|
$add=db('auth_rule')->insert($data);
|
|
if($add){
|
|
$this->success('添加权限成功!',url('lst'));
|
|
}else{
|
|
$this->error('添加权限失败!');
|
|
}
|
|
return;
|
|
}
|
|
$authRule=new AuthRuleModel();
|
|
$authRuleRes=$authRule->authRuleTree();
|
|
$this->assign('authRuleRes',$authRuleRes);
|
|
return view();
|
|
}
|
|
public function edit(){
|
|
if(request()->isPost()){
|
|
$data=input('post.');
|
|
$plevel=db('auth_rule')->where('id',$data['pid'])->field('level')->find();
|
|
if($plevel){
|
|
$data['level']=$plevel['level']+1;
|
|
}else{
|
|
$data['level']=0;
|
|
}
|
|
$save=db('auth_rule')->update($data);
|
|
if($save!==false){
|
|
$this->success('修改权限成功!',url('lst'));
|
|
}else{
|
|
$this->error('修改权限失败!');
|
|
}
|
|
return;
|
|
}
|
|
$authRule=new AuthRuleModel();
|
|
$authRuleRes=$authRule->authRuleTree();
|
|
$authRules=$authRule->find(input('id'));
|
|
$this->assign(array(
|
|
'authRuleRes'=>$authRuleRes,
|
|
'authRules'=>$authRules,
|
|
));
|
|
return view();
|
|
}
|
|
public function del(){
|
|
$authRule=new AuthRuleModel();
|
|
$authRule->getparentid(input('id'));
|
|
$authRuleIds=$authRule->getchilrenid(input('id'));
|
|
$authRuleIds[]=input('id');
|
|
$del= AuthRuleModel::destroy($authRuleIds);
|
|
if($del){
|
|
$this->success('删除权限成功!',url('lst'));
|
|
}else{
|
|
$this->error('删除权限失败!');
|
|
}
|
|
}
|
|
}
|
|
?>
|