From 9d3a0221b3ba6bf8610c6814cec1f74779a812a2 Mon Sep 17 00:00:00 2001 From: augushong Date: Thu, 29 Jun 2023 10:31:39 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=AE=BF=E9=97=AE=E8=AE=B0?= =?UTF-8?q?=E5=BD=95=E5=88=97=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/index/controller/BaseController.php | 25 +++++++++------ app/index/controller/Index.php | 23 ++++++++++++++ view/index/common/_right.html | 4 +++ view/index/index/visit.html | 41 +++++++++++++++++++++++++ view/index/post/read.html | 5 ++- 5 files changed, 87 insertions(+), 11 deletions(-) create mode 100644 view/index/index/visit.html diff --git a/app/index/controller/BaseController.php b/app/index/controller/BaseController.php index e441826..87bd2c6 100644 --- a/app/index/controller/BaseController.php +++ b/app/index/controller/BaseController.php @@ -5,6 +5,7 @@ namespace app\index\controller; use app\BaseController as AppBaseController; use app\common\Bootstrap; use think\exception\HttpResponseException; +use think\facade\Env; use think\facade\Request; use think\Paginator; @@ -18,21 +19,25 @@ class BaseController extends AppBaseController return new Bootstrap($items, $listRows, $currentPage, $total, $simple, $options); }); - $main_domain = get_system_config('main_domain'); - $url = Request::url(); + $debug = Env::get('app_debug'); - if (!empty($main_domain)) { - if (Request::host() != $main_domain) { + if (!$debug) { + // 调试模式不要跳转域名和协议 + $main_domain = get_system_config('main_domain'); + $url = Request::url(); - throw new HttpResponseException(redirect(Request::scheme() . '://' . $main_domain . '' . $url)); + if (!empty($main_domain)) { + if (Request::host() != $main_domain) { + throw new HttpResponseException(redirect(Request::scheme() . '://' . $main_domain . '' . $url)); + } } - } - $is_jump_https = get_system_config('is_jump_https', 0); + $is_jump_https = get_system_config('is_jump_https', 0); - if ($is_jump_https == 1) { - if (Request::scheme() != 'https') { - throw new HttpResponseException(redirect('https://' . Request::host() . '' . $url)); + if ($is_jump_https == 1) { + if (Request::scheme() != 'https') { + throw new HttpResponseException(redirect('https://' . Request::host() . '' . $url)); + } } } } diff --git a/app/index/controller/Index.php b/app/index/controller/Index.php index b67489b..11dc92c 100644 --- a/app/index/controller/Index.php +++ b/app/index/controller/Index.php @@ -5,6 +5,7 @@ namespace app\index\controller; use app\model\Category; use app\model\Post; use app\model\PostCategory; +use app\model\PostVisit; use think\facade\Cache; use think\facade\Session; use think\facade\View; @@ -98,6 +99,28 @@ class Index extends Common return $content; } + public function visit() + { + $post_id = $this->request->param('post_id'); + + $model_list_visit = PostVisit::with(['post'])->order('id desc'); + + if(!empty($post_id)) { + $model_list_visit->where('post_id', $post_id); + } + + $list_visit = $model_list_visit->paginate([ + 'url' => 'Index/visit', + 'list_rows' => 20, + 'query' => [ + 'post_id' => $post_id, + ], + ]); + View::assign('list_visit', $list_visit); + + return View::fetch(); + } + public function logout() { Session::clear(); diff --git a/view/index/common/_right.html b/view/index/common/_right.html index dca7991..6783467 100644 --- a/view/index/common/_right.html +++ b/view/index/common/_right.html @@ -39,6 +39,7 @@
最近浏览 + {empty name='Request.session.user_uid'} 点击登录 @@ -64,6 +65,9 @@
{/volist}
+
+ 更多记录,大家在看什么? +
累计浏览次数:{$total_hits}
一周浏览次数:{$total_week_hits}
今日浏览次数:{$total_day_hits}
diff --git a/view/index/index/visit.html b/view/index/index/visit.html new file mode 100644 index 0000000..34d6267 --- /dev/null +++ b/view/index/index/visit.html @@ -0,0 +1,41 @@ + + + + + + + 访问记录-{:get_system_config('site_name')} + {include file='common/_require'/} + + + +
+
+ {include file='common/_left'/} +
+
+
+ {volist name='list_visit' id='vo'} +
+
+
+
{$vo.nickname_title}
+
+ {$vo.create_time_title} + 《{$vo.post.title}》 +
+
+
+ {/volist} +
+ {$list_visit->render()|raw} +
+
+ {include file='common/_right'/} + +
+
+ + + + \ No newline at end of file diff --git a/view/index/post/read.html b/view/index/post/read.html index b2c8929..d4fecc2 100644 --- a/view/index/post/read.html +++ b/view/index/post/read.html @@ -154,7 +154,10 @@ {/volist} -
累计浏览次数:{$post->hits_title}
+
+ 更多记录,还有谁在看? +
+
累计浏览次数:{$post->hits_title}