feat: 重构代码架构 + 新增报表/跟单/输赢统计功能

- 拆分 HomeController → TransactionController, ReportWebController, FollowPlanController
- 新增 Service 层: TransactionService, ReportService, FollowPlanService
- pk10.php JS 抽离为 4 个独立文件 (sound/race/bet/poll)
- 前台新增报表查询页面 (/report) + 跟单计划页面 (/follow-plan)
- 后台新增跟单计划管理 + 用户输赢明细统计
- 封盘状态显示倒计时 (x:xx)
- 音效仅在开奖弹窗打开时播放
- 路由按模块分组整理
- autoload 支持 App\Services 命名空间
This commit is contained in:
li
2026-03-27 18:41:06 +08:00
parent 48cfe4be04
commit 4a94fe36cf
87 changed files with 8681 additions and 646 deletions
+43 -29
View File
@@ -38,21 +38,21 @@ class PluginManager {
$rootDir = realpath(__DIR__ . '/../../');
$logDir = $rootDir . '/Storage/log';
// 确保日志目录(如不存在则创建)
if (!is_dir($logDir)) {
if (!mkdir($logDir, 0755, true) && !is_dir($logDir)) {
throw new \RuntimeException("无法创建日志目录: $logDir ,请检查权限");
}
}
// 检查目录可写性
if (!is_writable($logDir)) {
throw new \RuntimeException("日志目录不可写: $logDir ,请检查权限");
}
$this->logFile = $logDir . '/plugin_manager.log';
// 尝试准备日志目录;失败时降级到 PHP error_log,不能阻断主流程
if (!is_dir($logDir) && !@mkdir($logDir, 0755, true) && !is_dir($logDir)) {
$this->logFile = null;
error_log("PluginManager log directory create failed: $logDir");
return;
}
if (!$this->canWriteLogFile()) {
$this->logFile = null;
error_log("PluginManager log path not writable: $logDir");
return;
}
// 检查日志文件大小并自动清理(大于2MB时)
$this->cleanupLogFile(2); // 传入最大允许的MB数
}
@@ -62,32 +62,47 @@ class PluginManager {
* @param int $maxSizeMB 最大允许的文件大小(MB)
*/
private function cleanupLogFile(int $maxSizeMB) {
// 检查文件是否存在
if (!file_exists($this->logFile)) {
if (!$this->canWriteLogFile() || !file_exists($this->logFile)) {
return;
}
// 转换MB为字节
$maxSizeBytes = $maxSizeMB * 1024 * 1024;
// 获取当前文件大小
$currentSize = filesize($this->logFile);
$currentSize = @filesize($this->logFile);
if ($currentSize === false) {
return;
}
// 如果文件大小超过限制,清空文件
if ($currentSize > $maxSizeBytes) {
// 先备份当前日志内容(可选)
$backupFile = $this->logFile . '.bak_' . date('YmdHis');
copy($this->logFile, $backupFile);
@copy($this->logFile, $backupFile);
// 清空日志文件
file_put_contents($this->logFile, '');
@file_put_contents($this->logFile, '');
// 记录清理日志
$message = "[" . date('Y-m-d H:i:s') . "] 日志文件超过{$maxSizeMB}MB,已自动清理\n";
file_put_contents($this->logFile, $message, FILE_APPEND);
@file_put_contents($this->logFile, $message, FILE_APPEND);
}
}
private function canWriteLogFile(): bool {
if (empty($this->logFile)) {
return false;
}
$logDir = dirname($this->logFile);
if (!is_dir($logDir) || !is_writable($logDir)) {
return false;
}
return !file_exists($this->logFile) || is_writable($this->logFile);
}
/**
* 设置系统核心路由
@@ -121,13 +136,12 @@ class PluginManager {
protected function log(string $msg, string $level = 'INFO'): void {
$date = date('Y-m-d H:i:s');
$logMsg = "[$date] [$level] $msg\n";
$logDir = dirname($this->logFile);
try {
if (is_dir($logDir) && is_writable($logDir)) {
file_put_contents($this->logFile, $logMsg, FILE_APPEND);
if ($this->canWriteLogFile()) {
@file_put_contents($this->logFile, $logMsg, FILE_APPEND);
} else {
error_log("PluginManager log directory not writable: $logDir");
error_log("PluginManager: " . trim($logMsg));
}
} catch (\Throwable $e) {
error_log("Failed to write plugin log: " . $e->getMessage());