初步完成

This commit is contained in:
2021-03-25 16:05:06 +08:00
parent ae1ba1d4e9
commit 9d041184ea
124 changed files with 4358 additions and 4034 deletions

View File

@@ -3,6 +3,27 @@
use App\Models\Advert;
use App\Models\Category;
use App\Models\Article;
use Encore\Admin\Config\ConfigModel;
function getConfigList($name, $take = 8)
{
return ConfigModel::where('name', 'like', "{$name}%")->get();
}
function getConfig($name, $return = '')
{
$info = ConfigModel::where('name', $name)->first();
if ($info) {
if ($return) {
return $info->{$return};
}
return $info;
}
return new ConfigModel;
}
function getOneCategory($categoryId, $return = '')
{
@@ -47,17 +68,22 @@ function getOneArticleBYCate($categoryId, $result = '')
* Notes: 获取分类下的文章
* @Author: 玄尘
* @Date : 2020/9/10 10:05
* @param $categoryId
* @param $take
* @param $categoryId
* @param int $take
* @param string $mark 显示多少当前分类还是当前分类+子分类
* @param bool $hasCover
* @param string $order
* @return \App\Models\Article
*/
function getArticlesBYCate($categoryId, $take = 8, $mark = 'one')
function getArticlesBYCate($categoryId, $take = 8, $mark = 'one', $hasCover = false, $order = 'desc')
{
if ($mark == 'one') {
$articles = Article::where('category_id', $categoryId)
->where('status', 1)
->latest('sort')
->latest()
->orderBy('sort', $order)
->when($hasCover, function ($q) {
$q->whereNotNull('cover');
})
->take($take)
->get();
} else {
@@ -66,8 +92,10 @@ function getArticlesBYCate($categoryId, $take = 8, $mark = 'one')
$articles = Article::whereIn('category_id', $ids)
->where('status', 1)
->latest('sort')
->latest()
->when($hasCover, function ($q) {
$q->whereNotNull('cover');
})
->orderBy('sort', $order)
->take($take)
->get();
}
@@ -121,6 +149,7 @@ function getAdvertsByCate($categoryId, $take = 8)
return Advert::where('category_id', $categoryId)
->latest('sort')
->latest()
->take($take)->get();
->take($take)
->get();
}