diff --git a/app/index/controller/Article.php b/app/index/controller/Article.php index cba125e..22f0a35 100644 --- a/app/index/controller/Article.php +++ b/app/index/controller/Article.php @@ -40,7 +40,7 @@ class Article extends BaseController switch ($type) { //查询文章,15个分1页 case 'jie': - $artList = ArticleModel::field('id,title,cate_id,user_id,create_time,is_top,is_hot')->with([ + $artList = ArticleModel::field('id,title,title_color,cate_id,user_id,create_time,is_top,is_hot')->with([ 'cate' => function($query){ $query->where('delete_time',0)->field('id,catename'); }, @@ -51,7 +51,7 @@ class Article extends BaseController break; case 'hot': - $artList = ArticleModel::field('id,title,cate_id,user_id,create_time,is_top,is_hot')->with([ + $artList = ArticleModel::field('id,title,title_color,cate_id,user_id,create_time,is_top,is_hot')->with([ 'cate' => function($query){ $query->where('delete_time',0)->field('id,catename'); }, @@ -62,7 +62,7 @@ class Article extends BaseController break; case 'top': - $artList = ArticleModel::field('id,title,cate_id,user_id,create_time,is_top,is_hot')->with([ + $artList = ArticleModel::field('id,title,title_color,cate_id,user_id,create_time,is_top,is_hot')->with([ 'cate' => function($query){ $query->where('delete_time',0)->field('id,catename'); }, @@ -73,7 +73,7 @@ class Article extends BaseController break; default: - $artList = ArticleModel::field('id,title,cate_id,user_id,create_time,is_top,is_hot')->with([ + $artList = ArticleModel::field('id,title,title_color,cate_id,user_id,create_time,is_top,is_hot')->with([ 'cate' => function($query){ $query->where('delete_time',0)->field('id,catename'); }, @@ -113,7 +113,7 @@ class Article extends BaseController $query->field('id,name,nickname,user_img,area_id,vip'); } ])->find($id); - Cache::set('article_'.$id,$article,3600); + Cache::tag('tagArtDetail')->set('article_'.$id,$article,3600); } $comments = $article->comments()->where('status',1)->paginate(10); $article->inc('pv')->update(); @@ -317,7 +317,24 @@ class Article extends BaseController $res = ['status'=>0,'msg'=>'精贴已取消']; } } + //清除文章缓存 + Cache::tag('tagArtDetail')->clear(); return json($res); } + //改变标题颜色 + public function titleColor() + { + $data = Request::param(); + $result = ArticleModel::update($data); + if($result){ + //清除文章缓存 + Cache::tag(['tagArt','tagArtDetail'])->clear(); + $res = ['code'=> 0, 'msg'=>'标题颜色设置成功']; + }else{ + $res = ['code'=> -1, 'msg'=>'标题颜色设置失败']; + } + return json($res); + } + } \ No newline at end of file diff --git a/app/index/controller/Index.php b/app/index/controller/Index.php index 66ef248..e83bed2 100644 --- a/app/index/controller/Index.php +++ b/app/index/controller/Index.php @@ -34,13 +34,13 @@ class Index extends BaseController $query->field('id,name,nickname,user_img,area_id,vip'); } ])->withCount(['comments'])->order('create_time','desc')->limit(5)->select(); - Cache::set('arttop',$artTop,60); + Cache::tag('tagArtDetail')->set('arttop',$artTop,60); } //首页文章显示20条 $artList = Cache::get('artlist'); if(!$artList){ - $artList = Article::field('id,title,cate_id,user_id,create_time,is_hot')->with([ + $artList = Article::field('id,title,title_color,cate_id,user_id,create_time,is_hot')->with([ 'cate' => function($query){ $query->where('delete_time',0)->field('id,catename'); }, @@ -48,7 +48,7 @@ class Index extends BaseController $query->field('id,name,nickname,user_img,area_id,vip'); } ])->withCount(['comments'])->where(['status'=>1,'delete_time'=>0])->order('create_time','desc')->limit(20)->select(); - Cache::set('artlist',$artList,60); + Cache::tag('tagArt')->set('artlist',$artList,60); } //热议文章 diff --git a/view/index/article/add.html b/view/index/article/add.html index e98eb87..8e15866 100644 --- a/view/index/article/add.html +++ b/view/index/article/add.html @@ -33,9 +33,11 @@ -