新增文章统计;新增浏览文章查看

This commit is contained in:
2023-06-28 16:09:53 +08:00
parent 9b29c5c67a
commit 37c20ae141
3 changed files with 23 additions and 8 deletions

View File

@@ -44,8 +44,8 @@ class Common extends BaseController
$top_posts = Post::where('is_top', 1)->limit(8)->where('type', 3)->cacheAlways('top_post')->select(); $top_posts = Post::where('is_top', 1)->limit(8)->where('type', 3)->cacheAlways('top_post')->select();
View::assign('top_posts', $top_posts); View::assign('top_posts', $top_posts);
$list_site_last_visit = PostVisit::order('id desc') $list_site_last_visit = PostVisit::with(['post'])->order('id desc')
->group('ip,uid') ->group('post_id,ip,uid')
->limit(6) ->limit(6)
->cache(60) ->cache(60)
->select(); ->select();
@@ -59,6 +59,12 @@ class Common extends BaseController
View::assign('total_week_hits', $total_week_hits); View::assign('total_week_hits', $total_week_hits);
View::assign('total_day_hits', $total_day_hits); View::assign('total_day_hits', $total_day_hits);
$total_post_count = Post::cache(60)->where('status', 1)->where('type', 3)->count();
View::assign('total_post_count', $total_post_count);
$total_month_post_count = Post::cache(60)->where('status', 1)->where('type', 3)->where('publish_time', '>', strtotime(date('Y-m-1 00:00:00')))->count();
View::assign('total_month_post_count', $total_month_post_count);
$this->userHubLogin(); $this->userHubLogin();
} }

View File

@@ -14,6 +14,11 @@ class PostVisit extends Model
{ {
// //
public function post()
{
return $this->belongsTo(Post::class, 'post_id');
}
public function getAvatarSrcAttr() public function getAvatarSrcAttr()
{ {
$value = $this->getAttr('avatar'); $value = $this->getAttr('avatar');

View File

@@ -32,12 +32,13 @@
{/volist} {/volist}
</div> </div>
<div style="margin-top: 10px;">全站文章:{$total_post_count}</div>
<div style="margin-top: 10px;">本月发表:{$total_month_post_count}</div>
</div> </div>
</div> </div>
<div class="session border"> <div class="session border">
<div class="header"> <div class="header">
<span>最近文章浏览</span> <span>最近浏览</span>
<span style="font-size: 12px;"> <span style="font-size: 12px;">
{empty name='Request.session.user_uid'} {empty name='Request.session.user_uid'}
<a href="{$login_url|default=''}">点击登录</a> <a href="{$login_url|default=''}">点击登录</a>
@@ -55,14 +56,17 @@
<div class="ul-avatar-sidebar-list-item-img" style="background-image: url({$vo.avatar_src});"></div> <div class="ul-avatar-sidebar-list-item-img" style="background-image: url({$vo.avatar_src});"></div>
<div class="ul-avatar-sidebar-list-item-info"> <div class="ul-avatar-sidebar-list-item-info">
<div class="ul-avatar-sidebar-list-item-title">{$vo.nickname_title}</div> <div class="ul-avatar-sidebar-list-item-title">{$vo.nickname_title}</div>
<div class="ul-avatar-sidebar-list-item-intro" style="color: #000;">{$vo.create_time_title}</div> <div class="ul-avatar-sidebar-list-item-intro" style="color: #000;">
<span>{$vo.create_time_title}</span>
<a href="{$vo.post.read_url}" title="{$vo.post.title}">《{$vo.post.title}》</a>
</div>
</div> </div>
</div> </div>
{/volist} {/volist}
</div> </div>
<div>累计文章浏览次数:{$total_hits}</div> <div>累计浏览次数:{$total_hits}</div>
<div>一周文章浏览次数:{$total_week_hits}</div> <div>一周浏览次数:{$total_week_hits}</div>
<div>今日文章浏览次数:{$total_day_hits}</div> <div>今日浏览次数:{$total_day_hits}</div>
</div> </div>
</div> </div>
<div class="session border"> <div class="session border">