diff --git a/app/index/controller/Index.php b/app/index/controller/Index.php index fe8033b..8f4b252 100644 --- a/app/index/controller/Index.php +++ b/app/index/controller/Index.php @@ -93,23 +93,27 @@ class Index extends BaseController //回帖榜 public function reply() { - $user = User::withCount('comments')->order(['comments_count'=>'desc','last_login_time'=>'desc'])->limit(20)->select(); - if($user) - { - $res['status'] = 0; - $res['data'] = array(); - foreach ($user as $key=>$v) { - - $u['uid'] = (string) url('user/home',['id'=>$v['id']]); - $u['count(*)'] = $v['comments_count']; - if($v['nickname']) - { - $u['user'] = ['username'=>$v['nickname'],'avatar'=>$v['user_img']]; - } else { - $u['user'] = ['username'=>$v['name'],'avatar'=>$v['user_img']]; - } - $res['data'][] = $u; - } + $res = Cache::get('reply'); + if(!$res){ + $user = User::withCount('comments')->order(['comments_count'=>'desc','last_login_time'=>'desc'])->limit(20)->select(); + if($user) + { + $res['status'] = 0; + $res['data'] = array(); + foreach ($user as $key=>$v) { + + $u['uid'] = (string) url('user/home',['id'=>$v['id']]); + $u['count(*)'] = $v['comments_count']; + if($v['nickname']) + { + $u['user'] = ['username'=>$v['nickname'],'avatar'=>$v['user_img']]; + } else { + $u['user'] = ['username'=>$v['name'],'avatar'=>$v['user_img']]; + } + $res['data'][] = $u; + } + } + Cache::set('reply',$res,3600); } return json($res); }