refactor: 使用FileManager统一文件操作

将分散在各处的文件操作统一封装到FileManager工具类中,包括文件读写、目录创建、JSON处理等操作
This commit is contained in:
LL
2025-12-12 14:22:40 +08:00
parent fbf39f81c2
commit 6c168246ca
6 changed files with 81 additions and 78 deletions

View File

@@ -1,5 +1,6 @@
<?php
// 基金监控系统管理页面
require_once 'utils/FileManager.php';
// 启动会话
session_start();
@@ -35,18 +36,14 @@ if (isset($_GET['action']) && $_GET['action'] === 'logout') {
// 保存注销日志
$log_file = 'data/operation_log.json';
if (file_exists($log_file)) {
$logs = json_decode(file_get_contents($log_file), true);
if (!is_array($logs)) {
$logs = [];
}
array_unshift($logs, $log_entry);
// 限制日志数量
if (count($logs) > 500) {
$logs = array_slice($logs, 0, 500);
}
file_put_contents($log_file, json_encode($logs, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT));
FileManager::ensureDirExists(dirname($log_file));
$logs = FileManager::loadJsonFile($log_file, []);
array_unshift($logs, $log_entry);
// 限制日志数量
if (count($logs) > 500) {
$logs = array_slice($logs, 0, 500);
}
FileManager::saveJsonFile($log_file, $logs, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
// 销毁会话
session_unset();