diff --git a/app/admin/controller/AnalyticsController.php b/app/admin/controller/AnalyticsController.php index a71e46f..a1e7cb2 100644 --- a/app/admin/controller/AnalyticsController.php +++ b/app/admin/controller/AnalyticsController.php @@ -23,10 +23,8 @@ class AnalyticsController extends BaseController public function getContentStats() { try { - $today = date('Y-m-d'); $yesterday = date('Y-m-d', strtotime('-1 day')); $monthStart = date('Y-m-01'); - $yesterdayMonthStart = date('Y-m-01', strtotime('-1 day')); $monthEnd = date('Y-m-t 23:59:59'); // 总发布量 @@ -34,67 +32,30 @@ class AnalyticsController extends BaseController ->where('status', 2) ->count(); - // 昨日总发布量 - $yesterdayTotalArticles = Articles::where('delete_time', null) + // 昨日新增发布 + $yesterdayArticles = Articles::where('delete_time', null) ->where('status', 2) ->where('publish_date', '>=', $yesterday . ' 00:00:00') ->where('publish_date', '<=', $yesterday . ' 23:59:59') ->count(); - // 本月新增 + // 本月新增发布 $monthNewArticles = Articles::where('delete_time', null) ->where('status', 2) ->where('publish_date', '>=', $monthStart . ' 00:00:00') ->where('publish_date', '<=', $monthEnd) ->count(); - // 上月同期新增(用于对比) - $lastMonthStart = date('Y-m-01', strtotime('-1 month')); - $lastMonthEnd = date('Y-m-t 23:59:59', strtotime('-1 month')); - $lastMonthNewArticles = Articles::where('delete_time', null) - ->where('status', 2) - ->where('publish_date', '>=', $lastMonthStart . ' 00:00:00') - ->where('publish_date', '<=', $lastMonthEnd) - ->count(); - // 总点赞量 $totalLikes = Articles::where('delete_time', null) ->where('status', 2) ->sum('likes'); - // 昨日点赞量 - $yesterdayLikes = Articles::where('delete_time', null) - ->where('status', 2) - ->where('update_time', '>=', $yesterday . ' 00:00:00') - ->where('update_time', '<=', $yesterday . ' 23:59:59') - ->sum('likes'); - // 总访问量 $totalViews = Articles::where('delete_time', null) ->where('status', 2) ->sum('views'); - // 昨日访问量 - $yesterdayViews = Articles::where('delete_time', null) - ->where('status', 2) - ->where('update_time', '>=', $yesterday . ' 00:00:00') - ->where('update_time', '<=', $yesterday . ' 23:59:59') - ->sum('views'); - - // 计算增长率 - $articleGrowth = $yesterdayTotalArticles > 0 - ? round(($totalArticles - $yesterdayTotalArticles) / $yesterdayTotalArticles * 100, 2) - : 0; - $monthGrowth = $lastMonthNewArticles > 0 - ? round(($monthNewArticles - $lastMonthNewArticles) / $lastMonthNewArticles * 100, 2) - : 0; - $likesGrowth = $yesterdayLikes > 0 - ? round(($totalLikes - $yesterdayLikes) / $yesterdayLikes * 100, 2) - : 0; - $viewsGrowth = $yesterdayViews > 0 - ? round(($totalViews - $yesterdayViews) / $yesterdayViews * 100, 2) - : 0; - // 热门内容TOP5 $hotArticles = Articles::where('delete_time', null) ->where('status', 2) @@ -107,28 +68,11 @@ class AnalyticsController extends BaseController ->select(); $stats = [ - 'overview' => [ - 'total_articles' => [ - 'value' => $totalArticles, - 'yesterday' => $yesterdayTotalArticles, - 'growth' => $articleGrowth - ], - 'month_new' => [ - 'value' => $monthNewArticles, - 'last_month' => $lastMonthNewArticles, - 'growth' => $monthGrowth - ], - 'total_likes' => [ - 'value' => (int)$totalLikes, - 'yesterday' => (int)$yesterdayLikes, - 'growth' => $likesGrowth - ], - 'total_views' => [ - 'value' => (int)$totalViews, - 'yesterday' => (int)$yesterdayViews, - 'growth' => $viewsGrowth - ], - ], + 'total_articles' => $totalArticles, + 'yesterday_articles' => $yesterdayArticles, + 'month_articles' => $monthNewArticles, + 'total_likes' => (int)$totalLikes, + 'total_views' => (int)$totalViews, 'hot_articles' => $hotArticles->toArray() ]; diff --git a/app/admin/controller/UserController.php b/app/admin/controller/UserController.php index 0877b1e..60f10b6 100644 --- a/app/admin/controller/UserController.php +++ b/app/admin/controller/UserController.php @@ -20,7 +20,7 @@ class UserController extends BaseController */ public function getAllUsers() { - $users = AdminUser::where('delete_time', null)->field('id, account, name, phone,email, qq, sex, group_id, status, last_login_ip, login_count, create_time, update_time')->select()->toArray(); + $users = AdminUser::where('delete_time', null)->field('id, account, name, phone, birth, email, qq, sex, group_id, status, last_login_ip, login_count, create_time, update_time')->select()->toArray(); return json([ 'code' => 200, 'msg' => '获取成功', @@ -38,12 +38,12 @@ class UserController extends BaseController public function getUserInfo(int $id) { $user = AdminUser::where('id', $id) - ->field('id, account, name, phone,email, qq, sex, group_id, status') - ->find(); - + ->field('id, account, name, phone, email, birth, qq, sex, group_id, status, create_time, last_login_ip') + ->find(); + // 记录操作日志 $this->logSuccess('用户管理', '获取用户信息', ['id' => $id]); - + return json([ 'code' => 200, 'msg' => '获取成功', @@ -123,7 +123,7 @@ class UserController extends BaseController public function deleteUser(int $id) { $user = AdminUser::where('id', $id)->where('delete_time', null)->find(); - + if (!$user) { return json([ 'code' => 404, @@ -134,7 +134,7 @@ class UserController extends BaseController AdminUser::where('id', $id)->update([ 'delete_time' => date('Y-m-d H:i:s') ]); - + $this->logSuccess('用户管理', '删除用户', ['id' => $id]); return json([ 'code' => 200,