From 1840d6f8aac842ad145b5f034dc649a14f901655 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E4=BA=91=E6=B3=BD=E7=BD=91?= <”357099073@qq.com“>
Date: Mon, 19 May 2025 22:38:27 +0800
Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0welcome?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
app/admin/controller/IndexController.php | 199 +++++++---
app/admin/view/index/welcome.php | 93 +++--
.../temp/060aaf82e6a412e1d93b52eb2415c06f.php | 298 ++++++++++++++
.../temp/2022feb4cf19b13311bd33466ada27df.php | 363 ++++++++++++++++++
.../temp/792969fb591a0f355761a1b3bf3d1226.php | 95 +++--
5 files changed, 926 insertions(+), 122 deletions(-)
create mode 100644 runtime/admin/temp/060aaf82e6a412e1d93b52eb2415c06f.php
create mode 100644 runtime/admin/temp/2022feb4cf19b13311bd33466ada27df.php
diff --git a/app/admin/controller/IndexController.php b/app/admin/controller/IndexController.php
index 994cfb2..1e4656f 100644
--- a/app/admin/controller/IndexController.php
+++ b/app/admin/controller/IndexController.php
@@ -68,77 +68,150 @@ class IndexController extends Base{
}
# 欢迎页面
public function welcome(){
- // 获取今日统计数据
- $today = date('Y-m-d');
- $todayStats = DailyStats::where('date', $today)
- ->find();
+ try {
+ // 获取最近7天的日期
+ $dates = [];
+ for ($i = 6; $i >= 0; $i--) {
+ $dates[] = date('Y-m-d', strtotime("-$i day"));
+ }
- // 获取最近7天的访问趋势
- $last7Days = DailyStats::where('date', '>=', date('Y-m-d', strtotime('-7 days')))
- ->where('date', '<=', $today)
- ->order('date', 'asc')
- ->select()
- ->toArray();
+ // 初始化数据数组
+ $visitData = [];
+ $userData = [];
+ $resourceData = [];
+ $articleData = [];
- // 获取用户增长趋势
- $userGrowth = DailyStats::where('date', '>=', date('Y-m-d', strtotime('-30 days')))
- ->where('date', '<=', $today)
- ->field('date, new_users, total_users')
- ->order('date', 'asc')
- ->select()
- ->toArray();
+ // 直接查询每天的数据
+ foreach ($dates as $date) {
+ $dayStats = Db::name('daily_stats')
+ ->where('date', $date)
+ ->find();
- // 获取资源下载统计
- $resourceStats = DailyStats::where('date', '>=', date('Y-m-d', strtotime('-7 days')))
- ->where('date', '<=', $today)
- ->field('date, daily_resources, resource_downloads')
- ->order('date', 'asc')
- ->select()
- ->toArray();
+ // 访问数据
+ $visitData[] = [
+ 'date' => $date,
+ 'visits' => $dayStats ? intval($dayStats['daily_visits']) : 0,
+ 'uv' => $dayStats ? intval($dayStats['unique_visitors']) : 0
+ ];
- // 获取文章访问统计
- $articleStats = DailyStats::where('date', '>=', date('Y-m-d', strtotime('-7 days')))
- ->where('date', '<=', $today)
- ->field('date, daily_articles, article_views')
- ->order('date', 'asc')
- ->select()
- ->toArray();
+ // 用户数据
+ $userData[] = [
+ 'date' => $date,
+ 'total' => $dayStats ? intval($dayStats['total_users']) : 0,
+ 'new' => $dayStats ? intval($dayStats['new_users']) : 0
+ ];
- // 获取最近的操作日志
- $recentActivities = LogsOperation::field('operation_time, module, operation')
- ->order('operation_time desc')
- ->limit(10)
- ->select()
- ->each(function($item) {
- // 格式化时间
- $item['time'] = date('Y年m月d日 H:i:s', strtotime($item['operation_time']));
- // 格式化操作内容
- $item['content'] = date('Y年m月d日 H:i:s', strtotime($item['operation_time'])) . '在【' . $item['module'] . '】模块进行操作:' . $item['operation'];
- return $item;
- });
-
+ // 资源数据
+ $resourceData[] = [
+ 'date' => $date,
+ 'total' => $dayStats ? intval($dayStats['total_resources']) : 0,
+ 'new' => $dayStats ? intval($dayStats['daily_resources']) : 0,
+ 'downloads' => $dayStats ? intval($dayStats['resource_downloads']) : 0
+ ];
- // 准备图表数据
- $chartData = [
- 'visitTrend' => $this->formatVisitTrendData($last7Days),
- 'userGrowth' => $this->formatUserGrowthData($userGrowth),
- 'resourceStats' => $this->formatResourceStatsData($resourceStats),
- 'articleStats' => $this->formatArticleStatsData($articleStats)
- ];
+ // 文章数据
+ $articleData[] = [
+ 'date' => $date,
+ 'total' => $dayStats ? intval($dayStats['total_articles']) : 0,
+ 'new' => $dayStats ? intval($dayStats['daily_articles']) : 0,
+ 'views' => $dayStats ? intval($dayStats['article_views']) : 0
+ ];
+ }
- // 准备统计数据
- $stats = [
- 'total_users' => $todayStats['total_users'] ?? 0,
- 'daily_visits' => $todayStats['daily_visits'] ?? 0,
- 'total_articles' => $todayStats['total_articles'] ?? 0,
- 'total_resources' => $todayStats['total_resources'] ?? 0,
- ];
+ // 获取今日统计数据
+ $today = date('Y-m-d');
+ $todayStats = Db::name('daily_stats')
+ ->where('date', $today)
+ ->find();
- return View::fetch('', [
- 'stats' => $stats,
- 'chartData' => $chartData,
- 'recentActivities' => $recentActivities
- ]);
+ // 获取最近的操作日志
+ $recentActivities = Db::name('logs_operation')
+ ->field('operation_time, module, operation')
+ ->order('operation_time DESC')
+ ->limit(5)
+ ->select()
+ ->each(function($item) {
+ $item['content'] = date('Y年m月d日 H:i:s', strtotime($item['operation_time'])) . ' 在 ' .
+ ($item['module'] ?: '未知模块') . ' ' .
+ ($item['operation'] ?: '未知操作');
+ $item['icon'] = $this->getActivityIcon($item['module'] ?: '其他');
+ return $item;
+ });
+
+ // 处理图表数据
+ $chartData = [
+ 'visitTrend' => [
+ 'dates' => array_map(function($item) { return date('m-d', strtotime($item['date'])); }, $visitData),
+ 'visits' => array_column($visitData, 'visits'),
+ 'uvs' => array_column($visitData, 'uv')
+ ],
+ 'userGrowth' => [
+ 'dates' => array_map(function($item) { return date('m-d', strtotime($item['date'])); }, $userData),
+ 'newUsers' => array_column($userData, 'new'),
+ 'totalUsers' => array_column($userData, 'total')
+ ],
+ 'resourceStats' => [
+ 'dates' => array_map(function($item) { return date('m-d', strtotime($item['date'])); }, $resourceData),
+ 'newResources' => array_column($resourceData, 'new'),
+ 'totalResources' => array_column($resourceData, 'total'),
+ 'downloads' => array_column($resourceData, 'downloads')
+ ],
+ 'articleStats' => [
+ 'dates' => array_map(function($item) { return date('m-d', strtotime($item['date'])); }, $articleData),
+ 'newArticles' => array_column($articleData, 'new'),
+ 'totalArticles' => array_column($articleData, 'total'),
+ 'views' => array_column($articleData, 'views')
+ ]
+ ];
+
+ // 传递给视图
+ View::assign([
+ 'todayStats' => $todayStats ?: [
+ 'total_users' => 0,
+ 'new_users' => 0,
+ 'total_visits' => 0,
+ 'daily_visits' => 0,
+ 'unique_visitors' => 0,
+ 'total_articles' => 0,
+ 'daily_articles' => 0,
+ 'article_views' => 0,
+ 'total_resources' => 0,
+ 'daily_resources' => 0,
+ 'resource_downloads' => 0
+ ],
+ 'recentActivities' => $recentActivities,
+ 'chartData' => $chartData
+ ]);
+
+ return View::fetch();
+ } catch (\Exception $e) {
+ // 记录错误日志
+ \think\facade\Log::error('获取统计数据失败:' . $e->getMessage());
+ // 返回空数据
+ View::assign([
+ 'todayStats' => [
+ 'total_users' => 0,
+ 'new_users' => 0,
+ 'total_visits' => 0,
+ 'daily_visits' => 0,
+ 'unique_visitors' => 0,
+ 'total_articles' => 0,
+ 'daily_articles' => 0,
+ 'article_views' => 0,
+ 'total_resources' => 0,
+ 'daily_resources' => 0,
+ 'resource_downloads' => 0
+ ],
+ 'recentActivities' => [],
+ 'chartData' => [
+ 'visitTrend' => ['dates' => [], 'visits' => [], 'uvs' => []],
+ 'userGrowth' => ['dates' => [], 'newUsers' => [], 'totalUsers' => []],
+ 'resourceStats' => ['dates' => [], 'newResources' => [], 'totalResources' => [], 'downloads' => []],
+ 'articleStats' => ['dates' => [], 'newArticles' => [], 'totalArticles' => [], 'views' => []]
+ ]
+ ]);
+ return View::fetch();
+ }
}
/**
diff --git a/app/admin/view/index/welcome.php b/app/admin/view/index/welcome.php
index 45efed5..5ac53a4 100644
--- a/app/admin/view/index/welcome.php
+++ b/app/admin/view/index/welcome.php
@@ -211,22 +211,22 @@
用户总数
-
{$stats.total_users|number_format}
+
{$todayStats.total_users|number_format}
👥
今日访问
-
{$stats.daily_visits|number_format}
+
{$todayStats.daily_visits|number_format}
📊
文章总数
-
{$stats.total_articles|number_format}
+
{$todayStats.total_articles|number_format}
📝
资源总数
-
{$stats.total_resources|number_format}
+
{$todayStats.total_resources|number_format}
📦
@@ -504,7 +504,6 @@ function initVisitTrend() {
// 用户增长图表
function initUserGrowth() {
var chart = echarts.init(document.getElementById('userGrowth'));
- window.userChart = chart;
var option = {
tooltip: {
trigger: 'axis',
@@ -527,7 +526,7 @@ function initUserGrowth() {
xAxis: {
type: 'category',
boundaryGap: false,
- data: []
+ data: {$chartData.userGrowth.dates|json_encode}
},
yAxis: {
type: 'value'
@@ -536,7 +535,7 @@ function initUserGrowth() {
{
name: '新增用户',
type: 'bar',
- data: [],
+ data: {$chartData.userGrowth.newUsers|json_encode},
itemStyle: {
color: '#3881fd'
}
@@ -545,7 +544,7 @@ function initUserGrowth() {
name: '总用户数',
type: 'line',
smooth: true,
- data: [],
+ data: {$chartData.userGrowth.totalUsers|json_encode},
itemStyle: {
color: '#10b981'
},
@@ -561,7 +560,6 @@ function initUserGrowth() {
// 资源统计图表
function initResourceStats() {
var chart = echarts.init(document.getElementById('resourceStats'));
- window.resourceChart = chart;
var option = {
tooltip: {
trigger: 'axis',
@@ -573,7 +571,7 @@ function initResourceStats() {
}
},
legend: {
- data: ['新增资源', '总资源数']
+ data: ['新增资源', '总资源数', '下载量']
},
grid: {
left: '3%',
@@ -584,7 +582,7 @@ function initResourceStats() {
xAxis: {
type: 'category',
boundaryGap: false,
- data: []
+ data: {$chartData.resourceStats.dates|json_encode}
},
yAxis: {
type: 'value'
@@ -593,7 +591,7 @@ function initResourceStats() {
{
name: '新增资源',
type: 'bar',
- data: [],
+ data: {$chartData.resourceStats.newResources|json_encode},
itemStyle: {
color: '#3881fd'
}
@@ -602,13 +600,25 @@ function initResourceStats() {
name: '总资源数',
type: 'line',
smooth: true,
- data: [],
+ data: {$chartData.resourceStats.totalResources|json_encode},
itemStyle: {
color: '#10b981'
},
lineStyle: {
width: 3
}
+ },
+ {
+ name: '下载量',
+ type: 'line',
+ smooth: true,
+ data: {$chartData.resourceStats.downloads|json_encode},
+ itemStyle: {
+ color: '#f59e0b'
+ },
+ lineStyle: {
+ width: 3
+ }
}
]
};
@@ -618,7 +628,6 @@ function initResourceStats() {
// 文章统计图表
function initArticleStats() {
var chart = echarts.init(document.getElementById('articleStats'));
- window.articleChart = chart;
var option = {
tooltip: {
trigger: 'axis',
@@ -630,7 +639,7 @@ function initArticleStats() {
}
},
legend: {
- data: ['新增文章', '总文章数']
+ data: ['新增文章', '总文章数', '浏览量']
},
grid: {
left: '3%',
@@ -641,7 +650,7 @@ function initArticleStats() {
xAxis: {
type: 'category',
boundaryGap: false,
- data: []
+ data: {$chartData.articleStats.dates|json_encode}
},
yAxis: {
type: 'value'
@@ -650,7 +659,7 @@ function initArticleStats() {
{
name: '新增文章',
type: 'bar',
- data: [],
+ data: {$chartData.articleStats.newArticles|json_encode},
itemStyle: {
color: '#3881fd'
}
@@ -659,13 +668,25 @@ function initArticleStats() {
name: '总文章数',
type: 'line',
smooth: true,
- data: [],
+ data: {$chartData.articleStats.totalArticles|json_encode},
itemStyle: {
color: '#10b981'
},
lineStyle: {
width: 3
}
+ },
+ {
+ name: '浏览量',
+ type: 'line',
+ smooth: true,
+ data: {$chartData.articleStats.views|json_encode},
+ itemStyle: {
+ color: '#f59e0b'
+ },
+ lineStyle: {
+ width: 3
+ }
}
]
};
@@ -674,18 +695,32 @@ function initArticleStats() {
// 初始化所有图表
document.addEventListener('DOMContentLoaded', function() {
- initVisitTrend();
- initUserGrowth();
- initResourceStats();
- initArticleStats();
-
- // 监听窗口大小变化,重绘图表
- window.addEventListener('resize', function() {
- var charts = document.querySelectorAll('.chart-container');
- charts.forEach(function(chart) {
- echarts.getInstanceByDom(chart)?.resize();
+ // 确保ECharts已加载
+ if (typeof echarts === 'undefined') {
+ console.error('ECharts未加载');
+ return;
+ }
+
+ // 初始化图表
+ try {
+ initVisitTrend();
+ initUserGrowth();
+ initResourceStats();
+ initArticleStats();
+
+ // 监听窗口大小变化,重绘图表
+ window.addEventListener('resize', function() {
+ var charts = document.querySelectorAll('.chart-container');
+ charts.forEach(function(chart) {
+ var instance = echarts.getInstanceByDom(chart);
+ if (instance) {
+ instance.resize();
+ }
+ });
});
- });
+ } catch (error) {
+ console.error('初始化图表失败:', error);
+ }
});
diff --git a/runtime/admin/temp/060aaf82e6a412e1d93b52eb2415c06f.php b/runtime/admin/temp/060aaf82e6a412e1d93b52eb2415c06f.php
new file mode 100644
index 0000000..4f5dad4
--- /dev/null
+++ b/runtime/admin/temp/060aaf82e6a412e1d93b52eb2415c06f.php
@@ -0,0 +1,298 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/runtime/admin/temp/2022feb4cf19b13311bd33466ada27df.php b/runtime/admin/temp/2022feb4cf19b13311bd33466ada27df.php
new file mode 100644
index 0000000..d261565
--- /dev/null
+++ b/runtime/admin/temp/2022feb4cf19b13311bd33466ada27df.php
@@ -0,0 +1,363 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/runtime/admin/temp/792969fb591a0f355761a1b3bf3d1226.php b/runtime/admin/temp/792969fb591a0f355761a1b3bf3d1226.php
index 61ccadd..45f63c2 100644
--- a/runtime/admin/temp/792969fb591a0f355761a1b3bf3d1226.php
+++ b/runtime/admin/temp/792969fb591a0f355761a1b3bf3d1226.php
@@ -1,4 +1,4 @@
-
+
@@ -305,22 +305,22 @@
@@ -598,7 +598,6 @@ function initVisitTrend() {
// 用户增长图表
function initUserGrowth() {
var chart = echarts.init(document.getElementById('userGrowth'));
- window.userChart = chart;
var option = {
tooltip: {
trigger: 'axis',
@@ -621,7 +620,7 @@ function initUserGrowth() {
xAxis: {
type: 'category',
boundaryGap: false,
- data: []
+ data:
},
yAxis: {
type: 'value'
@@ -630,7 +629,7 @@ function initUserGrowth() {
{
name: '新增用户',
type: 'bar',
- data: [],
+ data: ,
itemStyle: {
color: '#3881fd'
}
@@ -639,7 +638,7 @@ function initUserGrowth() {
name: '总用户数',
type: 'line',
smooth: true,
- data: [],
+ data: ,
itemStyle: {
color: '#10b981'
},
@@ -655,7 +654,6 @@ function initUserGrowth() {
// 资源统计图表
function initResourceStats() {
var chart = echarts.init(document.getElementById('resourceStats'));
- window.resourceChart = chart;
var option = {
tooltip: {
trigger: 'axis',
@@ -667,7 +665,7 @@ function initResourceStats() {
}
},
legend: {
- data: ['新增资源', '总资源数']
+ data: ['新增资源', '总资源数', '下载量']
},
grid: {
left: '3%',
@@ -678,7 +676,7 @@ function initResourceStats() {
xAxis: {
type: 'category',
boundaryGap: false,
- data: []
+ data:
},
yAxis: {
type: 'value'
@@ -687,7 +685,7 @@ function initResourceStats() {
{
name: '新增资源',
type: 'bar',
- data: [],
+ data: ,
itemStyle: {
color: '#3881fd'
}
@@ -696,13 +694,25 @@ function initResourceStats() {
name: '总资源数',
type: 'line',
smooth: true,
- data: [],
+ data: ,
itemStyle: {
color: '#10b981'
},
lineStyle: {
width: 3
}
+ },
+ {
+ name: '下载量',
+ type: 'line',
+ smooth: true,
+ data: ,
+ itemStyle: {
+ color: '#f59e0b'
+ },
+ lineStyle: {
+ width: 3
+ }
}
]
};
@@ -712,7 +722,6 @@ function initResourceStats() {
// 文章统计图表
function initArticleStats() {
var chart = echarts.init(document.getElementById('articleStats'));
- window.articleChart = chart;
var option = {
tooltip: {
trigger: 'axis',
@@ -724,7 +733,7 @@ function initArticleStats() {
}
},
legend: {
- data: ['新增文章', '总文章数']
+ data: ['新增文章', '总文章数', '浏览量']
},
grid: {
left: '3%',
@@ -735,7 +744,7 @@ function initArticleStats() {
xAxis: {
type: 'category',
boundaryGap: false,
- data: []
+ data:
},
yAxis: {
type: 'value'
@@ -744,7 +753,7 @@ function initArticleStats() {
{
name: '新增文章',
type: 'bar',
- data: [],
+ data: ,
itemStyle: {
color: '#3881fd'
}
@@ -753,13 +762,25 @@ function initArticleStats() {
name: '总文章数',
type: 'line',
smooth: true,
- data: [],
+ data: ,
itemStyle: {
color: '#10b981'
},
lineStyle: {
width: 3
}
+ },
+ {
+ name: '浏览量',
+ type: 'line',
+ smooth: true,
+ data: ,
+ itemStyle: {
+ color: '#f59e0b'
+ },
+ lineStyle: {
+ width: 3
+ }
}
]
};
@@ -768,18 +789,32 @@ function initArticleStats() {
// 初始化所有图表
document.addEventListener('DOMContentLoaded', function() {
- initVisitTrend();
- initUserGrowth();
- initResourceStats();
- initArticleStats();
-
- // 监听窗口大小变化,重绘图表
- window.addEventListener('resize', function() {
- var charts = document.querySelectorAll('.chart-container');
- charts.forEach(function(chart) {
- echarts.getInstanceByDom(chart)?.resize();
+ // 确保ECharts已加载
+ if (typeof echarts === 'undefined') {
+ console.error('ECharts未加载');
+ return;
+ }
+
+ // 初始化图表
+ try {
+ initVisitTrend();
+ initUserGrowth();
+ initResourceStats();
+ initArticleStats();
+
+ // 监听窗口大小变化,重绘图表
+ window.addEventListener('resize', function() {
+ var charts = document.querySelectorAll('.chart-container');
+ charts.forEach(function(chart) {
+ var instance = echarts.getInstanceByDom(chart);
+ if (instance) {
+ instance.resize();
+ }
+ });
});
- });
+ } catch (error) {
+ console.error('初始化图表失败:', error);
+ }
});