TaoLer/app/admin/controller/AuthGroup.php
2020-01-01 13:17:19 +08:00

108 lines
2.1 KiB
PHP

<?php
namespace app\admin\controller;
use app\common\controller\AdminController;
use app\admin\validate\Admin;
use app\admin\model\Admin as adminModel;
use think\facade\View;
use think\facade\Request;
use think\facade\Db;
use think\exception\ValidateException;
use app\admin\model\AuthGroup as AuthGroupModel;
use app\admin\model\AuthRule as AuthRuleModel;
class AuthGroup extends AdminController
{
/**
protected function initialize()
{
parent::initialize();
}
*/
//角色
public function list()
{
if(Request::isAjax()){
$role = Db::name('auth_group')->select();
$count = $role->count();
$res = [];
if($role){
$res = ['code'=>0,'msg'=>'','count'=>$count];
foreach($role as $k => $v){
$data = ['id'=>$v['id'],'rolename'=>$v['title'],'limits'=>$v['limits'],'descr'=>$v['descr'],'check'=>$v['status']];
$res['data'][] = $data;
}
}
return json($res);
}
return View::fetch('role');
}
//角色管理
public function role()
{
//
return View::fetch('role');
}
//角色添加
public function roleAdd()
{
if(Request::isAjax()){
$data = Request::param();
$result = AuthGroupModel::create($data);
if($result) {
$res = ['code'=>1,'msg'=>'添加成功'];
} else {
$res = ['code'=>0,'msg'=>'添加失败'];
}
return json($res);
}
$menus = $this->getMenus();
View::assign('menus',$menus);
return View::fetch('roleadd');
}
//角色编辑
public function roleEdit()
{
if(Request::isAjax()){
$data = Request::param();
/*
if(!strpos($data['rules'],'1,2,3,4,5'))
{
$data['rules'] = substr_replace($data['rules'],"1,2,3,4,5,",0,0);
}
*/
$rule = AuthGroupModel::update($data);
if($rule){
$res = ['code'=>1,'msg'=>'保存成功'];
} else {
$res = ['code'=>1,'msg'=>'保存成功'];
}
return json($res);
}
$menus = $this->getMenus();
View::assign('menus',$menus);
$authGroup = AuthGroupModel::select();
$auth = AuthGroupModel::find(input('id'));
$ru = $auth->rules;
View::assign(['authGroup'=>$authGroup,'auth'=>$auth,'ru'=>$ru]);
return View::fetch('roleedit');
}
}