diff --git a/app/controller/Share.php b/app/controller/Share.php index 75da8a8..b8c8edc 100644 --- a/app/controller/Share.php +++ b/app/controller/Share.php @@ -14,9 +14,18 @@ class Share $where = "id < ".$lastIndex; } $result['lastIndex'] = 0; - $list = Db::name("app_users")->where($where)->order("share_count desc,id desc")->limit(env("PAGE_COUNT"))->select()->toArray(); + + $list = Db::name("app_users")->where($where)->order('share_count desc,id desc')->limit(env("PAGE_COUNT"))->paginate([ + "list_rows" => env("PAGE_COUNT"), + "page" => $lastIndex + ]); + + if (empty($list)) { + return show("获取成功", SUCCESS_CODE, $result); + } + + foreach($list as $vo){ - $result['lastIndex'] = $vo['id']; $result['data'][] = [ "id"=>$vo['id'], "nickname"=>$vo['nickname'], @@ -26,6 +35,12 @@ class Share ]; } + if ($list->currentPage() < $list->lastPage()) { + $result['lastIndex'] = $lastIndex + 1; + } else { + $result['lastIndex'] = 0; + } + if (count($list) < env("PAGE_COUNT")) { $result["lastIndex"] = 0; }