sort = $item->id; $item->save(); } /** * 获取文章列表 * @param $categoryId 分类ID * @param int $per 每页数量 * @param string $keyword 关键词 * @param array $param 文章类型:置顶、热门、推荐 ['top','hot','recommend'] * @param int $status 文章状态,-1表示不限制 * @return \think\Paginator * @throws \think\db\exception\DbException */ public static function getList( $per = 20, $keyword = '') { $whereMap = []; $pageParam = []; if (!empty($keyword)) { $whereMap[] = ['title', 'like', '%' . $keyword . '%']; $pageParam['keyword'] = $keyword; } $paginate = [ 'list_rows' => $per, 'query' => $pageParam ]; return self::when(count($whereMap) > 0, function ($query) use ($whereMap) { $query->where($whereMap); }) ->order("sort desc") ->paginate($paginate, false); } // ----------页面函数 }