请点击->友情连接在线测试后台管理页面
lang="en">
charset="UTF-8">
http-equiv="X-UA-Compatible"content="IE=edge">
name="viewport"content="width=device-width, initial-scale=1.0">
管理员账号列表 rel="stylesheet"href="/static/layui-v2.6.8/layui/css/layui.css"/>
style="padding:10px;min-width:737px">
class="layui-item">style="color:#777;font-size:20px;height:30px;line-height:30px">首页/
style="color:#ccc">管理员列表
class="layui-table">
ID
用户名
管理员级别
真实姓名
注册时间
状态
编辑
{foreach $admin as $v}
{$v['id']}
{$v['username']}
{$v['gid']}
{$v['truename']}
{:date('Y-m-d H:i:s',$v['add_time'])}
style="color:{$v['status']==0?'green':'red'};"> {$v['status']==0 ? '开启' : '关闭'}
{/foreach}
$=layui.jquery;
//修改信息
functionedit(aid){
layer.open({
type:2,
title:'修改信息',
shadeClose:true,
shade:0.8,
area:['450px','450px'],
content:'/admin/Admin/edit?aid='+aid
});
}
//删除
functiondle(aid){
layer.confirm('确定删除吗?',{
btn:['确定','取消'],
},
function(){
let date={};
$.post('/admin/Admin/dle?aid='+aid,date,function(res){
if(res.id==1){
layer.alert(res.msg,{icon:1});
setTimeout(()=>{
window.location.reload();
},1000);
}else{
layer.alert(res.msg,{icon:2});
}
},'json')
});
}
//添加管理员
functionadd()
{
layer.open({
type:2,
title:'添加信息',
shadeClose:true,
shade:0.8,
area:['450px','450px'],
content:'/admin/Admin/add'
});
}
php
namespaceapp\admin\controller;
useapp\admin\controller\Base;
usethink\facade\Request;
usethink\facade\Db;
usethink\facade\View;
usethink\facade\Session;
/**
* 管理员账号管理
*/
classAdminextendsBase
{
//账号列表
publicfunctionindex()
{
//获取信息 渲染到账号列表
$admin=Db::table('admin a')
->select()
->toArray();
//管理员角色
$group=Db::table('admin_group')->field(['gid','title'])->select()->toArray();
foreach($adminas$key=>$av){
$admin[$key]['gid']='';
foreach($groupas$gv){
if($av['gid']==$gv['gid']){
$admin[$key]['gid']=$gv['title'];
break;
}
}
}
View::assign([
'admin'=>$admin
]);
returnView('/admin/index');
}
//管理员编辑
publicfunctionedit()
{
$aid=(int)Request::get('aid');
$user=Db::table('admin')->where('id',$aid)->find();
$group=$group=Db::table('admin_group')->field(['gid','title'])->select();
View::assign([
'user'=>$user,
'group'=>$group,
'aid'=>$aid
]);
returnView('/admin/edit');
}
//管理员添加页面
publicfunctionadd()
{
$group=$group=Db::table('admin_group')->field(['gid','title'])->select();
View::assign([
'group'=>$group,
]);
returnView('/admin/add');
}
//添加管理员信息
publicfunctionadd_user()
{
//管理员信息接收
$data['username']=Request::post('username');
$data['password']=md5($data['username'].Request::post('password'));
$data['gid']=Request::post('gid');
$data['truename']=Request::post('truename');
$data['add_time']=time();
$data['lastlogin']=time();
$data['status']=Request::post('status');
$data['phone']=Request::post('phone','');
//查询是否有此管理员
if(!empty($data)){
$find=Db::table('admin')->where('username',$data['username'])->field('username')->find();
}
//添加管理员
if(!empty($find)){
exit(json_encode(['id'=>0,"msg"=>'该用户名已存在']));
}else{
if(!empty($data)){
$insert=Db::table('admin')->insert($data);
}
}
if(!empty($insert)){
exit(json_encode(['id'=>1,"msg"=>'添加成功']));
}else{
exit(json_encode(['id'=>0,"msg"=>'添加失败']));
}
}
//管理员账号修改
publicfunctionedit_user()
{
//管理员信息接收
$id=Request::param('aid');
$data['username']=Request::post('username');
$data['password']=md5($data['username'].Request::post('password'));
$data['gid']=Request::post('gid');
$data['truename']=Request::post('truename');
$data['lastlogin']=time();
$data['status']=Request::post('status');
if(!empty($data)){
//更新管理员信息
$update=Db::table("admin")->where('id',$id)->update($data);
}
if(!empty($update)){
echo json_encode(['id'=>1,'msg'=>'修改成功']);
}else{
echo json_encode(['id'=>0,'msg'=>'修改失败']);
}
}
//管理员删除
publicfunctiondle()
{
$aid=Request::param("aid");
if(!empty($aid)){
$delete=Db::table("admin")->where('id',$aid)->delete();
}
if(!empty($delete)){
echo json_encode(['id'=>1,'msg'=>'删除成功']);
}else{
echo json_encode(['id'=>0,'msg'=>'删除失败']);
}
}
}