增加访问记录功能

This commit is contained in:
2023-06-28 11:12:30 +08:00
parent a12cca37e4
commit 65e1800c6f
18 changed files with 447 additions and 98 deletions

View File

@@ -8,18 +8,16 @@ use app\model\PostCategory;
use think\facade\Cache;
use think\facade\Session;
use think\facade\View;
use think\Request;
class Index extends Common
{
/**
* 显示资源列表
* 显示资源列表.
*
* @return \think\Response
*/
public function index()
{
$page_cache_key = md5($this->request->url());
$content = Cache::get($page_cache_key);
@@ -47,20 +45,18 @@ class Index extends Common
if (empty($sub_category_id)) {
$categorys = [$category_id];
$categorys = array_merge($categorys, array_column((array)Category::getListLevel($category_id), 3));
$categorys = array_merge($categorys, array_column((array) Category::getListLevel($category_id), 3));
$categorys_where = PostCategory::whereIn('category_id', $categorys);
$model_post = Post::hasWhere('categorys', $categorys_where)->where('status', 1)->order('id desc');
} else {
$model_sub_category = Category::find($sub_category_id);
$page_title .= "-{$model_sub_category->title}";
$model_post = Post::hasWhere('categorys', ['category_id' => $sub_category_id])->where('status', 1)->order('id desc');
}
} else {
$model_post = Post::where('status', 1)->order('id desc');
}
@@ -84,9 +80,9 @@ class Index extends Common
'category_id' => $this->request->param('category_id'),
'sub_category_id' => $this->request->param('sub_category_id'),
'page' => $page,
'keywords' => $keywords
'keywords' => $keywords,
],
'list_rows' => 10
'list_rows' => 10,
]);
View::assign('current_category', $current_category);
@@ -102,13 +98,12 @@ class Index extends Common
return $content;
}
public function logout()
{
Session::clear();
$back_url = $this->request->param('back_url', '/');
return $this->success('退出成功', $back_url);
}
}