增加日志功能

This commit is contained in:
云泽网
2025-05-19 01:26:03 +08:00
parent 11fe0b4357
commit b947009126
9 changed files with 1169 additions and 531 deletions
+43
View File
@@ -8,6 +8,7 @@ use think\facade\Db;
use think\facade\View;
use think\facade\Request;
use app\admin\model\YzAdminConfig;
use app\admin\controller\Log;
class Yunzer extends Base{
# 菜单列表
@@ -25,6 +26,7 @@ class Yunzer extends Base{
if ($req->isPost()) {
$data['label'] = trim(input('post.label'));
if (empty($data['label'])) {
Log::record('添加菜单', 0, '请输入菜单名称', '菜单管理');
$this->returnCode(1, '请输入菜单名称');
}
$data['icon_class'] = trim(input('post.icon_class'));
@@ -34,11 +36,13 @@ class Yunzer extends Base{
if ($data['type'] == 1) {
$data['src'] = trim(input('post.src1'));
if (empty($data['src'])) {
Log::record('添加菜单', 0, '请输入内部跳转地址', '菜单管理');
$this->returnCode(1, '请输入内部跳转地址');
}
} else if ($data['type'] == 2) {
$data['src'] = trim(input('post.src2'));
if (empty($data['src'])) {
Log::record('添加菜单', 0, '请输入超链接地址', '菜单管理');
$this->returnCode(1, '请输入超链接地址');
}
} else {
@@ -47,6 +51,7 @@ class Yunzer extends Base{
// 保存菜单
$res = Db::table('yz_admin_sys_menu')->insert($data);
if (!$res) {
Log::record('添加菜单', 0, '添加菜单失败', '菜单管理');
$this->returnCode(1, '添加菜单失败');
}
@@ -73,6 +78,7 @@ class Yunzer extends Base{
}
}
Log::record('添加菜单', 1, '', '菜单管理');
$this->returnCode(0);
} else {
$iconfont = Db::table('yz_z_iconfont')->where('status', 1)->select();
@@ -89,6 +95,7 @@ class Yunzer extends Base{
$smid = (int)input('post.smid');
$data['label'] = trim(input('post.label'));
if(!$data['label']){
Log::record('编辑菜单', 0, '请输入菜单名称', '菜单管理');
$this->returnCode(1, '请输入菜单名称');
}
$data['icon_class'] = trim(input('post.icon_class'));
@@ -98,11 +105,13 @@ class Yunzer extends Base{
if($data['type'] == 1){
$data['src'] = trim(input('post.src1'));
if(empty($data['src'])){
Log::record('编辑菜单', 0, '请输入内部跳转地址', '菜单管理');
$this->returnCode(1, '请输入内部跳转地址');
}
}else if($data['type'] == 2){
$data['src'] = trim(input('post.src2'));
if(empty($data['src'])){
Log::record('编辑菜单', 0, '请输入超链接地址', '菜单管理');
$this->returnCode(1, '请输入超链接地址');
}
}else{
@@ -111,8 +120,10 @@ class Yunzer extends Base{
// 保存用户
$res = Db::table('yz_admin_sys_menu')->where('smid',$smid)->update($data);
if(!$res){
Log::record('编辑菜单', 0, '修改菜单失败', '菜单管理');
$this->returnCode(1, '修改菜单失败');
}
Log::record('编辑菜单', 1, '', '菜单管理');
$this->returnCode(0);
}else{
$smid = (int)input('get.smid');
@@ -130,12 +141,15 @@ class Yunzer extends Base{
$smid = (int)input('post.smid');
$count = Db::table('yz_admin_sys_menu')->where('parent_id',$smid)->count();
if($count > 0){
Log::record('删除菜单', 0, '该菜单下还有子菜单,不能删除', '菜单管理');
$this->returnCode(1, '该菜单下还有子菜单,不能删除');
}
$res = Db::table('yz_admin_sys_menu')->where('smid',$smid)->delete();
if(empty($res)){
Log::record('删除菜单', 0, '删除菜单失败', '菜单管理');
$this->returnCode(1, '删除菜单失败');
}
Log::record('删除菜单', 1, '', '菜单管理');
$this->returnCode(0);
}
# 按钮管理
@@ -173,6 +187,7 @@ class Yunzer extends Base{
$smid = (int)input('post.smid');
$data['label'] = trim(input('post.label'));
if(!$data['label']){
Log::record('添加按钮', 0, '请输入按钮名称', '按钮管理');
$this->returnCode(1, '请输入按钮名称');
}
$data['icon_class'] = trim(input('post.icon_class'));
@@ -180,24 +195,29 @@ class Yunzer extends Base{
$data['status'] = (int)trim(input('post.status'));
$data['type'] = (int)trim(input('post.type'));
if(empty($data['type'])){
Log::record('添加按钮', 0, '请选择按钮类型', '按钮管理');
$this->returnCode(1, '请选择按钮类型');
}
if($data['type'] == 1){
$data['src'] = trim(input('post.src1'));
if(empty($data['src'])){
Log::record('添加按钮', 0, '请输入内部跳转地址', '按钮管理');
$this->returnCode(1, '请输入内部跳转地址');
}
}else if($data['type'] == 2){
$data['src'] = trim(input('post.src2'));
if(empty($data['src'])){
Log::record('添加按钮', 0, '请输入超链接地址', '按钮管理');
$this->returnCode(1, '请输入超链接地址');
}
}
$data['parent_id'] = $smid;
$res = Db::table('yz_admin_sys_menu')->insert($data);
if(!$res){
Log::record('添加按钮', 0, '添加按钮失败', '按钮管理');
$this->returnCode(1, '添加按钮失败');
}
Log::record('添加按钮', 1, '', '按钮管理');
$this->returnCode(0);
}else{
$smid = (int)input('get.smid');
@@ -216,6 +236,7 @@ class Yunzer extends Base{
$smid = (int)input('post.smid');
$data['label'] = trim(input('post.label'));
if(!$data['label']){
Log::record('编辑按钮', 0, '请输入按钮名称', '按钮管理');
$this->returnCode(1, '请输入按钮名称');
}
$data['icon_class'] = trim(input('post.icon_class'));
@@ -223,23 +244,28 @@ class Yunzer extends Base{
$data['status'] = (int)trim(input('post.status'));
$data['type'] = (int)trim(input('post.type'));
if(empty($data['type'])){
Log::record('编辑按钮', 0, '请选择按钮类型', '按钮管理');
$this->returnCode(1, '请选择按钮类型');
}
if($data['type'] == 1){
$data['src'] = trim(input('post.src1'));
if(empty($data['src'])){
Log::record('编辑按钮', 0, '请输入内部跳转地址', '按钮管理');
$this->returnCode(1, '请输入内部跳转地址');
}
}else if($data['type'] == 2){
$data['src'] = trim(input('post.src2'));
if(empty($data['src'])){
Log::record('编辑按钮', 0, '请输入超链接地址', '按钮管理');
$this->returnCode(1, '请输入超链接地址');
}
}
$res = Db::table('yz_admin_sys_menu')->where('smid',$smid)->update($data);
if(!$res){
Log::record('编辑按钮', 0, '修改按钮失败', '按钮管理');
$this->returnCode(1, '修改按钮失败');
}
Log::record('编辑按钮', 1, '', '按钮管理');
$this->returnCode(0);
}else{
$smid = (int)input('get.smid');
@@ -257,8 +283,10 @@ class Yunzer extends Base{
$smid = (int)input('post.smid');
$res = Db::table('yz_admin_sys_menu')->where('smid',$smid)->delete();
if(empty($res)){
Log::record('删除按钮', 0, '删除按钮失败', '按钮管理');
$this->returnCode(1, '删除按钮失败');
}
Log::record('删除按钮', 1, '', '按钮管理');
$this->returnCode(0);
}
# 配置列表
@@ -280,10 +308,12 @@ class Yunzer extends Base{
if($req->isPost()){
$data['config_name'] = trim(input('post.config_name'));
if(empty($data['config_name'])){
Log::record('添加配置', 0, '请输入关键词', '系统配置');
$this->returnCode(1,'请输入关键词');
}
$data['config_info'] = trim(input('post.config_info'));
if(empty($data['config_info'])){
Log::record('添加配置', 0, '请输入作用', '系统配置');
$this->returnCode(1,'请输入作用');
}
$data['config_type'] = trim(input('post.config_type'));
@@ -292,8 +322,10 @@ class Yunzer extends Base{
$data['config_sort'] = trim(input('post.config_sort'));
$res = Db::table('yz_admin_config')->insert($data);
if(empty($res)){
Log::record('添加配置', 0, '添加配置失败', '系统配置');
$this->returnCode(1, '添加配置失败');
}
Log::record('添加配置', 1, '', '系统配置');
$this->returnCode(0);
}else{
return View::fetch();
@@ -305,14 +337,17 @@ class Yunzer extends Base{
if($req->isPost()){
$config_id = (int)input('post.config_id');
if(empty($config_id)){
Log::record('编辑配置', 0, '请选择一条数据', '系统配置');
$this->returnCode(1,'请选择一条数据');
}
$data['config_name'] = trim(input('post.config_name'));
if(empty($data['config_name'])){
Log::record('编辑配置', 0, '请输入关键词', '系统配置');
$this->returnCode(1,'请输入关键词');
}
$data['config_info'] = trim(input('post.config_info'));
if(empty($data['config_info'])){
Log::record('编辑配置', 0, '请输入作用', '系统配置');
$this->returnCode(1,'请输入作用');
}
$data['config_type'] = trim(input('post.config_type'));
@@ -321,8 +356,10 @@ class Yunzer extends Base{
$data['config_sort'] = trim(input('post.config_sort'));
$res = Db::table('yz_admin_config')->where('config_id',$config_id)->update($data);
if(empty($res)){
Log::record('编辑配置', 0, '修改配置失败', '系统配置');
$this->returnCode(1, '修改配置失败');
}
Log::record('编辑配置', 1, '', '系统配置');
$this->returnCode(0);
}else{
$config_id = (int)input('get.config_id');
@@ -337,12 +374,15 @@ class Yunzer extends Base{
public function configdel(){
$config_id = (int)input('post.config_id');
if(empty($config_id)){
Log::record('删除配置', 0, '请选择一条数据', '系统配置');
$this->returnCode(1,'请选择一条数据');
}
$res = Db::table('yz_admin_config')->where('config_id',$config_id)->delete();
if(empty($res)){
Log::record('删除配置', 0, '删除配置失败', '系统配置');
$this->returnCode(1, '删除配置失败');
}
Log::record('删除配置', 1, '', '系统配置');
$this->returnCode(0);
}
# 配置值
@@ -351,13 +391,16 @@ class Yunzer extends Base{
if($req->isPost()){
$post = input('post.');
if(empty($post)){
Log::record('更新配置值', 0, '数据不能为空', '系统配置');
$this->returnCode(1,'数据不能为空');
}
$oConfig = new YzAdminConfig();
$updateAll = $oConfig->updateAll($post);
if(empty($updateAll)){
Log::record('更新配置值', 0, '更新配置值失败', '系统配置');
$this->returnCode(1, '更新配置值失败');
}
Log::record('更新配置值', 1, '', '系统配置');
$this->returnCode(0);
}else{
$lists = Db::table('yz_admin_config')->order('config_sort DESC,config_id')->select();