field($field) ->order($order) ->paginate(['list_rows' => $pageSize, 'query' => request()->param()]); $page = $list->render(); $data['list'] = $list->toArray()['data']; $data['count'] = $list->total(); $data['last_page'] = $list->toArray()['last_page']; // $data['page'] = $page; return $data; } /** * 获取全部列表(不分页) */ public static function getAllList($where = [], $field = '*', $order = 'publish_time desc', $limit = '0') { $data = self::where($where) ->field($field) ->order($order) ->limit($limit) ->select(); return $data; } /** * 获取单条数据 */ public static function getInfo($where = [], $field = '*') { $data = self::where($where) ->field($field) ->find(); return $data; } /** * 获取热榜资讯 */ public static function getHotNews($limit = 10, $field = '*') { return self::where('status', 1) ->where('is_hot', 1) ->field($field) ->order('publish_time desc') ->limit($limit) ->select(); } /** * 获取精选资讯 */ public static function getFeaturedNews($limit = 10, $field = '*') { return self::where('status', 1) ->where('is_featured', 1) ->field($field) ->order('publish_time desc') ->limit($limit) ->select(); } /** * 根据作者ID获取资讯 */ public static function getNewsByAuthor($authorId, $limit = 10, $field = '*') { return self::where('status', 1) ->where('author_id', $authorId) ->field($field) ->order('publish_time desc') ->limit($limit) ->select(); } /** * 搜索资讯 */ public static function searchNews($keyword, $field = '*', $pageSize = 15) { return self::where('status', 1) ->where('title', 'like', '%' . $keyword . '%') ->field($field) ->order('publish_time desc') ->paginate(['list_rows' => $pageSize, 'query' => request()->param()]); } }