diff --git a/app/common/model/Tag.php b/app/common/model/Tag.php index 31307ff..9a47289 100644 --- a/app/common/model/Tag.php +++ b/app/common/model/Tag.php @@ -62,4 +62,37 @@ class Tag extends BaseModel } return $this->saveAll($saveAll); } + + + + /** + * 列表 + * @param $where + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @author 李玉坤 + * @date 2021-02-15 23:24 + */ + public static function getList($where): array + { + $list = cache('index:tagList'); + if ($list){ + return json_decode($list,true); + }else{ + $tagList = self::systemPage($where); + $list = []; + foreach ($tagList['data'] as $tag){ + $list[] = [ + "text" => $tag['name'], + "href" => url("/index/article/tag?t=".$tag['name'])->build() + ]; + } + if ($list){ + cache('index:tagList',json_encode($list),24*60*60); + } + } + return $list; + } } \ No newline at end of file diff --git a/app/index/common.php b/app/index/common.php index af2dcaf..d314ac2 100644 --- a/app/index/common.php +++ b/app/index/common.php @@ -367,7 +367,10 @@ function tpl_get_list($orderby, $pagesize, $cid, $type, $table = 'article', $whe break; case 'tag': //读取指定tag的文章 - $documentListModel = $documentListModel->where('a.keywords', 'like', "%$where%"); + $tag = substr(input('t'),0,strpos(input('t'),'.')); //搜索关键词 + $tagModel = new \app\common\model\Tag(); + $tagList = $tagModel->where('name',$tag)->select()->toArray(); + $documentListModel = $documentListModel->where('a.id', 'in', array_column($tagList,'document_id')); break; } $documentListModel = $documentListModel->order($orderby); diff --git a/app/index/controller/Article.php b/app/index/controller/Article.php index b5979e7..d646535 100644 --- a/app/index/controller/Article.php +++ b/app/index/controller/Article.php @@ -5,6 +5,7 @@ use app\common\model\Document; use app\common\model\DocumentCategory; use app\common\model\DocumentCategoryContent; use app\common\model\Comment as commentModel; +use app\common\model\Tag as TagModel; use app\Request; use think\facade\Log; @@ -237,6 +238,25 @@ class Article extends Base return $this->fetch(); } + /** + * 标签列表 + * @return mixed + * @author 李玉坤 + * @date 2021-11-11 0:27 + */ + public function tagList() + { + $where = Util::postMore([ + ['name',''], + ['document_id',''], + ['start_time',''], + ['end_time',''], + ['page',1], + ['limit',10] + ]); + return app("json")->layui(TagModel::getList($where)); + } + /** * 搜索页面 * @return string diff --git a/public/template/default/pc/article/detail.html b/public/template/default/pc/article/detail.html index f8072ae..42ce01d 100644 --- a/public/template/default/pc/article/detail.html +++ b/public/template/default/pc/article/detail.html @@ -222,191 +222,191 @@