chore: 重写初始提交(清空历史,整理后全量提交)
This commit is contained in:
@@ -0,0 +1,91 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | YwxApp [ WE CAN DO IT JUST THINK ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2026-2036 http://ywxapp.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: ywxapp<admin@ywxapp.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types = 1);
|
||||
|
||||
namespace addon\blog\controller\backend;
|
||||
|
||||
use addon\blog\model\BlogArticle as ArticleModel;
|
||||
use ywxapp\model\MemberUser as UserModel;
|
||||
use addon\blog\model\BlogComment as CommentModel;
|
||||
use addon\blog\model\BlogVisit as VisitModel;
|
||||
use addon\blog\model\BlogLike as LikeModel;
|
||||
use think\facade\View;
|
||||
use ywxapp\controller\BackendBase;
|
||||
|
||||
/**
|
||||
* Dashboard 类
|
||||
*
|
||||
* @author ywxapp <admin@ywxapp.cn>
|
||||
*/
|
||||
class Dashboard extends BackendBase
|
||||
{
|
||||
|
||||
protected $noNeedVerify = ['*'];
|
||||
|
||||
|
||||
protected function initialize()
|
||||
{
|
||||
}
|
||||
/**
|
||||
* 今日起始时间戳
|
||||
*/
|
||||
private function todayStart()
|
||||
{
|
||||
return strtotime(date('Y-m-d'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 仪表盘首页
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$today = $this->todayStart();
|
||||
|
||||
$stats = [
|
||||
'article_count' => ArticleModel::count(),
|
||||
'user_count' => UserModel::count(),
|
||||
'comment_count' => CommentModel::count(),
|
||||
'today_article' => ArticleModel::where('create_at', '>=', $today)->count(),
|
||||
'today_user' => UserModel::where('create_at', '>=', $today)->count(),
|
||||
'today_comment' => CommentModel::where('create_at', '>=', $today)->count(),
|
||||
'today_visit' => VisitModel::where('create_at', '>=', $today)->count(),
|
||||
'total_visit' => VisitModel::count(),
|
||||
];
|
||||
|
||||
$latestArticles = ArticleModel::with(['user', 'category'])
|
||||
->order('create_at', 'desc')
|
||||
->limit(5)
|
||||
->select();
|
||||
|
||||
$latestComments = CommentModel::with(['user', 'article'])
|
||||
->order('create_at', 'desc')
|
||||
->limit(5)
|
||||
->select();
|
||||
|
||||
$hotArticles = ArticleModel::with(['user', 'category'])
|
||||
->order('view_count', 'desc')
|
||||
->limit(5)
|
||||
->select();
|
||||
|
||||
$visitTrend = [];
|
||||
for ($i = 6; $i >= 0; $i--) {
|
||||
$date = date('Y-m-d', strtotime("-{$i} days"));
|
||||
$count = VisitModel::whereBetween('create_at', [strtotime($date), strtotime($date . ' +1 day') - 1])->count();
|
||||
$visitTrend[] = ['date' => $date, 'count' => $count];
|
||||
}
|
||||
|
||||
return $this->view->fetch('dashboard/index', [
|
||||
'stats' => $stats,
|
||||
'latestArticles' => $latestArticles,
|
||||
'latestComments' => $latestComments,
|
||||
'hotArticles' => $hotArticles,
|
||||
'visitTrend' => $visitTrend,
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user