mirror of https://github.com/1099438829/apeblog
修正用户管理
This commit is contained in:
parent
50114953fb
commit
3471a2bfa8
|
|
@ -5,8 +5,12 @@ namespace app\admin\controller;
|
|||
use app\admin\model\User as aModel;
|
||||
use app\Request;
|
||||
use app\admin\services\UtilService as Util;
|
||||
use FormBuilder\Factory\Elm;
|
||||
use app\admin\services\FormBuilderService as Form;
|
||||
use think\facade\Route as Url;
|
||||
|
||||
/**
|
||||
* 用户管理
|
||||
* Class User
|
||||
* @package app\admin\controller\system
|
||||
* @author 李玉坤
|
||||
|
|
@ -15,11 +19,9 @@ use app\admin\services\UtilService as Util;
|
|||
class User extends AuthController
|
||||
{
|
||||
/**
|
||||
* 活动列表
|
||||
* 账号列表
|
||||
* @return string
|
||||
* @throws \Exception
|
||||
* @author 李玉坤
|
||||
* @date 2021-02-16 13:15
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
|
|
@ -27,20 +29,19 @@ class User extends AuthController
|
|||
}
|
||||
|
||||
/**
|
||||
* 文章列表
|
||||
* 账号列表
|
||||
* @param Request $request
|
||||
* @return mixed
|
||||
* @return
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author 李玉坤
|
||||
* @date 2021-02-15 23:26
|
||||
*/
|
||||
public function lst(Request $request)
|
||||
{
|
||||
$where = Util::postMore([
|
||||
['name',''],
|
||||
['username',''],
|
||||
['tel',''],
|
||||
['is_admin',''],
|
||||
['start_time',''],
|
||||
['end_time',''],
|
||||
['status',''],
|
||||
|
|
@ -49,4 +50,94 @@ class User extends AuthController
|
|||
]);
|
||||
return app("json")->layui(aModel::systemPage($where));
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加账号
|
||||
* @param Request $request
|
||||
* @return string
|
||||
* @throws \FormBuilder\Exception\FormBuilderException
|
||||
*/
|
||||
public function add(Request $request)
|
||||
{
|
||||
$form = array();
|
||||
$form[] = Elm::input('username','登录账号')->col(10);
|
||||
$form[] = Elm::input('nickname','昵称')->col(10);
|
||||
$form[] = Elm::frameImage('avatar','头像',Url::buildUrl('admin/images/index',array('fodder'=>'avatar','limit'=>1)))->icon("ios-image")->width('96%')->height('440px')->col(10);
|
||||
$form[] = Elm::password('password','密码')->col(10);
|
||||
$form[] = Elm::input('tel','电话')->col(10);
|
||||
$form[] = Elm::email('email','邮箱')->col(10);
|
||||
$form[] = Elm::radio('is_admin','管理员',0)->options([['label'=>'是','value'=>1],['label'=>'否','value'=>0]])->col(10);
|
||||
$form[] = Elm::radio('status','状态',1)->options([['label'=>'启用','value'=>1],['label'=>'冻结','value'=>0]])->col(10);
|
||||
$form = Form::make_post_form($form, url('save')->build());
|
||||
$this->assign(compact('form'));
|
||||
return $this->fetch("public/form-builder");
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改账号
|
||||
* @return string
|
||||
* @throws \FormBuilder\Exception\FormBuilderException
|
||||
*/
|
||||
public function edit($id="")
|
||||
{
|
||||
if (!$id) return app("json")->fail("账号id不能为空");
|
||||
$ainfo = aModel::get($id);
|
||||
if (!$ainfo) return app("json")->fail("没有该账号");
|
||||
$form = array();
|
||||
$form[] = Elm::input('username','登录账号',$ainfo['username'])->col(10);
|
||||
$form[] = Elm::input('nickname','昵称',$ainfo['nickname'])->col(10);
|
||||
$form[] = Elm::frameImage('avatar','头像',Url::buildUrl('admin/images/index',array('fodder'=>'avatar','limit'=>1)),$ainfo['avatar'])->icon("ios-image")->width('96%')->height('440px')->col(10);
|
||||
$form[] = Elm::password('password','密码',$ainfo['password'])->col(10);
|
||||
$form[] = Elm::input('tel','电话',$ainfo['tel'])->col(10);
|
||||
$form[] = Elm::email('email','邮箱',$ainfo['email'])->col(10);
|
||||
$form[] = Elm::radio('is_admin','管理员',$ainfo['is_admin'])->options([['label'=>'是','value'=>1],['label'=>'否','value'=>0]])->col(10);
|
||||
$form[] = Elm::radio('status','状态',$ainfo['status'])->options([['label'=>'启用','value'=>1],['label'=>'冻结','value'=>0]])->col(10);
|
||||
$form = Form::make_post_form($form, url('save',['id'=>$id])->build());
|
||||
$this->assign(compact('form'));
|
||||
return $this->fetch("public/form-builder");
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存修改
|
||||
* @param string $id
|
||||
* @return mixed
|
||||
*/
|
||||
public function save($id="")
|
||||
{
|
||||
$data = Util::postMore([
|
||||
['username',''],
|
||||
['nickname',''],
|
||||
['avatar',''],
|
||||
['password',''],
|
||||
['tel',''],
|
||||
['email',''],
|
||||
['is_admin',''],
|
||||
['status','']
|
||||
]);
|
||||
if ($data['username'] == "") return app("json")->fail("登录账号不能为空");
|
||||
if ($data['password'] == "") return app("json")->fail("密码不能为空");
|
||||
if ($data['tel'] == "") return app("json")->fail("手机号不能为空");
|
||||
if ($data['email'] == "") return app("json")->fail("邮箱不能为空");
|
||||
if (is_array($data['avatar'])) $data['avatar'] = $data['avatar'][0];
|
||||
if ($id=="")
|
||||
{
|
||||
//判断下用户是否存在
|
||||
$info = aModel::where('username',$data['username'])->find();
|
||||
if ($info){
|
||||
return app("json")->fail("用户已存在");
|
||||
}
|
||||
$data['password'] = md5(md5($data['password']));
|
||||
$data['ip'] = $this->request->ip();
|
||||
$data['create_user'] = $this->adminId;
|
||||
$res = aModel::create($data);
|
||||
}else
|
||||
{
|
||||
$ainfo = aModel::get($id);
|
||||
if ($ainfo['password'] != $data['password']) $data['password'] = md5(md5($data['password']));
|
||||
$data['update_user'] = $this->adminId;
|
||||
$res = aModel::update($data,['id'=>$id]);
|
||||
}
|
||||
return $res ? app("json")->success("操作成功",'code') : app("json")->fail("操作失败");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -26,7 +26,7 @@ class User extends BaseModel
|
|||
*/
|
||||
public static function login(string $name,string $pwd): bool
|
||||
{
|
||||
$info = self::where("name|tel","=", $name)->find();
|
||||
$info = self::where("username|tel","=", $name)->find();
|
||||
if (!$info) return self::setErrorInfo("登录账号不存在");
|
||||
if ($info['pwd'] != md5(md5($pwd))) return self::setErrorInfo("密码不正确!");
|
||||
if ($info['status'] == 2) return self::setErrorInfo("账号已被冻结!");
|
||||
|
|
@ -78,11 +78,12 @@ class User extends BaseModel
|
|||
public static function systemPage(array $where): array
|
||||
{
|
||||
$model = new self;
|
||||
if ($where['name'] != '') $model = $model->where("username|nickname","like","%$where[name]%");
|
||||
if ($where['username'] != '') $model = $model->where("username|nickname","like","%$where[name]%");
|
||||
if ($where['start_time'] != '') $model = $model->where("create_time",">",strtotime($where['start_time']." 00:00:00"));
|
||||
if ($where['end_time'] != '') $model = $model->where("create_time","<", strtotime($where['end_time']." 23:59:59"));
|
||||
if ($where['tel'] != '') $model = $model->where("tel|mail", "like","%$where[tel]%");
|
||||
if ($where['tel'] != '') $model = $model->where("tel|email", "like","%$where[tel]%");
|
||||
if ($where['status'] != '') $model = $model->where("status",$where['status']);
|
||||
if ($where['is_admin'] != '') $model = $model->where("is_admin",$where['is_admin']);
|
||||
$count = self::counts($model);
|
||||
if ($where['page'] && $where['limit']) $model = $model->page((int)$where['page'],(int)$where['limit']);
|
||||
$data = $model->select();
|
||||
|
|
|
|||
|
|
@ -13,26 +13,35 @@
|
|||
<div class="card-body">
|
||||
<form class="form-inline searchForm" onsubmit="return false;">
|
||||
<div class="form-group">
|
||||
<label for="create_time">留言时间</label>
|
||||
<label for="username">账号昵称</label>
|
||||
<div class="input-group">
|
||||
<input class="form-control js-datetimepicker" type="text" id="create_time" name="create_time" value="" data-side-by-side="true" data-locale="zh-cn" data-format="YYYY-MM-DD" placeholder="开始时间">
|
||||
<span class="input-group-addon">~</span>
|
||||
<input class="form-control js-datetimepicker" type="text" name="create_time" value="" data-side-by-side="true" data-locale="zh-cn" data-format="YYYY-MM-DD" placeholder="结束时间">
|
||||
<div class="input-group">
|
||||
<input type="text" class="form-control" id="username" value="" name="username" placeholder="请输入账号或者昵称搜索">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="type">来源</label>
|
||||
<select name="type" id="type" class="form-control">
|
||||
<option value="">所有</option>
|
||||
<option value="1">CMS留言</option>
|
||||
</select>
|
||||
<label for="tel">电话邮箱</label>
|
||||
<div class="input-group">
|
||||
<div class="input-group">
|
||||
<input type="text" class="form-control" id="tel" value="" name="tel" placeholder="请输入电话或者邮箱">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="is_read">是否已读</label>
|
||||
<select name="is_read" class="form-control" id="is_read">
|
||||
<option value="">全部</option>
|
||||
<option value="0">未读</option>
|
||||
<option value="1">已读</option>
|
||||
<label for="start_time">创建时间</label>
|
||||
<div class="input-group">
|
||||
<input class="form-control js-datetimepicker" type="text" id="start_time" name="start_time" value="" autocomplete="off" data-side-by-side="true" data-locale="zh-cn" data-format="YYYY-MM-DD" placeholder="开始时间">
|
||||
<span class="input-group-addon">~</span>
|
||||
<input class="form-control js-datetimepicker" type="text" name="end_time" value="" autocomplete="off" data-side-by-side="true" data-locale="zh-cn" data-format="YYYY-MM-DD" placeholder="结束时间">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="status">状态</label>
|
||||
<select name="status" id="status" class="form-control">
|
||||
<option value="">所有</option>
|
||||
<option value="1">启用</option>
|
||||
<option value="0">禁用</option>
|
||||
</select>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-success" style="margin: -10px 0 0 10px;" id="search">搜索</button>
|
||||
|
|
@ -42,10 +51,19 @@
|
|||
</div>
|
||||
<div class="col-lg-12">
|
||||
<div class="card">
|
||||
<div class="card-header"><h4>用户留言</h4></div>
|
||||
<div class="card-header"><h4>用户管理</h4></div>
|
||||
<div class="card-body">
|
||||
<div id="toolbar" class="toolbar-btn-action">
|
||||
<button id="btn_delete" type="button" class="btn btn-danger">
|
||||
<button id="btn_add" type="button" class="btn btn-primary m-r-5" onclick="iframe.createIframe('添加用户','/admin/user/add')">
|
||||
<span class="mdi mdi-plus" aria-hidden="true"></span>新增
|
||||
</button>
|
||||
<button id="btn_edit" type="button" class="btn btn-success m-r-5" onclick="isEnable('enable')">
|
||||
<span class="mdi mdi-check" aria-hidden="true"></span>启用
|
||||
</button>
|
||||
<button id="btn_disable" type="button" class="btn btn-warning m-r-5" onclick="isEnable('disable')">
|
||||
<span class="mdi mdi-block-helper" aria-hidden="true"></span>禁用
|
||||
</button>
|
||||
<button id="btn_delete" type="button" class="btn btn-danger" onclick="del()">
|
||||
<span class="mdi mdi-window-close" aria-hidden="true"></span>删除
|
||||
</button>
|
||||
</div>
|
||||
|
|
@ -55,7 +73,7 @@
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{include file="public/footer" /}
|
||||
{include file="public/footer"/}
|
||||
<script type="text/javascript">
|
||||
$('#tb_departments').bootstrapTable({
|
||||
classes: 'table table-bordered table-hover table-striped',
|
||||
|
|
@ -73,56 +91,56 @@
|
|||
"rows": res.data,
|
||||
};
|
||||
},
|
||||
pagination: true, // 是否显示分页
|
||||
sortOrder: "asc", // 排序方式
|
||||
pagination: true,
|
||||
queryParams: function(params) {
|
||||
let temp = toArrayList($(".searchForm").serializeArray());
|
||||
var temp = toArrayList($(".searchForm").serializeArray());
|
||||
temp['limit'] = params.limit;
|
||||
temp['page'] = (params.offset / params.limit) + 1;
|
||||
return temp;
|
||||
}, // 传递参数
|
||||
sidePagination: "server", // 分页方式:client客户端分页,server服务端分页
|
||||
pageNumber: 1, // 初始化加载第一页,默认第一页
|
||||
pageSize: 10, // 每页的记录行数
|
||||
pageList: [20, 50, 100], // 可供选择的每页的行数
|
||||
},
|
||||
sidePagination: "server",
|
||||
pageNumber: 1,
|
||||
pageSize: 20,
|
||||
pageList: [20, 50, 100],
|
||||
columns: [{
|
||||
checkbox: true // 是否显示复选框
|
||||
}, {
|
||||
field: 'id',
|
||||
title: '留言ID',
|
||||
title: 'ID',
|
||||
sortable: true // 是否排序
|
||||
}, {
|
||||
field: 'truename',
|
||||
title: '用户昵称'
|
||||
field: 'username',
|
||||
title: '账号'
|
||||
}, {
|
||||
field: 'nickname',
|
||||
title: '昵称',
|
||||
}, {
|
||||
field: 'avatar',
|
||||
title: '头像',
|
||||
formatter:function (value,row,index) {
|
||||
return '<img src="'+value+'" style="width: 64px;"/>';
|
||||
},
|
||||
},{
|
||||
field: 'tel',
|
||||
title: '电话'
|
||||
}, {
|
||||
field: 'email',
|
||||
title: '邮箱'
|
||||
}, {
|
||||
field: 'ip',
|
||||
title: 'ip',
|
||||
}, {
|
||||
field: 'is_admin',
|
||||
title: '管理员',
|
||||
formatter: function (value, row, index) {
|
||||
return value?'是':'否';
|
||||
}
|
||||
}, {
|
||||
title: '是否是管理员',
|
||||
formatter:function (value,row,index) {
|
||||
return value === 1 ? '是' : '否';
|
||||
},
|
||||
},{
|
||||
field: 'create_time',
|
||||
title: '创建时间',
|
||||
}, {
|
||||
title: '创建时间'
|
||||
}
|
||||
, {
|
||||
field: 'status',
|
||||
title: '状态',
|
||||
formatter: function (value, row, index) {
|
||||
if (value == 0) {
|
||||
is_checked = '';
|
||||
} else if (value == 1){
|
||||
is_checked = 'checked="checked"';
|
||||
}
|
||||
var field = "status";
|
||||
result = '<label class="lyear-switch switch-primary switch-solid lyear-status"><input type="checkbox" '+ is_checked +'><span onClick="updateStatus('+ row.id +', '+ value +', \''+ field +'\')"></span></label>';
|
||||
return result;
|
||||
formatter:function (value,row,index) {
|
||||
return value === 1 ? '启用' : '冻结';
|
||||
},
|
||||
}, {
|
||||
field: 'operate',
|
||||
|
|
@ -130,7 +148,7 @@
|
|||
formatter: btnGroup, // 自定义方法
|
||||
events: {
|
||||
'click .edit-btn': function (event, value, row, index) {
|
||||
iframe.createIframe('修改','/admin/user/edit?id='+row.id)
|
||||
iframe.createIframe('修改用户','/admin/user/edit?id='+row.id)
|
||||
},
|
||||
'click .del-btn': function (event, value, row, index) {
|
||||
$.alert({
|
||||
|
|
@ -155,35 +173,117 @@
|
|||
}
|
||||
}
|
||||
}],
|
||||
|
||||
onEditableSave: function (field, row, oldValue, $el) {
|
||||
$.ajax({
|
||||
type: "get",
|
||||
url: "/admin/user/lst",
|
||||
data: row,
|
||||
dataType: 'jsonp',
|
||||
success: function (data, status) {
|
||||
if (data.code == '200') {
|
||||
// 这里的状态显示有自定义样式区分,做单行的更新
|
||||
$('.example-table').bootstrapTable('updateRow', {index: row.id, row: row});
|
||||
} else {
|
||||
alert(data.msg);
|
||||
}
|
||||
},
|
||||
error: function () {
|
||||
alert('修改失败,请稍后再试');
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
onLoadSuccess: function(data){
|
||||
$("[data-toggle='tooltip']").tooltip();
|
||||
}
|
||||
});
|
||||
|
||||
$("#search").click(function () {
|
||||
$("#tb_departments").bootstrapTable('refresh',{query:{page:1},pageNumber:1});
|
||||
});
|
||||
|
||||
// 操作按钮
|
||||
function btnGroup ()
|
||||
{
|
||||
let html =
|
||||
'<a href="#!" class="btn btn-xs btn-default m-r-5 edit-btn" title="编辑" data-toggle="tooltip"><i class="mdi mdi-pencil"></i></a>' +
|
||||
'<a href="#!" class="btn btn-xs btn-default del-btn" title="删除" data-toggle="tooltip"><i class="mdi mdi-window-close"></i></a>';
|
||||
return html;
|
||||
}
|
||||
|
||||
$("#search").click(function () {
|
||||
$("#tb_departments").bootstrapTable('refresh',{query:{page:1},pageNumber:1});
|
||||
});
|
||||
function updateStatus(id, value, field) {
|
||||
var newstate = (value == 1) ? 0 : 1; // 发送参数值跟当前参数值相反
|
||||
$.ajax({
|
||||
type: "post",
|
||||
url: "/admin/user/field?id="+id,
|
||||
data: {field: field, value: newstate},
|
||||
dataType: 'json',
|
||||
success: function (res) {
|
||||
if (res.status == 200) {parent.lightyear.notify('修改成功', 'success', 3000, 'mdi mdi-emoticon-happy', 'top', 'center');$(".tree-table").bootstrapTable('refresh');}
|
||||
else parent.lightyear.notify('修改失败', 'danger', 3000, 'mdi mdi-emoticon-happy', 'top', 'center');
|
||||
},
|
||||
error: function () {
|
||||
parent.lightyear.notify('修改失败', 'danger', 3000, 'mdi mdi-emoticon-happy', 'top', 'center');
|
||||
// 删除
|
||||
function del() {
|
||||
var checkID = "";
|
||||
var selectedItem = $('#tb_departments').bootstrapTable('getAllSelections');
|
||||
if (selectedItem=="") return lightyear.notify("没有选中项", 'danger', 3000, 'mdi mdi-emoticon-neutral', 'top', 'center');
|
||||
for (var i = 0 ; i< selectedItem.length; i++)
|
||||
{
|
||||
checkID += selectedItem[i]['id']+",";
|
||||
}
|
||||
if (checkID=="") return lightyear.notify("没有选中项", 'danger', 3000, 'mdi mdi-emoticon-neutral', 'top', 'center');
|
||||
$.confirm({
|
||||
title: '重要提醒!',
|
||||
content: '选中项将全部被删除,请谨慎操作!' ,
|
||||
backgroundDismiss: true,
|
||||
buttons: {
|
||||
ok: {
|
||||
text: '确认',
|
||||
btnClass: 'btn-danger',
|
||||
action: function () {
|
||||
$.post("/admin/user/del",data={id:checkID},function (res) {
|
||||
if (res.status == 200){ lightyear.notify(res.msg, 'success', 3000, 'mdi mdi-emoticon-happy', 'top', 'center');location.reload();}
|
||||
else lightyear.notify(res.msg, 'danger', 3000, 'mdi mdi-emoticon-neutral', 'top', 'center');
|
||||
})
|
||||
}
|
||||
},
|
||||
cancel: {
|
||||
text: '取消',
|
||||
btnClass: 'btn-primary'
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// 批量启用或者禁用
|
||||
function isEnable(type) {
|
||||
var checkID = "";
|
||||
var selectedItem = $('#tb_departments').bootstrapTable('getAllSelections');
|
||||
if (selectedItem=="") return lightyear.notify("没有选中项", 'danger', 3000, 'mdi mdi-emoticon-neutral', 'top', 'center');
|
||||
for (var i = 0 ; i< selectedItem.length; i++)
|
||||
{
|
||||
checkID += selectedItem[i]['id']+",";
|
||||
}
|
||||
if (checkID=="") return lightyear.notify("没有选中项", 'danger', 3000, 'mdi mdi-emoticon-neutral', 'top', 'center');
|
||||
$.confirm({
|
||||
title: '重要提醒!',
|
||||
content: type == 'enable' ? '选中项将全部启用,请谨慎操作!' : '选中项将全部禁用,请谨慎操作!',
|
||||
backgroundDismiss: true,
|
||||
buttons: {
|
||||
ok: {
|
||||
text: '确认',
|
||||
btnClass: 'btn-danger',
|
||||
action: function () {
|
||||
if (type == 'enable')
|
||||
{
|
||||
$.post("/admin/user/enabled",data={id:checkID},function (res) {
|
||||
if (res.status == 200) {lightyear.notify(res.msg, 'success', 3000, 'mdi mdi-emoticon-happy', 'top', 'center');location.reload();}
|
||||
else lightyear.notify(res.msg, 'danger', 3000, 'mdi mdi-emoticon-neutral', 'top', 'center');
|
||||
|
||||
})
|
||||
}else
|
||||
{
|
||||
$.post("/admin/user/disabled",data={id:checkID},function (res) {
|
||||
if (res.status == 200) {lightyear.notify(res.msg, 'success', 3000, 'mdi mdi-emoticon-happy', 'top', 'center');location.reload();}
|
||||
else lightyear.notify(res.msg, 'danger', 3000, 'mdi mdi-emoticon-neutral', 'top', 'center');
|
||||
})
|
||||
}
|
||||
}
|
||||
},
|
||||
cancel: {
|
||||
text: '取消',
|
||||
btnClass: 'btn-primary'
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue