优化前后台用户的操作日志记录等

This commit is contained in:
hdm 2021-06-15 20:01:07 +08:00
parent 2ba665dafc
commit c28cc3abd1
12 changed files with 109 additions and 96 deletions

View File

@ -289,65 +289,7 @@ class Api extends BaseController
$param=get_params();
$log = new AdminLog();
$content = $log->get_log_list($param);
return table_assign(0,'',$content);
}
//回复咨询
public function set_reply()
{
$param=get_params();
$data = [];
if(isset($param['cid']) && $param['cid']){
$data['cid'] = $param['cid'];
$data['uid'] = 0;
$data['create_time'] =time();
$data['content'] = $param['content'];
$res = Db::name('ConsultationReply')->strict(false)->field(true)->insertGetId($data);
}
if(isset($param['rid']) && $param['rid']){
$data['id'] = $param['rid'];
$data['update_time'] =time();
if(isset($param['status']) && $param['status']){
$data['status'] = $param['status'];
}
else{
$data['content'] = $param['content'];
}
$res = Db::name('ConsultationReply')->strict(false)->field(true)->update($data);
}
if($res){
return to_assign();
}
else{
return to_assign(0,'操作失败,请重试');
}
}
//评论动态
public function set_comment()
{
$param=get_params();
$data = [];
if(isset($param['rid']) && $param['rid']){
$data['id'] = $param['rid'];
$data['update_time'] =time();
if(isset($param['status']) && $param['status']){
$data['status'] = $param['status'];
}
else{
$data['content'] = $param['content'];
}
$res = Db::name('DynamicComment')->strict(false)->field(true)->update($data);
}
if($res){
return to_assign();
}
else{
return to_assign(0,'操作失败,请重试');
}
return table_assign(1,'',$content);
}
}

View File

@ -52,6 +52,7 @@ class Database extends BaseController
foreach ($tables as $table) {
$this->db->setFile()->backup($table, 0);
}
add_log('add');
return to_assign(1, '备份成功!');
} else {
return to_assign(0, '请选择要备份的表!');
@ -66,6 +67,7 @@ class Database extends BaseController
}
$tables = explode(',',$tables);
if ($this->db->optimize($tables)) {
add_log('edit');
return to_assign(1, '数据表优化成功!');
} else {
return to_assign(0, '数据表优化出错请重试!');
@ -80,6 +82,7 @@ class Database extends BaseController
}
$tables = explode(',',$tables);
if ($this->db->repair($tables)) {
add_log('edit');
return to_assign(1, '数据表修复成功!');
} else {
return to_assign(0, '数据表修复出错请重试!');
@ -111,6 +114,7 @@ class Database extends BaseController
{
$list = $this->db->getFile('timeverif', $id);
$this->db->setFile($list)->import(1);
add_log('save');
return to_assign(1,'还原成功!');
}
@ -155,9 +159,11 @@ class Database extends BaseController
foreach ($idArr as $k => $v) {
$this->db->delFile($v);
}
add_log('delete');
return to_assign(1,"删除成功!");
}
if ($this->db->delFile($id)) {
add_log('delete');
return to_assign(1,"删除成功!");
} else {
return to_assign(0, "备份文件删除失败,请检查文件权限!");

View File

@ -134,4 +134,41 @@ class User extends BaseController
}
}
public function record()
{
if (request()->isAjax()) {
$param = get_params();
$where = array();
if (!empty($param['keywords'])) {
$where[] = ['nickname|title','like', '%' . $param['keywords'] . '%'];
}
$rows = empty($param['limit']) ? get_config(app . page_size) : $param['limit'];
$content = DB::name('user_log')
->field("id,uid,nickname,title,content,ip,param,create_time")
->order('create_time desc')
->where($where)
->paginate($rows, false, ['query' => $param]);
$content->toArray();
foreach ($content as $k => $v) {
$data = $v;
$param_array = json_decode($v['param'], true);
$name = '';
if (!empty($param_array['name'])) {
$name = ''. $param_array['name'];
}
if (!empty($param_array['title'])) {
$name = ''. $param_array['title'];
}
$data['content'] = $v['content'] . $name;
$data['times'] = time_trans($v['create_time']);
$content->offsetSet($k, $data);
}
return table_assign(1, '', $content);
}
else{
return view();
}
}
}

View File

@ -45,10 +45,9 @@
align: 'center',
width: 90
}, {
field: 'admin_menu',
field: 'title',
title: '操作类型',
width: 90,
align: 'center',
width: 150
}, {
field: 'content',
title: '操作描述',

View File

@ -36,7 +36,7 @@
limit: limit
},
success: function(e) {
if (e.code == 0) {
if (e.code == 1) {
var html = '';
if(e.data.length>0){
page++;

View File

@ -222,7 +222,7 @@
limit: 10
},
success: function (e) {
if (e.code == 0) {
if (e.code == 1) {
var html = '';
$.each(e.data, function (key, value) {
html += '<li class="layui-timeline-item">\

View File

@ -41,8 +41,7 @@
}, {
field: 'content',
title: '操作描述',
align: 'center',
width: 348
width: 360
}, {
field: 'param',
title: '操作数据'
@ -50,12 +49,12 @@
field: 'nickname',
title: '昵称',
align: 'center',
width: 100
width: 120
}, {
field: 'ip',
title: 'IP地址',
align: 'center',
width: 100
width: 120
}, {
field: 'create_time',
title: '操作时间',

View File

@ -25,7 +25,7 @@ function get_login_user($key = "")
* @param int $param_id 操作类型
* @param array $param 提交的参数
*/
function add_user_log($type, $param_id = '', $param = [])
function add_user_log($type, $param_str='', $param_id = 0, $param = [])
{
$request = request();
switch ($type) {
@ -47,6 +47,18 @@ function add_user_log($type, $param_id = '', $param = [])
case 'delete':
$title = '删除';
break;
case 'join':
$title = '报名';
break;
case 'sign':
$title = '签到';
break;
case 'play':
$title = '播放';
break;
case 'order':
$title = '下单';
break;
case 'pay':
$title = '支付';
break;
@ -56,16 +68,28 @@ function add_user_log($type, $param_id = '', $param = [])
}
if ($type == 'login') {
$login_user = \think\facade\Db::name('user')->where(array('id' => $param_id))->find();
if($login_user['nickname'] == ''){
$login_user['nickname'] = $login_user['name'];
}
if($login_user['nickname'] == ''){
$login_user['nickname'] = $login_user['username'];
}
} else {
$session_user = get_config('app.session_user');
$login_user = \think\facade\Session::get($session_user);
$login_user = get_login_user();
if (empty($login_user)) {
$login_user['id'] = 0;
$login_user['nickname'] = '游客';
}
else{
if($login_user['nickname'] == ''){
$login_user['nickname'] = $login_user['username'];
}
}
}
$content = $login_user['nickname'] . '在' . date('Y-m-d H:i:s') . '执行了' . $title . '操作';
$content = $login_user['nickname'] . '在' . date('Y-m-d H:i:s') . '执行了' . $title . '操作';
if($param_str!=''){
$content = $login_user['nickname'] . '在' . date('Y-m-d H:i:s') . $title .'了' . $param_str;
}
$data = [];
$data['uid'] = $login_user['id'];
$data['nickname'] = $login_user['nickname'];

View File

@ -10,7 +10,8 @@ use think\facade\View;
class Index extends BaseController
{
public function index()
{
{
add_user_log('view','首页');
return View();
}

View File

@ -17,6 +17,7 @@ class Login
if(!empty(get_login_user('id'))){
redirect('/home/user/index')->send();
}
add_user_log('view','登录页面');
return View();
}
//错误页面
@ -63,7 +64,7 @@ class Login
$token = make_token();
set_cache($token, $userInfo, 7200);
$userInfo['token'] = $token;
add_user_log('login', $user['id'], $data);
add_user_log('login','',$user['id']);
return to_assign(1, '登录成功', $userInfo);
}
@ -96,16 +97,17 @@ class Login
$Avatar->Free();
return $path;
}
//注册
//注册
public function reg()
{
if(!empty(get_login_user('id'))){
redirect('/home/user/index')->send();
}
add_user_log('view','注册页面');
return View();
}
//提交注册
//提交注册
public function reg_submit()
{
$param = get_params();
@ -128,7 +130,7 @@ class Login
$char = mb_substr($param['username'], 0, 1, 'utf-8');
$param['headimgurl'] = $this->to_avatars($char);
$uid = Db::name('User')->strict(false)->field(true)->insertGetId($param);
add_user_log('reg', $uid, $param);
add_user_log('reg','',$uid);
return to_assign(1, '注册成功,请登录', $uid);
}

View File

@ -15,6 +15,7 @@ class User extends BaseController
$userInfo = Db::name('User')->where(['id' => $uid])->find();
$userInfo['showname'] = empty($userInfo['nickname']) ? $userInfo['username'] : $userInfo['nickname'];
$userInfo['sex'] = ($userInfo['sex'] == 1) ? '男' : '女';
add_user_log('view','个人中心');
View::assign('userInfo', $userInfo);
return view();
}
@ -23,6 +24,7 @@ class User extends BaseController
{
$uid=get_login_user('id');
$userInfo = Db::name('User')->where(['id' => $uid])->find();
add_user_log('view','个人信息');
View::assign('userInfo', $userInfo);
return view();
}
@ -33,6 +35,7 @@ class User extends BaseController
$param['birthday'] = strtotime($param['birthday']);
$res = Db::name('User')->where(['id' => $param['id']])->strict(false)->field(true)->update($param);
if($res!== false){
add_user_log('edit','个人信息',$param['id'],$param);
to_assign(1,'操作成功');
}
else{

View File

@ -25,7 +25,7 @@ CREATE TABLE `cms_admin` (
`status` int(1) NOT NULL DEFAULT '1' COMMENT '1正常-1禁止登录',
PRIMARY KEY (`id`),
UNIQUE KEY `id` (`id`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARACTER SET = utf8mb4 COMMENT='管理员';
) ENGINE=InnoDB DEFAULT CHARACTER SET = utf8mb4 COMMENT='管理员';
-- ----------------------------
-- Table structure for `cms_admin_group`
@ -42,7 +42,7 @@ CREATE TABLE `cms_admin_group` (
`update_time` int(11) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`),
UNIQUE KEY `id` (`id`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARACTER SET = utf8mb4 COMMENT='权限分组';
) ENGINE=InnoDB DEFAULT CHARACTER SET = utf8mb4 COMMENT='权限分组';
-- ----------------------------
-- Records of cms_admin_group
@ -224,7 +224,6 @@ CREATE TABLE `cms_admin_log` (
`controller` varchar(32) NOT NULL DEFAULT '' COMMENT '控制器',
`function` varchar(32) NOT NULL DEFAULT '' COMMENT '方法',
`rule_menu` varchar(255) NOT NULL DEFAULT '' COMMENT '节点权限路径',
`admin_menu` varchar(255) NOT NULL DEFAULT '' COMMENT '节点权限名称',
`ip` varchar(64) NOT NULL DEFAULT '' COMMENT '登录ip',
`param_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '操作数据id',
`param` text COMMENT '参数json格式',
@ -246,14 +245,14 @@ CREATE TABLE `cms_config` (
`create_time` int(11) NOT NULL DEFAULT '0' COMMENT '创建时间',
`update_time` int(11) NOT NULL DEFAULT '0' COMMENT '更新时间',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARACTER SET = utf8mb4 COMMENT='系统配置';
) ENGINE=InnoDB DEFAULT CHARACTER SET = utf8mb4 COMMENT='系统配置';
-- ----------------------------
-- Records of cms_config
-- ----------------------------
INSERT INTO `cms_config` VALUES (1, '网站配置', 'web', 'a:13:{s:2:\"id\";s:1:\"1\";s:11:\"admin_title\";s:9:\"勾股cms\";s:5:\"title\";s:9:\"勾股cms\";s:4:\"logo\";s:0:\"\";s:4:\"file\";s:0:\"\";s:6:\"domain\";s:24:\"https://www.gougucms.com\";s:3:\"icp\";s:23:\"粤ICP备1xxxxxx11号-1\";s:8:\"keywords\";s:9:\"勾股cms\";s:5:\"beian\";s:29:\"粤公网安备1xxxxxx11号-1\";s:4:\"desc\";s:255:\"勾股CMS是一套基于ThinkPHP6 + Layui + MySql打造的轻量级、高性能快速建站的内容管理系统。后台管理模块一目了然操作简单通用型后台权限管理框架紧随潮流、极低门槛、开箱即用。 \";s:4:\"code\";s:0:\"\";s:9:\"copyright\";s:32:\"© 2021 gouguapp.com MIT license\";s:7:\"version\";s:5:\"1.0.2\";}', 1, 1612514630, 1623721279);
INSERT INTO `cms_config` VALUES (1, '网站配置', 'web', 'a:13:{s:2:\"id\";s:1:\"1\";s:11:\"admin_title\";s:9:\"勾股cms\";s:5:\"title\";s:9:\"勾股cms\";s:4:\"logo\";s:0:\"\";s:4:\"file\";s:0:\"\";s:6:\"domain\";s:24:\"https://www.gougucms.com\";s:3:\"icp\";s:23:\"粤ICP备1xxxxxx11号-1\";s:8:\"keywords\";s:9:\"勾股cms\";s:5:\"beian\";s:29:\"粤公网安备1xxxxxx11号-1\";s:4:\"desc\";s:255:\"勾股CMS是一套基于ThinkPHP6 + Layui + MySql打造的轻量级、高性能快速建站的内容管理系统。后台管理模块一目了然操作简单通用型后台权限管理框架紧随潮流、极低门槛、开箱即用。 \";s:4:\"code\";s:0:\"\";s:9:\"copyright\";s:32:\"© 2021 gougucms.com MIT license\";s:7:\"version\";s:5:\"1.0.2\";}', 1, 1612514630, 1623721279);
INSERT INTO `eye_config` VALUES (2, '邮箱配置', 'email', 'a:8:{s:2:\"id\";s:1:\"2\";s:4:\"smtp\";s:11:\"smtp.qq.com\";s:9:\"smtp_port\";s:3:\"465\";s:9:\"smtp_user\";s:15:\"gougucms@qq.com\";s:8:\"smtp_pwd\";s:6:\"123456\";s:4:\"from\";s:24:\"勾股CMS系统管理员\";s:5:\"email\";s:18:\"admin@gougucms.com\";s:8:\"template\";s:122:\"<p>勾股CMS是一套基于ThinkPHP6 + Layui + MySql打造的轻量级、高性能快速建站的内容管理系统。</p>\";}', 1, 1612521657, 1619088538);
INSERT INTO `cms_config` VALUES (3, '微信配置', 'wechat', 'a:9:{s:2:\"id\";s:1:\"3\";s:5:\"token\";s:8:\"GOUGUCMS\";s:14:\"login_back_url\";s:48:\"http://www.gougucms.com/wechat/index/getChatInfo\";s:5:\"appid\";s:18:\"wxdf96xxxx7cd6f0c5\";s:9:\"appsecret\";s:32:\"1dbf319a4f0dfed7xxxxfd1c7dbba488\";s:5:\"mchid\";s:10:\"151xxxx331\";s:11:\"secrect_key\";s:32:\"beiyuexxxxhunangdmabcxxxxjixxxng\";s:8:\"cert_url\";s:13:\"/extend/cert/\";s:12:\"pay_back_url\";s:42:\"https://www.gouguapp.com/wxappv1/wx/notify\";}', 1, 1612522314, 1613789058);
INSERT INTO `cms_config` VALUES (4, '其他配置', 'other', 'a:3:{s:2:\"id\";s:1:\"4\";s:6:\"author\";s:12:\"629工作室\";s:7:\"version\";s:5:\"1.0.2\";}', 1, 1613725791, 1613789431);
INSERT INTO `cms_config` VALUES (3, '微信配置', 'wechat', 'a:9:{s:2:\"id\";s:1:\"3\";s:5:\"token\";s:8:\"GOUGUCMS\";s:14:\"login_back_url\";s:48:\"http://www.gougucms.com/wechat/index/getChatInfo\";s:5:\"appid\";s:18:\"wxdf96xxxx7cd6f0c5\";s:9:\"appsecret\";s:32:\"1dbf319a4f0dfed7xxxxfd1c7dbba488\";s:5:\"mchid\";s:10:\"151xxxx331\";s:11:\"secrect_key\";s:32:\"beiyuexxxxhunangdmabcxxxxjixxxng\";s:8:\"cert_url\";s:13:\"/extend/cert/\";s:12:\"pay_back_url\";s:42:\"https://www.gougucms.com/wechat/index/notify\";}', 1, 1612522314, 1613789058);
INSERT INTO `cms_config` VALUES (4, '其他配置', 'other', 'a:3:{s:2:\"id\";s:1:\"4\";s:6:\"author\";s:12:\"勾股工作室\";s:7:\"version\";s:5:\"1.0.2\";}', 1, 1613725791, 1613789431);
-- ----------------------------
@ -268,7 +267,7 @@ CREATE TABLE `cms_keywords` (
`create_time` int(11) NOT NULL DEFAULT '0' COMMENT '创建时间',
`update_time` int(11) NOT NULL DEFAULT '0' COMMENT '更新时间',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARACTER SET = utf8mb4 COMMENT='关键字';
) ENGINE=InnoDB DEFAULT CHARACTER SET = utf8mb4 COMMENT='关键字';
-- ----------------------------
-- Records of cms_keywords
-- ----------------------------
@ -288,7 +287,7 @@ CREATE TABLE `cms_article_cate` (
`create_time` int(11) NOT NULL DEFAULT '0' COMMENT '添加时间',
`update_time` int(11) NOT NULL DEFAULT '0' COMMENT '修改时间',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARACTER SET = utf8mb4 COMMENT='内容分类';
) ENGINE=InnoDB DEFAULT CHARACTER SET = utf8mb4 COMMENT='内容分类';
-- ----------------------------
-- Records of cms_article_cate
-- ----------------------------
@ -317,7 +316,7 @@ CREATE TABLE `cms_article` (
`update_time` int(11) NOT NULL DEFAULT '0',
`delete_time` int(11) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARACTER SET = utf8mb4 COMMENT='文章';
) ENGINE=InnoDB DEFAULT CHARACTER SET = utf8mb4 COMMENT='文章';
-- ----------------------------
-- Records of cms_article
@ -337,7 +336,7 @@ CREATE TABLE `cms_article_keywords` (
PRIMARY KEY (`id`),
KEY `aid` (`aid`),
KEY `inid` (`keywords_id`)
) ENGINE=InnoDB DEFAULT CHARACTER SET = utf8mb4 COMMENT='文章关联关键字';
) ENGINE=InnoDB DEFAULT CHARACTER SET = utf8mb4 COMMENT='文章关联';
-- ----------------------------
-- Records of cms_article_keywords
-- ----------------------------
@ -355,7 +354,7 @@ CREATE TABLE `cms_sitemap_cate` (
`create_time` int(11) NOT NULL DEFAULT 0,
`update_time` int(11) NOT NULL DEFAULT 0,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARACTER SET = utf8mb4 COMMENT = '网站地图分类';
) ENGINE=InnoDB DEFAULT CHARACTER SET = utf8mb4 COMMENT = '网站地图分类';
-- ----------------------------
-- Table structure for cms_sitemap
@ -374,7 +373,7 @@ CREATE TABLE `cms_sitemap` (
`create_time` int(11) NOT NULL DEFAULT 0,
`update_time` int(11) NOT NULL DEFAULT 0,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARACTER SET = utf8mb4 COMMENT = '网站地图内容';
) ENGINE=InnoDB DEFAULT CHARACTER SET = utf8mb4 COMMENT = '网站地图内容';
-- ----------------------------
@ -414,16 +413,17 @@ CREATE TABLE `cms_nav_info` (
`create_time` int(11) NOT NULL DEFAULT '0',
`update_time` int(11) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARACTER SET = utf8mb4 COMMENT='导航详情';
) ENGINE=InnoDB DEFAULT CHARACTER SET = utf8mb4 COMMENT='导航详情';
-- -----------------------------
-- Records of `cms_nav_info`
-- -----------------------------
INSERT INTO `cms_nav_info` VALUES ('1', '0', '1', '首页', '/', '', '0', '1', '1', '0', '0');
INSERT INTO `cms_nav_info` VALUES ('2', '0', '1', '文档', '/', '', '0', '1', '2', '0', '0');
INSERT INTO `cms_nav_info` VALUES ('3', '0', '1', '后台演示', '/admin/index/index.html', '', '1', '1', '4', '0', '0');
INSERT INTO `cms_nav_info` VALUES ('4', '0', '1', '社区', '/', '', '0', '1', '3', '0', '0');
INSERT INTO `cms_nav_info` VALUES ('3', '0', '1', '社区', '/', '', '1', '1', '3', '0', '0');
INSERT INTO `cms_nav_info` VALUES ('4', '0', '1', '腾讯云优惠', 'https://curl.qcloud.com/PPEgI0oV', '', '1', '1', '4', '0', '0');
INSERT INTO `cms_nav_info` VALUES ('5', '0', '1', '阿里云特惠', 'https://www.aliyun.com/activity/daily/bestoffer?userCode=dmrcx154', '', '1', '1', '5', '0', '0');
INSERT INTO `cms_nav_info` VALUES ('6', '0', '1', '后台演示', 'https://cms.gougucms.com/admin/index/index.html', '', '1', '1', '6', '0', '0');
-- ----------------------------
-- Table structure for `cms_slide`
@ -438,7 +438,7 @@ CREATE TABLE `cms_slide` (
`create_time` int(11) NOT NULL DEFAULT '0',
`update_time` int(11) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARACTER SET = utf8mb4 COMMENT='幻灯片';
) ENGINE=InnoDB DEFAULT CHARACTER SET = utf8mb4 COMMENT='幻灯片';
-- ----------------------------
-- Records of cms_slide
@ -461,7 +461,7 @@ CREATE TABLE `cms_slide_info` (
`create_time` int(11) NOT NULL DEFAULT '0',
`update_time` int(11) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARACTER SET = utf8mb4 COMMENT='幻灯片详情';
) ENGINE=InnoDB DEFAULT CHARACTER SET = utf8mb4 COMMENT='幻灯片详情';
-- ----------------------------
-- Records of cms_slide_info