<?php<hyzwd@outlook.com>namespace app\index\controller;
use app\index\model\AuthGroup;
use app\index\model\AuthGroupAccess;
use app\index\model\AuthRule;
use think\Db;
use think\Request;
use think\Session;
use think\Url;
class Department extends Common_base
{
public function index() {
$group = Db::name('auth_group')->order('id', 'asc')->select();
foreach ($group as $kcou=>$vcou) {
$group[$kcou]['count'] = Db::name('users')->where('user_auth',$vcou['id'])->where('status',1)->count();
}
foreach ($group as $key=>$val) {
$group[$key]['son']=Db::name('users')->field(['id'=>'uid','user_name','user_nick','user_auth'])->where('user_auth',$val['id'])->where('status',1)->order('uid','asc')->select();
}
$this->assign('title', '部门管理');
$this->assign('group', $group);
return $this->fetch();
}
public function add() {
IS_ROOT([1]) ? true : $this->error('没有权限');
return $this->fetch();
}
public function add_do() {
IS_ROOT([1]) ? true : $this->error('没有权限');
$Request = Request::instance();
if ($Request->isPost()) {
$title = $Request->param('bumenname');
if (empty($title)) {
$this->error('有错误');
}
$ByTitle = Db::name('auth_group')->where('title', $title)->find();
if ($ByTitle) {
$this->error('名称已存在,请更换。');
}
$result = Db::name('auth_group')->insert(['title'=>$title]);
if ($result) {
$this->success('添加部门成功',Url::build('department/index'));
} else {
$this->error('添加部门数据错误');
}
}
}
public function check_name() {
$Request = Request::instance();
if ($Request->isPost()) {
$title = $Request->param('bumenname');
$result = Db::name('auth_group')->where('title', $title)->find();
if ($result) {
return false;
} else {
return true;
}
}
}
public function auth() {
IS_ROOT([1]) ? true : $this->error('没有权限');
$Request = Request::instance();
if (Session::get('user_auth.id') !==1) {
$this->error("无权限操作");
}
$AuthGroup = new AuthGroup();
$AuthGroupAccess = new AuthGroupAccess();
$AuthRule = new AuthRule();
if ($Request->isPost()) {
} else {
return $this->fetch();
}
}
public function auth_rule() {
IS_ROOT([1]) ? true : $this->error('没有权限');
$Request = Request::instance();
if (Session::get('user_auth.id') !==1) {
$this->error("无权限操作");
}
$AuthRule = new AuthRule();
if ($Request->isPost()) {
} else {
return $this->fetch();
}
}
}