阶段更新

This commit is contained in:
2021-10-11 15:56:12 +08:00
parent 11b9e2ae76
commit 3381820ba0
17 changed files with 319 additions and 534 deletions

View File

@@ -52,39 +52,36 @@ function getOneArticleBYCate($categoryId, $result = '')
* @Date : 2020/9/10 10:05
* @param $categoryId
* @param int $take
* @param string $mark
* @param int $recommen
* @return \App\Models\Article
*/
function getArticlesBYCate($categoryId, $take = 8, $mark = 'one')
function getArticlesBYCate($categoryId, $take = 8, $recommen = 0)
{
if ($mark == 'one') {
$articles = Article::where('status', 1)
->ByCategory($categoryId)
->latest('sort')
->latest()
->take($take)
->get();
} else {
$cate = Category::find($categoryId);
$ids = $cate ? $cate->getAllChildrenId() : [];
$cate = Category::find($categoryId);
$ids = $cate ? $cate->getAllChildrenId() : [];
$articles = Article::where('status', 1)
->ByCategory($ids)
->latest('sort')
->latest()
->take($take)
->get();
}
$articles = Article::where('status', 1)
->ByCategory([$categoryId])
->latest('sort')
->latest()
->when($recommen, function ($q) use ($recommen) {
$q->where('recommen', 1);
})
->take($take)
->get();
return $articles;
}
//获取子分类
function getCateChild($categoryId)
function getCateChild($categoryId, $take = '')
{
return Category::where('status', 1)
->where('parent_id', $categoryId)
->orderBy('order', 'desc')
->when($take, function ($q) use ($take) {
$q->take($take);
})
->get();
}