Files
jj2/admin.php
LL 69ef47412d feat: 添加基金邮件定时发送功能并优化邮件内容格式
- 新增宝塔面板定时任务脚本 cron_send_email.php
- 添加手动发送邮件按钮到管理界面
- 使用PHPMailer替代原始SMTP实现
- 优化邮件内容格式,按涨跌幅排序基金数据
- 增加邮件发送时间窗口判断逻辑
- 更新项目文档说明定时任务配置
2025-12-12 17:10:03 +08:00

335 lines
14 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
// 基金监控系统管理页面
// 启动会话
session_start();
// 检查是否已登录
if (!isset($_SESSION['admin_logged_in']) || $_SESSION['admin_logged_in'] !== true) {
// 未登录,重定向到登录页面
header('Location: login.php');
exit;
}
// 可选检查登录时间设置会话超时例如30分钟
$session_timeout = 30 * 60; // 30分钟
if (isset($_SESSION['login_time']) && (time() - $_SESSION['login_time']) > $session_timeout) {
// 会话超时,销毁会话并重定向到登录页面
session_unset();
session_destroy();
header('Location: login.php');
exit;
}
// 更新最后活动时间
$_SESSION['last_activity'] = time();
// 注销功能
if (isset($_GET['action']) && $_GET['action'] === 'logout') {
// 记录注销日志
$log_entry = [
'timestamp' => date('Y-m-d H:i:s'),
'action' => '管理员注销',
'ip' => $_SERVER['REMOTE_ADDR']
];
// 保存注销日志
$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));
}
// 销毁会话
session_unset();
session_destroy();
header('Location: login.php');
exit;
}
?>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>🚀 基金监控 - 管理后台</title>
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<link rel="stylesheet" href="admin.css">
</head>
<body>
<div class="container">
<div class="header">
<div class="header-content">
<h1><i class="fas fa-cogs"></i> 基金监控管理后台</h1>
<p>管理基金代码和虚拟投资金额</p>
<div class="controls">
<button class="btn btn-outline" onclick="window.location.href='index.php'">
<i class="fas fa-arrow-left"></i> 返回监控页面
</button>
<button class="btn btn-danger" onclick="window.location.href='admin.php?action=logout'">
<i class="fas fa-sign-out-alt"></i> 注销
</button>
</div>
</div>
</div>
<!-- 消息提示 -->
<div id="message" class="alert"></div>
<div class="content">
<!-- 标签页 -->
<div class="tabs">
<button class="tab active" onclick="switchTab('fundManagement')">基金配置</button>
<button class="tab" onclick="switchTab('recommendedFunds')">推荐基金管理</button>
<button class="tab" onclick="switchTab('operationLog')">操作日志</button>
<button class="tab" onclick="switchTab('fundCharts')">净值图表</button>
<button class="tab" onclick="switchTab('emailSettings')">邮箱设置</button>
</div>
<!-- 推荐基金管理标签页 -->
<div id="recommendedFunds" class="tab-content">
<div class="section-header">
<h2>推荐基金管理</h2>
<div class="search-box">
<input type="text" id="searchRecommendedFund" placeholder="搜索基金代码...">
</div>
</div>
<div class="table-container">
<table class="data-table">
<thead>
<tr>
<th>基金代码</th>
<th>推荐IP</th>
<th>推荐时间</th>
<th>渠道</th>
<th>金额</th>
<th>状态</th>
<th>操作</th>
</tr>
</thead>
<tbody id="recommendedFundsList">
<!-- 推荐基金列表将通过JavaScript动态加载 -->
</tbody>
</table>
</div>
<div class="pagination" id="recommendedFundsPagination">
<!-- 分页控件将通过JavaScript动态加载 -->
</div>
</div>
<!-- 基金配置标签页 -->
<div id="fundManagement" class="tab-content active">
<div class="section-header">
<h2>基金配置管理</h2>
<button class="btn btn-primary" onclick="showAddModal()">
<i class="fas fa-plus"></i> 添加基金
</button>
</div>
<!-- 基金列表表格 -->
<div class="table-container">
<table class="funds-table">
<thead>
<tr>
<th>基金代码</th>
<th>基金名称</th>
<th>所属渠道</th>
<th>投资金额(元)</th>
<th>操作</th>
</tr>
</thead>
<tbody id="fundsTableBody">
<!-- 动态加载数据 -->
</tbody>
</table>
</div>
</div>
<!-- 操作日志标签页 -->
<div id="operationLog" class="tab-content">
<div class="section-header">
<h2>操作日志</h2>
<button class="btn btn-outline" onclick="loadOperationLog()">
<i class="fas fa-sync-alt"></i> 刷新
</button>
</div>
<div class="operation-log" id="operationLogContent">
<!-- 操作日志内容 -->
</div>
</div>
<!-- 净值图表标签页 -->
<div id="fundCharts" class="tab-content">
<div class="section-header">
<h2>基金净值变化</h2>
<div>
<select class="fund-selector" id="fundSelector" onchange="loadFundChart(this.value)">
<option value="">请选择基金</option>
</select>
</div>
</div>
<div class="chart-container">
<div class="chart-header">
<div class="chart-title" id="chartTitle">请选择基金查看净值变化</div>
</div>
<div class="chart-wrapper">
<canvas id="fundChart"></canvas>
</div>
</div>
</div>
<!-- 邮箱设置标签页 -->
<div id="emailSettings" class="tab-content">
<div class="section-header">
<h2>邮箱设置</h2>
<button id="sendFundEmail" class="btn btn-primary">发送基金状态邮件</button>
</div>
<!-- SMTP配置 -->
<div class="card">
<div class="card-header">
<h3>SMTP服务器配置</h3>
</div>
<div class="card-body">
<form id="smtpConfigForm">
<div class="grid grid-cols-2 gap-4">
<div class="form-group">
<label class="form-label" for="smtpServer">SMTP服务器</label>
<input type="text" class="form-control" id="smtpServer" placeholder="smtp.example.com" required>
</div>
<div class="form-group">
<label class="form-label" for="smtpPort">SMTP端口</label>
<input type="number" class="form-control" id="smtpPort" placeholder="465" required min="1" max="65535">
</div>
<div class="form-group">
<label class="form-label" for="smtpSecure">加密方式</label>
<select class="form-control form-select" id="smtpSecure">
<option value="ssl">SSL</option>
<option value="tls">TLS</option>
<option value="">无</option>
</select>
</div>
<div class="form-group">
<label class="form-label" for="username">用户名</label>
<input type="text" class="form-control" id="username" placeholder="your@email.com" required>
</div>
<div class="form-group">
<label class="form-label" for="password">密码/授权码</label>
<input type="password" class="form-control" id="password" placeholder="Password or Auth Code" required>
</div>
</div>
<div class="grid grid-cols-2 gap-4 mt-4">
<div class="form-group">
<label class="form-label" for="fromEmail">发件人邮箱</label>
<input type="email" class="form-control" id="fromEmail" placeholder="sender@email.com" required>
</div>
<div class="form-group">
<label class="form-label" for="fromName">发件人名称</label>
<input type="text" class="form-control" id="fromName" placeholder="基金监控系统" required>
</div>
</div>
<div class="mt-4">
<button type="submit" class="btn btn-primary">
<i class="fas fa-save"></i> 保存SMTP配置
</button>
</div>
</form>
</div>
</div>
<!-- 收件人管理 -->
<div class="card mt-4">
<div class="card-header">
<h3>收件人管理</h3>
</div>
<div class="card-body">
<div class="form-group">
<div class="flex items-center gap-2">
<input type="email" class="form-control" id="newEmail" placeholder="输入新的邮箱地址">
<button class="btn btn-primary" onclick="addEmailRecipient()">
<i class="fas fa-plus"></i> 添加
</button>
</div>
</div>
<div class="mt-4">
<h4>现有收件人:</h4>
<div id="emailRecipientsList" class="mt-2">
<!-- 收件人列表将通过JS动态加载 -->
</div>
</div>
</div>
</div>
</div>
</div>
<div class="footer">
<p><i class="fas fa-info-circle"></i> 基金监控系统管理后台</p>
</div>
</div>
<!-- 添加/编辑基金模态框 -->
<div class="modal" id="fundModal">
<div class="modal-content">
<div class="modal-header">
<h3 class="modal-title" id="modalTitle">添加基金</h3>
<button class="close-modal" onclick="closeModal()">&times;</button>
</div>
<form id="fundForm">
<input type="hidden" id="editIndex">
<div class="form-group">
<label class="form-label" for="fundCode">基金代码</label>
<input type="text" class="form-control" id="fundCode" required
placeholder="请输入6位基金代码" pattern="[0-9]{6}" maxlength="6">
</div>
<div class="form-group">
<label class="form-label" for="channel">所属渠道</label>
<select class="form-control form-select" id="channel" required>
<option value="">请选择渠道</option>
<option value="0">招商银行</option>
<option value="1">天天基金</option>
<option value="2">支付宝</option>
</select>
</div>
<div class="form-group">
<label class="form-label" for="investment">投资金额(元)</label>
<input type="number" class="form-control" id="investment" required
placeholder="请输入投资金额" min="1" step="0.01" value="1000">
</div>
<div class="modal-actions">
<button type="button" class="btn btn-outline" onclick="closeModal()">
取消
</button>
<button type="submit" class="btn btn-primary">
<i class="fas fa-save"></i> 保存
</button>
</div>
</form>
</div>
</div>
<script src="admin.js"></script>
</body>
</html>