first commit
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (c) 2021 勾股工作室
|
||||
* @license https://opensource.org/licenses/Apache-2.0
|
||||
* @link https://blog.gougucms.com
|
||||
*/
|
||||
|
||||
declare (strict_types = 1);
|
||||
|
||||
namespace app\admin\controller;
|
||||
|
||||
use app\base\BaseController;
|
||||
use app\admin\validate\ConfCheck;
|
||||
use think\exception\ValidateException;
|
||||
use think\facade\Db;
|
||||
use think\facade\View;
|
||||
|
||||
class Api
|
||||
// extends BaseController
|
||||
{
|
||||
//清空缓存
|
||||
public function cache_clear()
|
||||
{
|
||||
\think\facade\Cache::clear();
|
||||
return to_assign(0, '系统缓存已清空');
|
||||
}
|
||||
|
||||
//发送测试邮件
|
||||
public function email_to($email)
|
||||
{
|
||||
$name = empty(get_config('webconfig.admin_title')) ? '系统' : get_config('webconfig.admin_title');
|
||||
if (send_email($email, "一封来自{$name}的测试邮件。")) {
|
||||
return to_assign(0, '发送成功,请注意查收');
|
||||
}
|
||||
return to_assign(1, '发送失败');
|
||||
}
|
||||
|
||||
|
||||
|
||||
// 测试邮件发送
|
||||
public function email_test()
|
||||
{
|
||||
$sender = get_params('email');
|
||||
//检查是否邮箱格式
|
||||
if (!is_email($sender)) {
|
||||
return to_assign(1, '测试邮箱码格式有误');
|
||||
}
|
||||
$email_config = \think\facade\Db::name('config')
|
||||
->where('name', 'email')
|
||||
->find();
|
||||
$config = unserialize($email_config['content']);
|
||||
$content = $config['template'];
|
||||
print_r($content);
|
||||
//所有项目必须填写
|
||||
if (empty($config['smtp']) || empty($config['smtp_port']) || empty($config['smtp_user']) || empty($config['smtp_pwd'])) {
|
||||
return to_assign(1, '请完善邮件配置信息!');
|
||||
}
|
||||
|
||||
$send = send_email($sender, '测试邮件', $content);
|
||||
if ($send) {
|
||||
return to_assign(0, '邮件发送成功!');
|
||||
} else {
|
||||
return to_assign(1, '邮件发送失败!');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,119 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (c) 2023-2024 美天智能科技
|
||||
* @author 李志强
|
||||
* @link http://www.meteteme.com
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app\admin\controller;
|
||||
|
||||
use app\base\BaseController;
|
||||
use app\admin\validate\ConfCheck;
|
||||
use think\exception\ValidateException;
|
||||
use think\facade\Db;
|
||||
use think\facade\View;
|
||||
|
||||
class Conf extends BaseController
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
if (request()->isAjax()) {
|
||||
$param = get_params();
|
||||
$where = array();
|
||||
$where[] = ['status', '>=', 0];
|
||||
$rows = empty($param['limit']) ? get_config('app.page_size') : $param['limit'];
|
||||
$content = Db::name('Config')
|
||||
->where($where)
|
||||
->paginate($rows, false, ['query' => $param]);
|
||||
return table_assign(0, '', $content);
|
||||
} else {
|
||||
return view();
|
||||
}
|
||||
}
|
||||
|
||||
//添加/编辑配置项
|
||||
public function add()
|
||||
{
|
||||
$param = get_params();
|
||||
if (request()->isPost()) {
|
||||
try {
|
||||
validate(ConfCheck::class)->check($param);
|
||||
} catch (ValidateException $e) {
|
||||
// 验证失败 输出错误信息
|
||||
return to_assign(1, $e->getError());
|
||||
}
|
||||
if (!empty($param['id']) && $param['id'] > 0) {
|
||||
$param['update_time'] = time();
|
||||
$res = Db::name('config')->strict(false)->field(true)->update($param);
|
||||
if ($res) {
|
||||
add_log('edit', $param['id'], $param);
|
||||
}
|
||||
return to_assign();
|
||||
} else {
|
||||
$param['create_time'] = time();
|
||||
$insertId = Db::name('Config')->strict(false)->field(true)->insertGetId($param);
|
||||
if ($insertId) {
|
||||
add_log('add', $insertId, $param);
|
||||
}
|
||||
return to_assign();
|
||||
}
|
||||
} else {
|
||||
$id = isset($param['id']) ? $param['id'] : 0;
|
||||
if ($id > 0) {
|
||||
$config = Db::name('Config')->where(['id' => $id])->find();
|
||||
View::assign('config', $config);
|
||||
}
|
||||
View::assign('id', $id);
|
||||
return view();
|
||||
}
|
||||
}
|
||||
|
||||
//删除配置项
|
||||
public function delete()
|
||||
{
|
||||
if (request()->isDelete()) {
|
||||
$id = get_params("id");
|
||||
$data['status'] = '-1';
|
||||
$data['id'] = $id;
|
||||
$data['update_time'] = time();
|
||||
if (Db::name('Config')->update($data) !== false) {
|
||||
add_log('delete', $id, $data);
|
||||
return to_assign(0, "删除成功");
|
||||
} else {
|
||||
return to_assign(1, "删除失败");
|
||||
}
|
||||
} else {
|
||||
return to_assign(1, "错误的请求");
|
||||
}
|
||||
}
|
||||
|
||||
//编辑配置信息
|
||||
public function edit()
|
||||
{
|
||||
$param = get_params();
|
||||
if (request()->isPost()) {
|
||||
$data['content'] = serialize($param);
|
||||
$data['update_time'] = time();
|
||||
$data['id'] = $param['id'];
|
||||
$res = Db::name('Config')->strict(false)->field(true)->update($data);
|
||||
$conf = Db::name('Config')->where('id', $param['id'])->find();
|
||||
clear_cache('system_config' . $conf['name']);
|
||||
if ($res) {
|
||||
add_log('edit', $param['id'], $param);
|
||||
}
|
||||
return to_assign();
|
||||
} else {
|
||||
$id = isset($param['id']) ? $param['id'] : 0;
|
||||
$conf = Db::name('Config')->where('id', $id)->find();
|
||||
$config = [];
|
||||
if ($conf['content']) {
|
||||
$config = unserialize($conf['content']);
|
||||
}
|
||||
View::assign('id', $id);
|
||||
View::assign('config', $config);
|
||||
return view($conf['name']);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,223 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (c) 2023-2024 美天智能科技
|
||||
* @author 李志强
|
||||
* @link http://www.meteteme.com
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app\admin\controller;
|
||||
|
||||
use app\base\BaseController;
|
||||
use backup\Backup;
|
||||
use think\facade\Session;
|
||||
use think\facade\Db;
|
||||
use think\facade\View;
|
||||
|
||||
class Database extends BaseController
|
||||
{
|
||||
//数据表列表
|
||||
public function database()
|
||||
{
|
||||
if (request()->isAjax()) {
|
||||
// 数据信息
|
||||
$db = new Backup();
|
||||
$list = $db->dataList();
|
||||
// 计算总大小
|
||||
$total = 0;
|
||||
foreach ($list as $k => $v) {
|
||||
$total += $v['data_length'];
|
||||
$list[$k]['data_size'] = $v['data_length'];
|
||||
$list[$k]['data_length'] = format_bytes($v['data_length']);
|
||||
}
|
||||
// 提示信息
|
||||
$dataTips = '数据库中共有<strong> ' . count($list) . '</strong> 张表,共计 <strong>' . format_bytes($total) . '</strong>大小。';
|
||||
$data['data'] = $list;
|
||||
return table_assign(0, $dataTips, $data);
|
||||
}
|
||||
return view();
|
||||
}
|
||||
|
||||
//备份数据
|
||||
public function backup()
|
||||
{
|
||||
$db = new Backup();
|
||||
if (request()->isPost()) {
|
||||
$tables = get_params('tables');
|
||||
$fileinfo = $db->getFile();
|
||||
//检查是否有正在执行的任务
|
||||
$lock = "{$fileinfo['filepath']}backup.lock";
|
||||
if (is_file($lock)) {
|
||||
return to_assign(2, '检测到有一个备份任务未完成');
|
||||
} else {
|
||||
//创建锁文件
|
||||
file_put_contents($lock, time());
|
||||
}
|
||||
// 检查备份目录是否可写
|
||||
if (!is_writeable($fileinfo['filepath'])) {
|
||||
return to_assign(1, '备份目录不存在或不可写,请检查后重试!');
|
||||
}
|
||||
|
||||
//缓存锁文件
|
||||
Session::set('lock', $lock);
|
||||
//缓存备份文件信息
|
||||
Session::set('backup_file', $fileinfo['file']);
|
||||
//缓存要备份的表
|
||||
Session::set('backup_tables', $tables);
|
||||
//创建备份文件
|
||||
if (false !== $db->Backup_Init()) {
|
||||
return to_assign(0, '初始化成功,开始备份...', ['tab' => ['id' => 0, 'start' => 0, 'table' => $tables[0]]]);
|
||||
} else {
|
||||
return to_assign(1, '初始化失败,备份文件创建失败!');
|
||||
}
|
||||
} else if (request()->isGet()) {
|
||||
$tables = Session::get('backup_tables');
|
||||
$file = Session::get('backup_file');
|
||||
$id = get_params('id');
|
||||
$start = get_params('start');
|
||||
$start = $db->setFile($file)->backup($tables[$id], $start);
|
||||
if (false === $start) {
|
||||
return to_assign(1, '备份出错');
|
||||
} else if (0 === $start) {
|
||||
if (isset($tables[++$id])) {
|
||||
return to_assign(0, '备份完成', ['tab' => ['id' => $id, 'start' => 0, 'table' => $tables[$id - 1]]]);
|
||||
} else { //备份完成,清空缓存
|
||||
unlink(Session::get('lock'));
|
||||
Session::delete('backup_tables');
|
||||
Session::delete('backup_file');
|
||||
add_log('bak');
|
||||
return to_assign(0, '备份完成', ['tab' => ['start' => 'ok', 'table' => $tables[$id - 1]]]);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return to_assign(1, '参数错误!');
|
||||
}
|
||||
}
|
||||
|
||||
//优化表
|
||||
public function optimize($tables = null)
|
||||
{
|
||||
$db = new Backup();
|
||||
//return to_assign(0, $db->optimize($tables));
|
||||
if ($db->optimize($tables)) {
|
||||
add_log('optimize');
|
||||
return to_assign(0, '数据表优化完成');
|
||||
} else {
|
||||
return to_assign(1, '数据表优化出错请重试');
|
||||
}
|
||||
}
|
||||
|
||||
//修复表
|
||||
public function repair($tables = null)
|
||||
{
|
||||
$db = new Backup();
|
||||
//return to_assign(0, $db->repair($tables));
|
||||
if ($db->repair($tables)) {
|
||||
add_log('repair');
|
||||
return to_assign(0, '数据表修复完成');
|
||||
} else {
|
||||
return to_assign(1, '数据表修复出错请重试');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//备份文件列表
|
||||
public function backuplist()
|
||||
{
|
||||
$db = new Backup();
|
||||
$list = $db->fileList();
|
||||
$fileinfo = $db->getFile();
|
||||
$lock = "{$fileinfo['filepath']}backup.lock";
|
||||
$lock_time = 0;
|
||||
if (is_file($lock)) {
|
||||
$lock_time = file_get_contents($lock);
|
||||
}
|
||||
$listNew = [];
|
||||
$indx = 0;
|
||||
foreach ($list as $k => $v) {
|
||||
$listNew[$indx]['time'] = $k;
|
||||
$listNew[$indx]['timespan'] = $v['time'];
|
||||
$listNew[$indx]['data'] = $v;
|
||||
$indx++;
|
||||
}
|
||||
$list = $listNew;
|
||||
array_multisort(array_column($list, 'time'), SORT_DESC, $list);
|
||||
return view('', ['list' => $list, 'lock_time' => $lock_time]);
|
||||
}
|
||||
|
||||
//数据还原
|
||||
public function import($time = 0, $part = null, $start = null)
|
||||
{
|
||||
$db = new Backup();
|
||||
$time = (int) $time;
|
||||
if (is_numeric($time) && is_null($part) && is_null($start)) {
|
||||
$list = $db->getFile('timeverif', $time);
|
||||
if (is_array($list)) {
|
||||
Session::set('backup_list', $list);
|
||||
return to_assign(0, '初始化完成,开始还原...', array('part' => 1, 'start' => 0, 'time' => $time));
|
||||
} else {
|
||||
return to_assign(1, '备份文件可能已经损坏,请检查');
|
||||
}
|
||||
} else if (is_numeric($part) && is_numeric($start)) {
|
||||
$list = Session::get('backup_list');
|
||||
$part = (int) $part;
|
||||
$start = (int) $start;
|
||||
$start = $db->setFile($list)->import($start, $time, $part);
|
||||
if (false === $start) {
|
||||
return to_assign(1, '还原数据出错,请重试');
|
||||
} elseif (0 === $start) {
|
||||
if (isset($list[++$part])) {
|
||||
$data = array('part' => $part, 'start' => 0, 'time' => $time);
|
||||
return to_assign(0, "正在还原...卷{$part},请勿关闭当前页面", $data);
|
||||
} else {
|
||||
Session::delete('backup_list');
|
||||
return to_assign(0, '还原数据成功');
|
||||
}
|
||||
} else {
|
||||
$data = array('part' => $part, 'start' => $start[0], 'time' => $time);
|
||||
if ($start[1]) {
|
||||
$rate = floor(100 * ($start[0] / $start[1]));
|
||||
return to_assign(0, "正在还原...卷{$part} ({$rate}%),请勿关闭当前页面", $data);
|
||||
} else {
|
||||
$data['gz'] = 1;
|
||||
return to_assign(0, "正在还原...卷{$part},请勿关闭当前页面", $data);
|
||||
}
|
||||
return to_assign(0, "正在还原...卷{$part},请勿关闭当前页面");
|
||||
}
|
||||
} else {
|
||||
return to_assign(1, "参数错误");
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 删除备份文件
|
||||
*/
|
||||
public function del($time = 0, $lock = 0)
|
||||
{
|
||||
$db = new Backup();
|
||||
if ($lock == 1) {
|
||||
$fileinfo = $db->getFile();
|
||||
$lock = "{$fileinfo['filepath']}backup.lock";
|
||||
if (is_file($lock)) {
|
||||
$time = file_get_contents($lock);
|
||||
unlink($lock);
|
||||
}
|
||||
}
|
||||
if ($db->delFile((int) $time)) {
|
||||
add_log('delete');
|
||||
return to_assign(0, '删除成功');
|
||||
} else {
|
||||
return to_assign(0, '删除失败,请检查权限');
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 下载备份文件
|
||||
*/
|
||||
public function downfile($time = 0, $part = 0)
|
||||
{
|
||||
$db = new Backup();
|
||||
add_log('down');
|
||||
$db->downloadFile((int) $time, $part - 1);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (c) 2023-2024 美天智能科技
|
||||
* @author 李志强
|
||||
* @link http://www.meteteme.com
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app\admin\controller;
|
||||
|
||||
use app\base\BaseController;
|
||||
use app\admin\validate\DepartmentCheck;
|
||||
use think\exception\ValidateException;
|
||||
use think\facade\Db;
|
||||
use think\facade\View;
|
||||
|
||||
class Department extends BaseController
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
if (request()->isAjax()) {
|
||||
$list = Db::name('Department')
|
||||
->field('d.*,a.name as leader')
|
||||
->alias('d')
|
||||
->join('Admin a', 'a.id = d.leader_id', 'LEFT')
|
||||
->order('d.id asc')
|
||||
->select();
|
||||
return to_assign(0, '', $list);
|
||||
} else {
|
||||
return view();
|
||||
}
|
||||
}
|
||||
|
||||
//添加部门
|
||||
public function add()
|
||||
{
|
||||
$param = get_params();
|
||||
if (request()->isPost()) {
|
||||
if ($param['id'] > 0) {
|
||||
try {
|
||||
validate(DepartmentCheck::class)->scene('edit')->check($param);
|
||||
} catch (ValidateException $e) {
|
||||
// 验证失败 输出错误信息
|
||||
return to_assign(1, $e->getError());
|
||||
}
|
||||
$param['update_time'] = time();
|
||||
$department_array = get_department_son($param['id']);
|
||||
if (in_array($param['pid'], $department_array)) {
|
||||
return to_assign(1, '上级部门不能是该部门本身或其下属部门');
|
||||
} else {
|
||||
Db::name('Department')->strict(false)->field(true)->update($param);
|
||||
add_log('edit', $param['id'], $param);
|
||||
return to_assign();
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
validate(DepartmentCheck::class)->scene('add')->check($param);
|
||||
} catch (ValidateException $e) {
|
||||
// 验证失败 输出错误信息
|
||||
return to_assign(1, $e->getError());
|
||||
}
|
||||
$did = Db::name('Department')->strict(false)->field(true)->insertGetId($param);
|
||||
add_log('add', $did, $param);
|
||||
return to_assign();
|
||||
}
|
||||
} else {
|
||||
$id = isset($param['id']) ? $param['id'] : 0;
|
||||
$pid = isset($param['pid']) ? $param['pid'] : 0;
|
||||
$department = set_recursion(get_department());
|
||||
if ($id > 0) {
|
||||
$detail = Db::name('Department')->where(['id' => $id])->find();
|
||||
$users = Db::name('Admin')->where(['did' => $id, 'status' => 1])->select();
|
||||
View::assign('users', $users);
|
||||
View::assign('detail', $detail);
|
||||
}
|
||||
View::assign('department', $department);
|
||||
View::assign('pid', $pid);
|
||||
View::assign('id', $id);
|
||||
return view();
|
||||
}
|
||||
}
|
||||
|
||||
//删除
|
||||
public function delete()
|
||||
{
|
||||
if (request()->isDelete()) {
|
||||
$id = get_params("id");
|
||||
$count = Db::name('Department')->where([['pid', '=', $id], ['status', '>=', 0]])->count();
|
||||
if ($count > 0) {
|
||||
return to_assign(1, "该部门下还有子部门,无法删除");
|
||||
}
|
||||
$users = Db::name('Admin')->where([['did', '=', $id], ['status', '>=', 0]])->count();
|
||||
if ($users > 0) {
|
||||
return to_assign(1, "该部门下还有员工,无法删除");
|
||||
}
|
||||
if (Db::name('Department')->delete($id) !== false) {
|
||||
add_log('delete', $id);
|
||||
return to_assign(0, "删除成功");
|
||||
} else {
|
||||
return to_assign(1, "删除失败");
|
||||
}
|
||||
} else {
|
||||
return to_assign(1, "错误的请求");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,117 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (c) 2023-2024 美天智能科技
|
||||
* @author 李志强
|
||||
* @link http://www.meteteme.com
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app\admin\controller;
|
||||
|
||||
use app\base\BaseController;
|
||||
use app\admin\validate\KnowledgeCateCheck;
|
||||
use think\exception\ValidateException;
|
||||
use think\facade\Db;
|
||||
use think\facade\View;
|
||||
|
||||
class Kcate extends BaseController
|
||||
{
|
||||
//知识类别
|
||||
public function index()
|
||||
{
|
||||
if (request()->isAjax()) {
|
||||
$cate = Db::name('KnowledgeCate')->order('create_time asc')->select();
|
||||
return to_assign(0, '', $cate);
|
||||
} else {
|
||||
return view();
|
||||
}
|
||||
}
|
||||
|
||||
public function tags()
|
||||
{
|
||||
if (request()->isAjax()) {
|
||||
$cate = Db::name('KnowledgeTags')->order('id asc')->select();
|
||||
return to_assign(0, '', $cate);
|
||||
} else {
|
||||
return view();
|
||||
}
|
||||
}
|
||||
|
||||
//知识分类添加&编辑
|
||||
public function add()
|
||||
{
|
||||
$param = get_params();
|
||||
if (request()->isPost()) {
|
||||
if (!empty($param['id']) && $param['id'] > 0) {
|
||||
try {
|
||||
validate(KnowledgeCateCheck::class)->scene('edit')->check($param);
|
||||
} catch (ValidateException $e) {
|
||||
// 验证失败 输出错误信息
|
||||
return to_assign(1, $e->getError());
|
||||
}
|
||||
$cate_array = admin_knowledge_cate_son($param['id']);
|
||||
if (in_array($param['pid'], $cate_array)) {
|
||||
return to_assign(1, '父级分类不能是该分类本身或其子分类');
|
||||
} else {
|
||||
$param['update_time'] = time();
|
||||
$res = Db::name('KnowledgeCate')->strict(false)->field(true)->update($param);
|
||||
if ($res) {
|
||||
add_log('edit', $param['id'], $param);
|
||||
return to_assign();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
validate(KnowledgeCateCheck::class)->scene('add')->check($param);
|
||||
} catch (ValidateException $e) {
|
||||
// 验证失败 输出错误信息
|
||||
return to_assign(1, $e->getError());
|
||||
}
|
||||
$param['create_time'] = time();
|
||||
$insertId = Db::name('KnowledgeCate')->strict(false)->field(true)->insertGetId($param);
|
||||
if ($insertId) {
|
||||
add_log('add', $insertId, $param);
|
||||
}
|
||||
return to_assign();
|
||||
}
|
||||
} else {
|
||||
$id = isset($param['id']) ? $param['id'] : 0;
|
||||
$pid = isset($param['pid']) ? $param['pid'] : 0;
|
||||
$cate = Db::name('KnowledgeCate')->order('id desc')->select()->toArray();
|
||||
$cates = set_recursion($cate);
|
||||
if ($id > 0) {
|
||||
$detail = Db::name('KnowledgeCate')->where(['id' => $id])->find();
|
||||
View::assign('detail', $detail);
|
||||
}
|
||||
View::assign('id', $id);
|
||||
View::assign('pid', $pid);
|
||||
View::assign('cates', $cates);
|
||||
return view();
|
||||
}
|
||||
}
|
||||
|
||||
//删除知识分类
|
||||
public function delete()
|
||||
{
|
||||
if (request()->isDelete()) {
|
||||
$id = get_params("id");
|
||||
$cate_count = Db::name('KnowledgeCate')->where(["pid" => $id])->count();
|
||||
if ($cate_count > 0) {
|
||||
return to_assign(1, "该分类下还有子分类,无法删除");
|
||||
}
|
||||
$content_count = Db::name('Knowledge')->where(["cate_id" => $id])->count();
|
||||
if ($content_count > 0) {
|
||||
return to_assign(1, "该分类下还有文档,无法删除");
|
||||
}
|
||||
if (Db::name('KnowledgeCate')->delete($id) !== false) {
|
||||
add_log('delete', $id);
|
||||
return to_assign(0, "删除成功");
|
||||
} else {
|
||||
return to_assign(1, "删除失败");
|
||||
}
|
||||
} else {
|
||||
return to_assign(1, "错误的请求");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (c) 2023-2024 美天智能科技
|
||||
* @author 李志强
|
||||
* @link http://www.meteteme.com
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app\admin\controller;
|
||||
|
||||
use app\base\BaseController;
|
||||
use think\facade\Db;
|
||||
use think\facade\View;
|
||||
|
||||
class Log extends BaseController
|
||||
{
|
||||
//管理员操作日志
|
||||
public function index()
|
||||
{
|
||||
if (request()->isAjax()) {
|
||||
$param = get_params();
|
||||
$where = array();
|
||||
if (!empty($param['keywords'])) {
|
||||
$where[] = ['name|rule_menu|param_id', 'like', '%' . $param['keywords'] . '%'];
|
||||
}
|
||||
if (!empty($param['action'])) {
|
||||
$where['action'] = $param['action'];
|
||||
}
|
||||
$rows = empty($param['limit']) ? get_config('app.page_size') : $param['limit'];
|
||||
$content = DB::name('AdminLog')
|
||||
->field("id,uid,name,action,title,content,rule_menu,ip,param_id,param,FROM_UNIXTIME(create_time,'%Y-%m-%d %H:%i:%s') 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);
|
||||
if (is_array($param_array)) {
|
||||
$param_value = '';
|
||||
foreach ($param_array as $key => $value) {
|
||||
if (is_array($value)) {
|
||||
$value = implode(',', $value);
|
||||
}
|
||||
$param_value .= $key . ':' . $value . ' | ';
|
||||
}
|
||||
$data['param'] = $param_value;
|
||||
} else {
|
||||
$data['param'] = $param_array;
|
||||
}
|
||||
$content->offsetSet($k, $data);
|
||||
}
|
||||
return table_assign(0, '', $content);
|
||||
} else {
|
||||
$type_action = get_config('log.type_action');
|
||||
View::assign('type_action', $type_action);
|
||||
return view();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (c) 2023 李志强
|
||||
* @author 李志强
|
||||
* @link https://www.yunzer.cn
|
||||
*/
|
||||
namespace app\admin\controller;
|
||||
|
||||
use app\base\BaseController;
|
||||
use app\admin\validate\ConfCheck;
|
||||
use think\exception\ValidateException;
|
||||
use think\facade\Db;
|
||||
use think\facade\View;
|
||||
use PHPMailer\PHPMailer\PHPMailer;
|
||||
use PHPMailer\PHPMailer\SMTP;
|
||||
use PHPMailer\PHPMailer\Exception;
|
||||
|
||||
class Mail extends BaseController
|
||||
{
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,107 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (c) 2023-2024 美天智能科技
|
||||
* @author 李志强
|
||||
* @link http://www.meteteme.com
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app\admin\controller;
|
||||
|
||||
use app\base\BaseController;
|
||||
use app\admin\validate\NoteCateCheck;
|
||||
use think\exception\ValidateException;
|
||||
use think\facade\Db;
|
||||
use think\facade\View;
|
||||
|
||||
class Ncate extends BaseController
|
||||
{
|
||||
//公告类别
|
||||
public function index()
|
||||
{
|
||||
if (request()->isAjax()) {
|
||||
$cate = Db::name('NoteCate')->order('create_time asc')->select();
|
||||
return to_assign(0, '', $cate);
|
||||
} else {
|
||||
return view();
|
||||
}
|
||||
}
|
||||
|
||||
//公告类别添加
|
||||
public function add()
|
||||
{
|
||||
$param = get_params();
|
||||
if (request()->isPost()) {
|
||||
if (!empty($param['id']) && $param['id'] > 0) {
|
||||
try {
|
||||
validate(NoteCateCheck::class)->scene('edit')->check($param);
|
||||
} catch (ValidateException $e) {
|
||||
// 验证失败 输出错误信息
|
||||
return to_assign(1, $e->getError());
|
||||
}
|
||||
$note_array = admin_note_cate_son($param['id']);
|
||||
if (in_array($param['pid'], $note_array)) {
|
||||
return to_assign(1, '父级分类不能是该分类本身或其子分类');
|
||||
} else {
|
||||
$param['update_time'] = time();
|
||||
$res = Db::name('NoteCate')->strict(false)->field(true)->update($param);
|
||||
if ($res) {
|
||||
add_log('edit', $param['id'], $param);
|
||||
}
|
||||
return to_assign();
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
validate(NoteCateCheck::class)->scene('add')->check($param);
|
||||
} catch (ValidateException $e) {
|
||||
// 验证失败 输出错误信息
|
||||
return to_assign(1, $e->getError());
|
||||
}
|
||||
$param['create_time'] = time();
|
||||
$insertId = Db::name('NoteCate')->strict(false)->field(true)->insertGetId($param);
|
||||
if ($insertId) {
|
||||
add_log('add', $insertId, $param);
|
||||
}
|
||||
return to_assign();
|
||||
}
|
||||
} else {
|
||||
$id = isset($param['id']) ? $param['id'] : 0;
|
||||
$pid = isset($param['pid']) ? $param['pid'] : 0;
|
||||
$cate = $cate = Db::name('NoteCate')->order('id desc')->select()->toArray();
|
||||
$cates = set_recursion($cate);
|
||||
if ($id > 0) {
|
||||
$detail = Db::name('NoteCate')->where(['id' => $id])->find();
|
||||
View::assign('detail', $detail);
|
||||
}
|
||||
View::assign('id', $id);
|
||||
View::assign('pid', $pid);
|
||||
View::assign('cates', $cates);
|
||||
return view();
|
||||
}
|
||||
}
|
||||
|
||||
//公告类别删除
|
||||
public function delete()
|
||||
{
|
||||
if (request()->isDelete()) {
|
||||
$id = get_params("id");
|
||||
$cate_count = Db::name('NoteCate')->where(["pid" => $id])->count();
|
||||
if ($cate_count > 0) {
|
||||
return to_assign(1, "该分类下还有子分类,无法删除");
|
||||
}
|
||||
$content_count = Db::name('Note')->where(["cate_id" => $id])->count();
|
||||
if ($content_count > 0) {
|
||||
return to_assign(1, "该分类下还有公告,无法删除");
|
||||
}
|
||||
if (Db::name('NoteCate')->delete($id) !== false) {
|
||||
add_log('delete', $id);
|
||||
return to_assign(0, "删除成功");
|
||||
} else {
|
||||
return to_assign(1, "删除失败");
|
||||
}
|
||||
} else {
|
||||
return to_assign(1, "错误的请求");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,136 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (c) 2023-2024 美天智能科技
|
||||
* @author 李志强
|
||||
* @link http://www.meteteme.com
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app\admin\controller;
|
||||
|
||||
use app\admin\validate\NoteCheck;
|
||||
use app\base\BaseController;
|
||||
use app\model\Note as NoteList;
|
||||
use think\exception\ValidateException;
|
||||
use think\facade\Db;
|
||||
use think\facade\View;
|
||||
|
||||
class Note extends BaseController
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
if (request()->isAjax()) {
|
||||
$param = get_params();
|
||||
$where = array();
|
||||
if (!empty($param['keywords'])) {
|
||||
$where[] = ['a.title|a.content', 'like', '%' . $param['keywords'] . '%'];
|
||||
}
|
||||
$where[] = ['a.delete_time', '=', 0];
|
||||
$rows = empty($param['limit']) ? get_config('app.page_size') : $param['limit'];
|
||||
$note = NoteList::where($where)
|
||||
->field('a.*,c.title as cate_title')
|
||||
->alias('a')
|
||||
->join('NoteCate c', 'a.cate_id = c.id', 'LEFT')
|
||||
->order('a.create_time desc')
|
||||
->paginate($rows, false, ['query' => $param])
|
||||
->each(function ($item, $key) {
|
||||
$item->start_time = empty($item->start_time) ? '-' : date('Y-m-d', $item->start_time);
|
||||
$item->end_time = empty($item->end_time) ? '-' : date('Y-m-d', $item->end_time);
|
||||
});
|
||||
return table_assign(0, '', $note);
|
||||
} else {
|
||||
return view();
|
||||
}
|
||||
}
|
||||
|
||||
//添加
|
||||
public function add()
|
||||
{
|
||||
$param = get_params();
|
||||
if (request()->isPost()) {
|
||||
//markdown数据处理
|
||||
if (isset($param['table-align'])) {
|
||||
unset($param['table-align']);
|
||||
}
|
||||
if (isset($param['docContent-html-code'])) {
|
||||
$param['content'] = $param['docContent-html-code'];
|
||||
$param['md_content'] = $param['docContent-markdown-doc'];
|
||||
unset($param['docContent-html-code']);
|
||||
unset($param['docContent-markdown-doc']);
|
||||
}
|
||||
if (isset($param['ueditorcontent'])) {
|
||||
$param['content'] = $param['ueditorcontent'];
|
||||
$param['md_content'] = '';
|
||||
}
|
||||
|
||||
$param['start_time'] = isset($param['start_time']) ? strtotime(urldecode($param['start_time'])) : 0;
|
||||
$param['end_time'] = isset($param['end_time']) ? strtotime(urldecode($param['end_time'])) : 0;
|
||||
if (!empty($param['id']) && $param['id'] > 0) {
|
||||
try {
|
||||
validate(NoteCheck::class)->scene('edit')->check($param);
|
||||
} catch (ValidateException $e) {
|
||||
// 验证失败 输出错误信息
|
||||
return to_assign(1, $e->getError());
|
||||
}
|
||||
$param['update_time'] = time();
|
||||
$res = NoteList::where('id', $param['id'])->strict(false)->field(true)->update($param);
|
||||
if ($res) {
|
||||
add_log('edit', $param['id'], $param);
|
||||
}
|
||||
|
||||
return to_assign();
|
||||
} else {
|
||||
try {
|
||||
validate(NoteCheck::class)->scene('add')->check($param);
|
||||
} catch (ValidateException $e) {
|
||||
// 验证失败 输出错误信息
|
||||
return to_assign(1, $e->getError());
|
||||
}
|
||||
$param['create_time'] = time();
|
||||
$sid = NoteList::strict(false)->field(true)->insertGetId($param);
|
||||
if ($sid) {
|
||||
add_log('add', $sid, $param);
|
||||
$users = Db::name('Admin')->where(['status' => 1])->column('id');
|
||||
sendMessage($users, 1, ['title' => $param['title'], 'from_uid' => $this->uid, 'action_id' => $sid]);
|
||||
}
|
||||
return to_assign();
|
||||
}
|
||||
} else {
|
||||
$id = isset($param['id']) ? $param['id'] : 0;
|
||||
if ($id > 0) {
|
||||
$note = Db::name('Note')->where(['id' => $id])->find();
|
||||
View::assign('note', $note);
|
||||
}
|
||||
View::assign('id', $id);
|
||||
return view();
|
||||
}
|
||||
}
|
||||
|
||||
//查看
|
||||
public function view()
|
||||
{
|
||||
$id = empty(get_params('id')) ? 0 : get_params('id');
|
||||
$note = Db::name('Note')->where(['id' => $id])->find();
|
||||
View::assign('note', $note);
|
||||
return view();
|
||||
}
|
||||
|
||||
//删除
|
||||
public function delete()
|
||||
{
|
||||
if (request()->isDelete()) {
|
||||
$id = get_params("id");
|
||||
$data['delete_time'] = time();
|
||||
$data['id'] = $id;
|
||||
if (Db::name('Note')->update($data) !== false) {
|
||||
add_log('delete', $id);
|
||||
return to_assign(0, "删除成功");
|
||||
} else {
|
||||
return to_assign(0, "删除失败");
|
||||
}
|
||||
} else {
|
||||
return to_assign(1, "错误的请求");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,180 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (c) 2023-2024 美天智能科技
|
||||
* @author 李志强
|
||||
* @link http://www.meteteme.com
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app\admin\controller;
|
||||
|
||||
use app\base\BaseController;
|
||||
use app\admin\validate\PositionCheck;
|
||||
use think\exception\ValidateException;
|
||||
use think\facade\Db;
|
||||
use think\facade\View;
|
||||
|
||||
class Position extends BaseController
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
if (request()->isAjax()) {
|
||||
$list = Db::name('Position')->where('status', '>=', 0)->order('create_time asc')->select()->toArray();
|
||||
foreach ($list as &$val) {
|
||||
$groupId = Db::name('PositionGroup')->where(['pid' => $val['id']])->column('group_id');
|
||||
$groupName = Db::name('AdminGroup')->where('id', 'in', $groupId)->column('title');
|
||||
$val['groupName'] = implode(',', $groupName);
|
||||
}
|
||||
$res['data'] = $list;
|
||||
return table_assign(0, '', $res);
|
||||
} else {
|
||||
return view();
|
||||
}
|
||||
}
|
||||
|
||||
//添加&编辑
|
||||
public function add()
|
||||
{
|
||||
$param = get_params();
|
||||
if (request()->isPost()) {
|
||||
if (!empty($param['id']) && $param['id'] > 0) {
|
||||
try {
|
||||
validate(PositionCheck::class)->scene('edit')->check($param);
|
||||
} catch (ValidateException $e) {
|
||||
// 验证失败 输出错误信息
|
||||
return to_assign(1, $e->getError());
|
||||
}
|
||||
// 启动事务
|
||||
Db::startTrans();
|
||||
try {
|
||||
Db::name('Position')->where(['id' => $param['id']])->strict(false)->field(true)->update($param);
|
||||
Db::name('PositionGroup')->where(['pid' => $param['id']])->delete();
|
||||
foreach ($param['group_id'] as $k => $v) {
|
||||
$data[$k] = [
|
||||
'pid' => $param['id'],
|
||||
'group_id' => $v,
|
||||
'create_time' => time(),
|
||||
];
|
||||
}
|
||||
Db::name('PositionGroup')->strict(false)->field(true)->insertAll($data);
|
||||
add_log('edit', $param['id'], $param);
|
||||
//清除菜单\权限缓存
|
||||
clear_cache('adminMenu');
|
||||
clear_cache('adminRules');
|
||||
// 提交事务
|
||||
Db::commit();
|
||||
} catch (\Exception $e) {
|
||||
// 回滚事务
|
||||
Db::rollback();
|
||||
return to_assign(1, '提交失败:' . $e->getMessage());
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
validate(PositionCheck::class)->scene('add')->check($param);
|
||||
} catch (ValidateException $e) {
|
||||
// 验证失败 输出错误信息
|
||||
return to_assign(1, $e->getError());
|
||||
}
|
||||
// 启动事务
|
||||
Db::startTrans();
|
||||
try {
|
||||
$uid = Db::name('Position')->strict(false)->field(true)->insertGetId($param);
|
||||
foreach ($param['group_id'] as $k => $v) {
|
||||
$data[$k] = [
|
||||
'pid' => $uid,
|
||||
'group_id' => $v,
|
||||
'create_time' => time(),
|
||||
];
|
||||
}
|
||||
Db::name('PositionGroup')->strict(false)->field(true)->insertAll($data);
|
||||
add_log('add', $uid, $param);
|
||||
// 提交事务
|
||||
Db::commit();
|
||||
} catch (\Exception $e) {
|
||||
// 回滚事务
|
||||
Db::rollback();
|
||||
return to_assign(1, '提交失败:' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
return to_assign();
|
||||
} else {
|
||||
$id = isset($param['id']) ? $param['id'] : 0;
|
||||
$group = Db::name('AdminGroup')->order('create_time asc')->select()->toArray();
|
||||
if ($id > 0) {
|
||||
$detail = Db::name('Position')->where(['id' => $id])->find();
|
||||
$detail['group_id'] = Db::name('PositionGroup')->where(['pid' => $id])->column('group_id');
|
||||
foreach ($group as &$val) {
|
||||
if (in_array($val['id'], $detail['group_id'])) {
|
||||
$val['checked'] = 1;
|
||||
} else {
|
||||
$val['checked'] = 0;
|
||||
}
|
||||
}
|
||||
View::assign('detail', $detail);
|
||||
}
|
||||
View::assign('group', $group);
|
||||
View::assign('id', $id);
|
||||
return view();
|
||||
}
|
||||
}
|
||||
|
||||
//查看
|
||||
public function view()
|
||||
{
|
||||
$id = get_params('id');
|
||||
$group = Db::name('AdminGroup')->order('create_time asc')->select()->toArray();
|
||||
$detail = Db::name('Position')->where(['id' => $id])->find();
|
||||
$detail['group_id'] = Db::name('PositionGroup')->where(['pid' => $id])->column('group_id');
|
||||
foreach ($group as &$val) {
|
||||
if (in_array($val['id'], $detail['group_id'])) {
|
||||
$val['checked'] = 1;
|
||||
} else {
|
||||
$val['checked'] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
$rule = Db::name('AdminRule')->order('sort asc,id asc')->select()->toArray();
|
||||
$user_groups = Db::name('PositionGroup')
|
||||
->alias('a')
|
||||
->join("AdminGroup g", "a.group_id=g.id", 'LEFT')
|
||||
->where("a.pid='{$id}' and g.status='1'")
|
||||
->select()
|
||||
->toArray();
|
||||
$groups = $user_groups ?: [];
|
||||
|
||||
$rules = [];
|
||||
foreach ($groups as $g) {
|
||||
$rules = array_merge($rules, explode(',', trim($g['rules'], ',')));
|
||||
}
|
||||
$rules = array_unique($rules);
|
||||
|
||||
$role_rule = create_tree_list(0, $rule, $rules);
|
||||
View::assign('role_rule', $role_rule);
|
||||
View::assign('detail', $detail);
|
||||
View::assign('group', $group);
|
||||
add_log('view', $id);
|
||||
return view();
|
||||
}
|
||||
//删除
|
||||
public function delete()
|
||||
{
|
||||
if (request()->isDelete()) {
|
||||
$id = get_params("id");
|
||||
if ($id == 1) {
|
||||
return to_assign(0, "超级岗位,不能删除");
|
||||
}
|
||||
$data['status'] = '-1';
|
||||
$data['id'] = $id;
|
||||
$data['update_time'] = time();
|
||||
if (Db::name('Position')->update($data) !== false) {
|
||||
add_log('delete', $id);
|
||||
return to_assign(0, "删除成功");
|
||||
} else {
|
||||
return to_assign(1, "删除失败");
|
||||
}
|
||||
} else {
|
||||
return to_assign(1, "错误的请求");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (c) 2023-2024 美天智能科技
|
||||
* @author 李志强
|
||||
* @link http://www.meteteme.com
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app\admin\controller;
|
||||
|
||||
use app\base\BaseController;
|
||||
use app\model\AdminGroup;
|
||||
use app\admin\validate\GroupCheck;
|
||||
use think\exception\ValidateException;
|
||||
use think\facade\Db;
|
||||
use think\facade\View;
|
||||
|
||||
class Role extends BaseController
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
if (request()->isAjax()) {
|
||||
$param = get_params();
|
||||
$where = array();
|
||||
if (!empty($param['keywords'])) {
|
||||
$where[] = ['id|title|desc', 'like', '%' . $param['keywords'] . '%'];
|
||||
}
|
||||
$rows = empty($param['limit']) ? get_config('app.page_size') : $param['limit'];
|
||||
$group = AdminGroup::where($where)
|
||||
->order('create_time asc')
|
||||
->paginate($rows, false, ['query' => $param]);
|
||||
return table_assign(0, '', $group);
|
||||
} else {
|
||||
return view();
|
||||
}
|
||||
}
|
||||
|
||||
//添加&编辑
|
||||
public function add()
|
||||
{
|
||||
$param = get_params();
|
||||
if (request()->isPost()) {
|
||||
$ruleData = isset($param['rule']) ? $param['rule'] : 0;
|
||||
$param['rules'] = implode(',', $ruleData);
|
||||
if (!empty($param['id']) && $param['id'] > 0) {
|
||||
try {
|
||||
validate(GroupCheck::class)->scene('edit')->check($param);
|
||||
} catch (ValidateException $e) {
|
||||
// 验证失败 输出错误信息
|
||||
return to_assign(1, $e->getError());
|
||||
}
|
||||
//为了系统安全id为1的系统所有者管理组不允许修改
|
||||
if ($param['id'] == 1) {
|
||||
return to_assign(1, '为了系统安全,该管理组不允许修改');
|
||||
}
|
||||
Db::name('AdminGroup')->where(['id' => $param['id']])->strict(false)->field(true)->update($param);
|
||||
add_log('edit', $param['id'], $param);
|
||||
} else {
|
||||
try {
|
||||
validate(GroupCheck::class)->scene('add')->check($param);
|
||||
} catch (ValidateException $e) {
|
||||
// 验证失败 输出错误信息
|
||||
return to_assign(1, $e->getError());
|
||||
}
|
||||
$gid = Db::name('AdminGroup')->strict(false)->field(true)->insertGetId($param);
|
||||
add_log('add', $gid, $param);
|
||||
}
|
||||
//清除菜单\权限缓存
|
||||
clear_cache('adminMenu');
|
||||
return to_assign();
|
||||
} else {
|
||||
$id = isset($param['id']) ? $param['id'] : 0;
|
||||
$rule = admin_rule();
|
||||
if ($id > 0) {
|
||||
$rules = admin_group_info($id);
|
||||
$role_rule = create_tree_list(0, $rule, $rules);
|
||||
$role = Db::name('AdminGroup')->where(['id' => $id])->find();
|
||||
View::assign('role', $role);
|
||||
} else {
|
||||
$role_rule = create_tree_list(0, $rule, []);
|
||||
}
|
||||
View::assign('role_rule', $role_rule);
|
||||
View::assign('id', $id);
|
||||
return view();
|
||||
}
|
||||
}
|
||||
|
||||
//删除
|
||||
public function delete()
|
||||
{
|
||||
if (request()->isDelete()) {
|
||||
$id = get_params("id");
|
||||
if ($id == 1) {
|
||||
return to_assign(1, "该组是系统所有者,无法删除");
|
||||
}
|
||||
if (Db::name('AdminGroup')->delete($id) !== false) {
|
||||
add_log('delete', $id, []);
|
||||
return to_assign(0, "删除成功");
|
||||
} else {
|
||||
return to_assign(1, "删除失败");
|
||||
}
|
||||
} else {
|
||||
return to_assign(1, "错误的请求");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (c) 2023-2024 美天智能科技
|
||||
* @author 李志强
|
||||
* @link http://www.meteteme.com
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app\admin\controller;
|
||||
|
||||
use app\base\BaseController;
|
||||
use app\admin\validate\RuleCheck;
|
||||
use think\exception\ValidateException;
|
||||
use think\facade\Db;
|
||||
use think\facade\View;
|
||||
|
||||
class Rule extends BaseController
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
if (request()->isAjax()) {
|
||||
$rule = Db::name('adminRule')->order('sort asc,id asc')->select();
|
||||
return to_assign(0, '', $rule);
|
||||
} else {
|
||||
return view();
|
||||
}
|
||||
}
|
||||
|
||||
//添加
|
||||
public function add()
|
||||
{
|
||||
$param = get_params();
|
||||
if (request()->isPost()) {
|
||||
$param['src'] = preg_replace('# #', '', $param['src']);
|
||||
if ($param['id'] > 0) {
|
||||
try {
|
||||
validate(RuleCheck::class)->scene('edit')->check($param);
|
||||
} catch (ValidateException $e) {
|
||||
// 验证失败 输出错误信息
|
||||
return to_assign(1, $e->getError());
|
||||
}
|
||||
Db::name('AdminRule')->strict(false)->field(true)->update($param);
|
||||
add_log('edit', $param['id'], $param);
|
||||
} else {
|
||||
try {
|
||||
validate(RuleCheck::class)->scene('add')->check($param);
|
||||
} catch (ValidateException $e) {
|
||||
// 验证失败 输出错误信息
|
||||
return to_assign(1, $e->getError());
|
||||
}
|
||||
$param['create_time'] = time();
|
||||
$rid = Db::name('AdminRule')->strict(false)->field(true)->insertGetId($param);
|
||||
//自动为系统所有者管理组分配新增的节点
|
||||
// $groups = Db::name('AdminGroup')->select();
|
||||
// if (!empty($group)) {
|
||||
// $newGroup['id'] = 1;
|
||||
// $newGroup['rules'] = $group['rules'] . ',' . $rid;
|
||||
// Db::name('AdminGroup')->strict(false)->field(true)->update($newGroup);
|
||||
// add_log('add', $rid, $param);
|
||||
// }
|
||||
//自动为系统所有人分配新增的节点
|
||||
$groups = Db::name('AdminGroup')->select();
|
||||
foreach ($groups as $group) {
|
||||
$newGroup['id'] = $group['id'];
|
||||
$newGroup['rules'] = $group['rules'] . ',' . $rid;
|
||||
Db::name('AdminGroup')->strict(false)->field(true)->update($newGroup);
|
||||
}
|
||||
add_log('add', $rid, $param);
|
||||
}
|
||||
// 删除后台节点缓存
|
||||
clear_cache('adminRules');
|
||||
return to_assign();
|
||||
} else {
|
||||
$id = isset($param['id']) ? $param['id'] : 0;
|
||||
$pid = isset($param['pid']) ? $param['pid'] : 0;
|
||||
if ($id > 0) {
|
||||
$detail = Db::name('AdminRule')->where('id', $id)->find();
|
||||
View::assign('detail', $detail);
|
||||
}
|
||||
View::assign('id', $id);
|
||||
View::assign('pid', $pid);
|
||||
return view();
|
||||
}
|
||||
}
|
||||
//删除
|
||||
public function delete()
|
||||
{
|
||||
if (request()->isDelete()) {
|
||||
$id = get_params("id");
|
||||
$count = Db::name('AdminRule')->where(["pid" => $id])->count();
|
||||
if ($count > 0) {
|
||||
return to_assign(1, "该节点下还有子菜单,无法删除");
|
||||
}
|
||||
if (Db::name('AdminRule')->delete($id) !== false) {
|
||||
clear_cache('adminRules');
|
||||
add_log('delete', $id, []);
|
||||
return to_assign(0, "删除成功");
|
||||
} else {
|
||||
return to_assign(1, "删除失败");
|
||||
}
|
||||
} else {
|
||||
return to_assign(1, "错误的请求");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (c) 2023-2024 美天智能科技
|
||||
* @author 李志强
|
||||
* @link http://www.meteteme.com
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app\admin\controller;
|
||||
|
||||
use app\base\BaseController;
|
||||
use think\facade\Db;
|
||||
use think\facade\View;
|
||||
|
||||
class Setting extends BaseController
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
$install = false;
|
||||
if (file_exists(CMS_ROOT . 'app/install')) {
|
||||
$install = true;
|
||||
}
|
||||
View::assign('install', $install);
|
||||
$conf = Db::name('Config')->where('id', 1)->find();
|
||||
$config = [];
|
||||
if ($conf['content']) {
|
||||
$config = unserialize($conf['content']);
|
||||
}
|
||||
View::assign('config', $config);
|
||||
View::assign('TP_VERSION', \think\facade\App::version());
|
||||
return View();
|
||||
}
|
||||
|
||||
public function errorShow()
|
||||
{
|
||||
echo '错误';
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (c) 2023-2024 美天智能科技
|
||||
* @author 李志强
|
||||
* @link http://www.meteteme.com
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app\admin\controller;
|
||||
|
||||
use app\base\BaseController;
|
||||
use app\admin\validate\TaskCateCheck;
|
||||
use think\exception\ValidateException;
|
||||
use think\facade\Db;
|
||||
use think\facade\View;
|
||||
|
||||
class Tcate extends BaseController
|
||||
{
|
||||
//任务类别
|
||||
public function index()
|
||||
{
|
||||
if (request()->isAjax()) {
|
||||
$cate = Db::name('TaskCate')->order('sort desc')->select();
|
||||
return to_assign(0, '', $cate);
|
||||
} else {
|
||||
return view();
|
||||
}
|
||||
}
|
||||
//任务类别添加
|
||||
public function add()
|
||||
{
|
||||
if (request()->isPost()) {
|
||||
$param = get_params();
|
||||
if (!empty($param['id']) && $param['id'] > 0) {
|
||||
try {
|
||||
validate(TaskCateCheck::class)->scene('edit')->check($param);
|
||||
} catch (ValidateException $e) {
|
||||
// 验证失败 输出错误信息
|
||||
return to_assign(1, $e->getError());
|
||||
}
|
||||
$data['update_time'] = time();
|
||||
$res = Db::name('TaskCate')->strict(false)->field(true)->update($param);
|
||||
if ($res) {
|
||||
add_log('edit', $param['id'], $param);
|
||||
}
|
||||
return to_assign();
|
||||
} else {
|
||||
try {
|
||||
validate(TaskCateCheck::class)->scene('add')->check($param);
|
||||
} catch (ValidateException $e) {
|
||||
// 验证失败 输出错误信息
|
||||
return to_assign(1, $e->getError());
|
||||
}
|
||||
$param['create_time'] = time();
|
||||
$insertId = Db::name('TaskCate')->strict(false)->field(true)->insertGetId($param);
|
||||
if ($insertId) {
|
||||
add_log('add', $insertId, $param);
|
||||
}
|
||||
return to_assign();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//任务类别设置
|
||||
public function check()
|
||||
{
|
||||
if (request()->isPost()) {
|
||||
$param = get_params();
|
||||
$res = Db::name('TaskCate')->strict(false)->field('id,status')->update($param);
|
||||
if ($res) {
|
||||
if ($param['status'] == 0) {
|
||||
add_log('disable', $param['id'], $param);
|
||||
} else if ($param['status'] == 1) {
|
||||
add_log('recover', $param['id'], $param);
|
||||
}
|
||||
return to_assign();
|
||||
} else {
|
||||
return to_assign(0, '操作失败');
|
||||
}
|
||||
} else {
|
||||
return to_assign(0, '错误的请求');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,346 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (c) 2023-2024 美天智能科技
|
||||
* @author 李志强
|
||||
* @link http://www.meteteme.com
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app\admin\controller;
|
||||
|
||||
use app\base\BaseController;
|
||||
use app\model\Admin as AdminList;
|
||||
use app\admin\validate\AdminCheck;
|
||||
use avatars\MDAvatars;
|
||||
use Overtrue\Pinyin\Pinyin;
|
||||
use think\exception\ValidateException;
|
||||
use think\facade\Db;
|
||||
use think\facade\View;
|
||||
|
||||
class User extends BaseController
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
if (request()->isAjax()) {
|
||||
$param = get_params();
|
||||
$where = array();
|
||||
if (!empty($param['keywords'])) {
|
||||
$where[] = ['id|username|name|nickname|mobile|desc', 'like', '%' . $param['keywords'] . '%'];
|
||||
}
|
||||
$where[] = ['status', '<', 2];
|
||||
if (isset($param['status']) && $param['status'] != '') {
|
||||
$where[] = ['status', '=', $param['status']];
|
||||
}
|
||||
if (!empty($param['type'])) {
|
||||
$where[] = ['type', '=', $param['type']];
|
||||
}
|
||||
if (!empty($param['did'])) {
|
||||
$department_array = get_department_son($param['did']);
|
||||
$where[] = ['did', 'in', $department_array];
|
||||
}
|
||||
$rows = empty($param['limit']) ? get_config('app.page_size') : $param['limit'];
|
||||
$admin = AdminList::where($where)
|
||||
->order('id desc')
|
||||
->paginate($rows, false, ['query' => $param])
|
||||
->each(function ($item, $key) {
|
||||
$item->department = Db::name('Department')->where(['id' => $item->did])->value('title');
|
||||
$item->position = Db::name('Position')->where(['id' => $item->position_id])->value('title');
|
||||
$item->entry_time = empty($item->entry_time) ? '-' : date('Y-m-d', $item->entry_time);
|
||||
$item->last_login_time = empty($item->last_login_time) ? '-' : date('Y-m-d H:i', $item->last_login_time);
|
||||
$item->last_login_ip = empty($item->last_login_ip) ? '-' : $item->last_login_ip;
|
||||
});
|
||||
return table_assign(0, '', $admin);
|
||||
} else {
|
||||
return view();
|
||||
}
|
||||
}
|
||||
|
||||
//添加
|
||||
public function add()
|
||||
{
|
||||
$param = get_params();
|
||||
if (request()->isPost()) {
|
||||
$param['entry_time'] = strtotime($param['entry_time']);
|
||||
$param['nickname'] = $param['name'];
|
||||
$pinyin = new Pinyin();
|
||||
$username = $pinyin->name($param['name'], PINYIN_UMLAUT_V);
|
||||
$param['username'] = implode('', $username);
|
||||
if (!empty($param['id']) && $param['id'] > 0) {
|
||||
$count = Db::name('Admin')->where([['username', 'like', $param['username'] . '%'], ['id', '<>', $param['id']]])->count();
|
||||
if ($count > 0) {
|
||||
$param['username'] = implode('', $username) . $count;
|
||||
}
|
||||
try {
|
||||
validate(AdminCheck::class)->scene('edit')->check($param);
|
||||
} catch (ValidateException $e) {
|
||||
// 验证失败 输出错误信息
|
||||
return to_assign(1, $e->getError());
|
||||
}
|
||||
// 启动事务
|
||||
Db::startTrans();
|
||||
try {
|
||||
Db::name('Admin')->where(['id' => $param['id']])->strict(false)->field(true)->update($param);
|
||||
if (!isset($param['thumb']) || $param['thumb'] == '') {
|
||||
$char = mb_substr($param['name'], 0, 1, 'utf-8');
|
||||
Db::name('Admin')->where('id', $param['id'])->update(['thumb' => $this->to_avatars($char)]);
|
||||
}
|
||||
add_log('edit', $param['id'], $param);
|
||||
//清除菜单\权限缓存
|
||||
clear_cache('adminMenu');
|
||||
// 提交事务
|
||||
Db::commit();
|
||||
} catch (\Exception $e) {
|
||||
// 回滚事务
|
||||
Db::rollback();
|
||||
return to_assign(1, '提交失败:' . $e->getMessage());
|
||||
}
|
||||
} else {
|
||||
$count = Db::name('Admin')->where([['username', 'like', $param['username'] . '%']])->count();
|
||||
if ($count > 0) {
|
||||
$param['username'] = implode('', $username) . $count;
|
||||
}
|
||||
try {
|
||||
validate(AdminCheck::class)->scene('add')->check($param);
|
||||
} catch (ValidateException $e) {
|
||||
// 验证失败 输出错误信息
|
||||
return to_assign(1, $e->getError());
|
||||
}
|
||||
$param['salt'] = set_salt(20);
|
||||
$param['pwd'] = set_password($param['reg_pwd'], $param['salt']);
|
||||
// 启动事务
|
||||
Db::startTrans();
|
||||
try {
|
||||
$uid = Db::name('Admin')->strict(false)->field(true)->insertGetId($param);
|
||||
if (!isset($param['thumb']) || $param['thumb'] == '') {
|
||||
$char = mb_substr($param['name'], 0, 1, 'utf-8');
|
||||
Db::name('Admin')->where('id', $uid)->update(['thumb' => $this->to_avatars($char)]);
|
||||
}
|
||||
add_log('add', $uid, $param);
|
||||
// 提交事务
|
||||
Db::commit();
|
||||
} catch (\Exception $e) {
|
||||
// 回滚事务
|
||||
Db::rollback();
|
||||
return to_assign(1, '提交失败:' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
return to_assign();
|
||||
} else {
|
||||
$id = isset($param['id']) ? $param['id'] : 0;
|
||||
$department = set_recursion(get_department());
|
||||
$position = Db::name('Position')->where('status', '>=', 0)->order('create_time asc')->select();
|
||||
if ($id > 0) {
|
||||
$detail = get_admin($id);
|
||||
View::assign('detail', $detail);
|
||||
} else {
|
||||
//初始化密码
|
||||
$reg_pwd = set_salt(6);
|
||||
View::assign('reg_pwd', $reg_pwd);
|
||||
}
|
||||
View::assign('department', $department);
|
||||
View::assign('position', $position);
|
||||
View::assign('id', $id);
|
||||
return view();
|
||||
}
|
||||
}
|
||||
|
||||
//生成头像
|
||||
public function to_avatars($char)
|
||||
{
|
||||
$defaultData = array(
|
||||
'A',
|
||||
'B',
|
||||
'C',
|
||||
'D',
|
||||
'E',
|
||||
'F',
|
||||
'G',
|
||||
'H',
|
||||
'I',
|
||||
'J',
|
||||
'K',
|
||||
'L',
|
||||
'M',
|
||||
'N',
|
||||
'O',
|
||||
'P',
|
||||
'Q',
|
||||
'R',
|
||||
'S',
|
||||
'T',
|
||||
'U',
|
||||
'V',
|
||||
'W',
|
||||
'S',
|
||||
'Y',
|
||||
'Z',
|
||||
'0',
|
||||
'1',
|
||||
'2',
|
||||
'3',
|
||||
'4',
|
||||
'5',
|
||||
'6',
|
||||
'7',
|
||||
'8',
|
||||
'9',
|
||||
'零',
|
||||
'壹',
|
||||
'贰',
|
||||
'叁',
|
||||
'肆',
|
||||
'伍',
|
||||
'陆',
|
||||
'柒',
|
||||
'捌',
|
||||
'玖',
|
||||
'拾',
|
||||
'一',
|
||||
'二',
|
||||
'三',
|
||||
'四',
|
||||
'五',
|
||||
'六',
|
||||
'七',
|
||||
'八',
|
||||
'九',
|
||||
'十'
|
||||
);
|
||||
if (isset($char)) {
|
||||
$Char = $char;
|
||||
} else {
|
||||
$Char = $defaultData[mt_rand(0, count($defaultData) - 1)];
|
||||
}
|
||||
$OutputSize = min(512, empty($_GET['size']) ? 36 : intval($_GET['size']));
|
||||
|
||||
$Avatar = new MDAvatars($Char, 256, 1);
|
||||
$avatar_name = '/avatars/avatar_256_' . set_salt(10) . time() . '.png';
|
||||
$path = get_config('filesystem.disks.public.url') . $avatar_name;
|
||||
$res = $Avatar->Save('.' . $path, 256);
|
||||
$Avatar->Free();
|
||||
return $path;
|
||||
}
|
||||
|
||||
//查看
|
||||
public function view()
|
||||
{
|
||||
$id = get_params('id');
|
||||
$detail = get_admin($id);
|
||||
//查询所有菜单和权限节点
|
||||
$menu = Db::name('AdminRule')->where(['menu' => 1])->order('sort asc,id asc')->select()->toArray();
|
||||
$rule = Db::name('AdminRule')->order('sort asc,id asc')->select()->toArray();
|
||||
|
||||
//查询用户拥有的查单和节点
|
||||
$user_groups = Db::name('PositionGroup')
|
||||
->alias('a')
|
||||
->join("AdminGroup g", "a.group_id=g.id", 'LEFT')
|
||||
->where([['a.pid', '=', $detail["position_id"]], ['g.status', '=', 1]])
|
||||
->select()
|
||||
->toArray();
|
||||
$groups = $user_groups ?: [];
|
||||
|
||||
$rules = [];
|
||||
foreach ($groups as $g) {
|
||||
$rules = array_merge($rules, explode(',', trim($g['rules'], ',')));
|
||||
}
|
||||
$rules = array_unique($rules);
|
||||
|
||||
//数据嵌套
|
||||
$role_rule = create_tree_list(0, $rule, $rules);
|
||||
|
||||
View::assign('role_rule', $role_rule);
|
||||
View::assign('detail', $detail);
|
||||
add_log('view', get_params('id'));
|
||||
return view();
|
||||
}
|
||||
|
||||
//禁用,恢复
|
||||
public function set()
|
||||
{
|
||||
if (request()->isPost()) {
|
||||
$type = get_params("type");
|
||||
$ids = get_params("ids");
|
||||
$idArray = explode(',', $ids);
|
||||
$list = [];
|
||||
foreach ($idArray as $key => $val) {
|
||||
if ($val == 1) {
|
||||
continue;
|
||||
}
|
||||
$list[] = [
|
||||
'status' => $type,
|
||||
'id' => $val,
|
||||
'update_time' => time(),
|
||||
];
|
||||
}
|
||||
foreach ($list as $key => $v) {
|
||||
if (Db::name('Admin')->update($v) !== false) {
|
||||
if ($type == 0) {
|
||||
add_log('disable', $v['id']);
|
||||
} else if ($type == 1) {
|
||||
add_log('recover', $v['id']);
|
||||
}
|
||||
}
|
||||
}
|
||||
return to_assign(0, '操作成功');
|
||||
} else {
|
||||
return to_assign(1, "错误的请求");
|
||||
}
|
||||
}
|
||||
|
||||
//重置密码
|
||||
public function reset()
|
||||
{
|
||||
if (request()->isPost()) {
|
||||
$id = get_params("id");
|
||||
if ($id == 1) {
|
||||
return to_assign(1, '该账号是超级管理员,不允许重置');
|
||||
}
|
||||
$new_pwd = set_salt(6);
|
||||
$salt = set_salt(20);
|
||||
$data = [
|
||||
'reg_pwd' => $new_pwd,
|
||||
'salt' => $salt,
|
||||
'pwd' => set_password($new_pwd, $salt),
|
||||
'id' => $id,
|
||||
'update_time' => time(),
|
||||
];
|
||||
if (Db::name('Admin')->update($data) !== false) {
|
||||
add_log('reset', $id);
|
||||
return to_assign(0, '操作成功');
|
||||
} else {
|
||||
return to_assign(1, '操作失败');
|
||||
}
|
||||
} else {
|
||||
return to_assign(1, "错误的请求");
|
||||
}
|
||||
}
|
||||
|
||||
//获取员工数据
|
||||
public function getuserinfo() {
|
||||
try {
|
||||
// 查询数据
|
||||
$list = Db::name('Admin')
|
||||
->field('id, nickname') // 选择所需字段
|
||||
->where('status', 1) // 增加条件,status 值为 1
|
||||
->order('id desc') // 按 id 倒序排序
|
||||
->select(); // 获取数据
|
||||
|
||||
// 返回成功响应
|
||||
return json([
|
||||
'code' => 1, // 成功状态码
|
||||
'msg' => '获取成功', // 提示信息
|
||||
'data' => $list // 数据展示
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
// 捕获异常并返回错误信息
|
||||
return json([
|
||||
'code' => 0, // 失败状态码
|
||||
'msg' => '获取失败: ' . $e->getMessage(), // 错误信息
|
||||
'data' => [] // 空数据
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (c) 2023-2024 美天智能科技
|
||||
* @author 李志强
|
||||
* @link http://www.meteteme.com
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app\admin\controller;
|
||||
|
||||
use app\base\BaseController;
|
||||
use app\admin\validate\WorkCateCheck;
|
||||
use think\exception\ValidateException;
|
||||
use think\facade\Db;
|
||||
use think\facade\View;
|
||||
|
||||
class Wcate extends BaseController
|
||||
{
|
||||
//工作类别
|
||||
public function index()
|
||||
{
|
||||
if (request()->isAjax()) {
|
||||
$cate = Db::name('WorkCate')->order('id asc')->select();
|
||||
return to_assign(0, '', $cate);
|
||||
} else {
|
||||
return view();
|
||||
}
|
||||
}
|
||||
//工作类别添加
|
||||
public function add()
|
||||
{
|
||||
if (request()->isPost()) {
|
||||
$param = get_params();
|
||||
if (!empty($param['id']) && $param['id'] > 0) {
|
||||
try {
|
||||
validate(WorkCateCheck::class)->scene('edit')->check($param);
|
||||
} catch (ValidateException $e) {
|
||||
// 验证失败 输出错误信息
|
||||
return to_assign(1, $e->getError());
|
||||
}
|
||||
$data['update_time'] = time();
|
||||
$res = Db::name('WorkCate')->strict(false)->field(true)->update($param);
|
||||
if ($res) {
|
||||
add_log('edit', $param['id'], $param);
|
||||
}
|
||||
return to_assign();
|
||||
} else {
|
||||
try {
|
||||
validate(WorkCateCheck::class)->scene('add')->check($param);
|
||||
} catch (ValidateException $e) {
|
||||
// 验证失败 输出错误信息
|
||||
return to_assign(1, $e->getError());
|
||||
}
|
||||
$param['create_time'] = time();
|
||||
$insertId = Db::name('WorkCate')->strict(false)->field(true)->insertGetId($param);
|
||||
if ($insertId) {
|
||||
add_log('add', $insertId, $param);
|
||||
}
|
||||
return to_assign();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//工作类别设置
|
||||
public function check()
|
||||
{
|
||||
if (request()->isPost()) {
|
||||
$param = get_params();
|
||||
$res = Db::name('WorkCate')->strict(false)->field('id,status')->update($param);
|
||||
if ($res) {
|
||||
if ($param['status'] == 0) {
|
||||
add_log('disable', $param['id'], $param);
|
||||
} else if ($param['status'] == 1) {
|
||||
add_log('recover', $param['id'], $param);
|
||||
}
|
||||
return to_assign();
|
||||
} else {
|
||||
return to_assign(0, '操作失败');
|
||||
}
|
||||
} else {
|
||||
return to_assign(0, '错误的请求');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user