・北京
1.删除Art.php
2.在app/common/model/Article.php中,大约第300行,添加代码
[pre]
//发帖榜
public function posts($num)
{
$res = Cache::get('posts');
if(empty($res)){
$user = User::withCount('articles')->order(['articles_count'=>'desc','last_login_time'=>'desc'])->limit($num)->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['articles_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('posts',$res,3600);
}
return json($res);
}
[/pre]
3.app/index/controller/index.php中添加代码:
[pre]
//回帖榜
public function reply()
{
$comment = new \app\common\model\Comment;
return $comment->reply(20);
}
//下面是你需要添加的代码
//发帖榜
public function posts()
{
return Article::posts(20);
}
[/pre]
4.url
[pre]
//注意这里,地址是这个
var replyUrlS = "{:url('index/posts')}";
[/pre]