namespace app\admin\controller;
use think\Controller;
use think\uploads;
use think\Session;
use app\index\model\Loginmodel;
use think\Model;
use think\Request;
use think\Db;
class Power extends Common
{
//管理员列表
public function adminlist()
{
$data = Db::query("select * from h_user inner join h_u_r on h_user.user_id = h_u_r.user_id inner join h_role on h_u_r.role_id = h_role.role_id");
return view("adminlist",["data"=>$data]);
}
//管理添加
public function adminadd()
{
$data = Db::query("select * from h_role");
return view("adminadd",["data"=>$data]);
}
//管理编辑
public function adminedit()
{
return view("adminedit");
}
//角色管理
public function adminrole()
{
$data = Db::query("select * from h_role ");
return view("adminrole",["data"=>$data]);
}
//权限分类
public function admincate()
{
return view("admincate");
}
//权限管理
public function adminrule()
{
$data = Db::query("select * from h_power");
$data = $this->recursive($data);
return view("adminrule",["data"=>$data]);
}
//权限添加
public function addPower()
{
$data = input();
$url = $data["controller"]."/".$data["action"];
$res = Db::execute("insert into h_power values(null,'".$data["cate_name"]."','".$url."','".$data["cateid"]."','".$data["cate_desc"]."','".$data["cate_id"]."')");
if ( $res )
{
echo "";
$this->redirect("Power/adminrule");
} else {
$this->redirect("Power/adminrule");
}
}
//角色添加
public function roleadd()
{
$data = Db::query("select * from h_power where pid=0");
$arr = array();
foreach ( $data as $key=>$val )
{
$arr[$key] = $val;
$info = Db::query("select * from h_power where pid=".$val['power_id']."");
foreach ( $info as $var )
{
$arr[$key]["powr_zq"][] = $var;
}
}
// var_dump($arr);die;
return view("roleadd",["data"=>$arr]);
}
//添加角色入库
public function addrole()
{
$data = input();
$desc = $data["desc"];
$name = $data["name"];
Db::execute("insert into h_role values(null,'".$name."','".$desc."')");
$role_id = Db::table('h_role')->getLastInsId();//res1:返回获取角色id;
foreach ( $data["id"] as $val )
{
Db::execute("insert into h_r_p values('".$role_id ."','".$val."')");
}
$this->redirect("Power/adminrole");
}
//递归的使用
public function recursive($data,$path=0,$f=0){
static $arr=array();
foreach ($data as $key => $val) {
if($val['pid'] == $path){
$val['f']=$f;
$arr[] = $val;
$this->recursive($data,$val['power_id'],$f+1);
}
}
return $arr;
}
}
一键复制
编辑
Web IDE
原始数据
按行查看
历史