feat: 添加基金邮件定时发送功能并优化邮件内容格式

- 新增宝塔面板定时任务脚本 cron_send_email.php
- 添加手动发送邮件按钮到管理界面
- 使用PHPMailer替代原始SMTP实现
- 优化邮件内容格式,按涨跌幅排序基金数据
- 增加邮件发送时间窗口判断逻辑
- 更新项目文档说明定时任务配置
This commit is contained in:
LL
2025-12-12 17:10:03 +08:00
parent 354133d6e4
commit 69ef47412d
13 changed files with 395 additions and 197 deletions

View File

@@ -1,9 +1,59 @@
<?php
// 首先检查是否是sendFundEmail请求
$isSendFundEmailRequest = false;
if (isset($_GET['action']) && $_GET['action'] === 'sendFundEmail') {
$isSendFundEmailRequest = true;
} elseif (isset($_POST['action']) && $_POST['action'] === 'sendFundEmail') {
$isSendFundEmailRequest = true;
}
// 如果是sendFundEmail请求完全独立处理
if ($isSendFundEmailRequest) {
// 设置响应头
header('Content-Type: application/json; charset=utf-8');
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET, POST, OPTIONS');
header('Access-Control-Allow-Headers: Content-Type, charset');
// 验证管理员权限
session_start();
// 调试模式允许通过debug参数绕过权限验证
$isDebugMode = (isset($_GET['debug']) && $_GET['debug'] === 'true') || (isset($_POST['debug']) && $_POST['debug'] === 'true');
if (!$isDebugMode && (!isset($_SESSION['admin_logged_in']) || $_SESSION['admin_logged_in'] !== true)) {
http_response_code(403);
echo json_encode(['success' => false, 'error' => '权限不足']);
exit;
}
// 引入FundMonitorAPI
require_once 'api.php';
$api = new FundMonitorAPI();
try {
// 调用发送基金状态邮件方法传入true参数强制发送
$result = $api->sendFundStatusEmail(true);
if ($result) {
echo json_encode(['success' => true, 'message' => '邮件发送成功']);
} else {
echo json_encode(['success' => false, 'error' => '邮件发送失败,请查看日志']);
}
} catch (Exception $e) {
http_response_code(500);
echo json_encode(['success' => false, 'error' => $e->getMessage()]);
}
// 立即终止脚本,确保不会执行任何后续代码
exit(0);
}
// 以下是其他API的处理逻辑
// 设置响应头
header('Content-Type: application/json; charset=utf-8');
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET, POST, OPTIONS');
header('Access-Control-Allow-Headers: Content-Type, charset');
// 定义FundAdminAPI类
class FundAdminAPI {
private $configFile = 'data/fund_config.json';
private $operationFile = 'data/operation_log.json';
@@ -1119,14 +1169,17 @@ class FundAdminAPI {
}
// 错误处理
try {
$api = new FundAdminAPI();
$api->handleRequest();
} catch (Exception $e) {
http_response_code(500);
echo json_encode([
'success' => false,
'message' => '服务器内部错误: ' . $e->getMessage()
]);
// 只有非sendFundEmail请求才会执行到这里
if (!$isSendFundEmailRequest) {
try {
$api = new FundAdminAPI();
$api->handleRequest();
} catch (Exception $e) {
http_response_code(500);
echo json_encode([
'success' => false,
'message' => '服务器内部错误: ' . $e->getMessage()
]);
}
}
?>