改版
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
use App\Models\Advert;
|
||||
use App\Models\Category;
|
||||
use App\Models\Article;
|
||||
use App\Models\Resume;
|
||||
use Encore\Admin\Config\ConfigModel;
|
||||
|
||||
function getConfigList($name, $take = 8)
|
||||
@@ -41,6 +42,7 @@ function getOneCategory($categoryId, $return = '')
|
||||
|
||||
/**
|
||||
* Notes: 获取文章分类详情
|
||||
*
|
||||
* @Author: 玄尘
|
||||
* @Date : 2020/9/10 13:21
|
||||
* @param $categoryId
|
||||
@@ -50,12 +52,12 @@ function getOneCategory($categoryId, $return = '')
|
||||
function getOneArticleBYCate($categoryId, $result = '')
|
||||
{
|
||||
$info = Article::latest('sort')
|
||||
->whereHas('categories', function ($q) use ($categoryId) {
|
||||
$q->where('id', $categoryId);
|
||||
})
|
||||
->latest('sort')
|
||||
->latest('created_at')
|
||||
->first();
|
||||
->whereHas('categories', function ($q) use ($categoryId) {
|
||||
$q->where('id', $categoryId);
|
||||
})
|
||||
->latest('sort')
|
||||
->latest('created_at')
|
||||
->first();
|
||||
|
||||
if ($info) {
|
||||
if ($result) {
|
||||
@@ -67,49 +69,49 @@ function getOneArticleBYCate($categoryId, $result = '')
|
||||
return '';
|
||||
}
|
||||
|
||||
return new Article;
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes: 获取分类下的文章
|
||||
*
|
||||
* @Author: 玄尘
|
||||
* @Date : 2020/9/10 10:05
|
||||
* @param $categoryId
|
||||
* @param int $take
|
||||
* @param string $mark 显示多少当前分类还是当前分类+子分类
|
||||
* @param bool $hasCover
|
||||
* @Date: 2021/12/1 13:27
|
||||
* @param $categoryId
|
||||
* @param int $take
|
||||
* @param string $mark
|
||||
* @param false $hasCover
|
||||
* @param string $order
|
||||
* @return \App\Models\Article
|
||||
* @return mixed
|
||||
*/
|
||||
function getArticlesBYCate($categoryId, $take = 8, $mark = 'one', $hasCover = false, $order = 'desc')
|
||||
function getArticlesBYCate($categoryId, int $take = 8, string $mark = 'one', $hasCover = false, string $order = 'desc')
|
||||
{
|
||||
if ($mark == 'one') {
|
||||
$articles = Article::where('status', 1)
|
||||
->whereHas('categories', function ($q) use ($categoryId) {
|
||||
$q->where('id', $categoryId);
|
||||
})
|
||||
->latest('sort')
|
||||
->latest('created_at')
|
||||
->when($hasCover, function ($q) {
|
||||
$q->whereNotNull('cover');
|
||||
})
|
||||
->take($take)
|
||||
->get();
|
||||
->whereHas('categories', function ($q) use ($categoryId) {
|
||||
$q->where('id', $categoryId);
|
||||
})
|
||||
->latest('sort')
|
||||
->latest('created_at')
|
||||
->when($hasCover, function ($q) {
|
||||
$q->whereNotNull('cover');
|
||||
})
|
||||
->take($take)
|
||||
->get();
|
||||
} else {
|
||||
$cate = Category::find($categoryId);
|
||||
$ids = $cate->getAllChildrenId();
|
||||
|
||||
$articles = Article::where('status', 1)
|
||||
->whereHas('categories', function ($q) use ($ids) {
|
||||
$q->whereIn('id', $ids);
|
||||
})
|
||||
->when($hasCover, function ($q) {
|
||||
$q->whereNotNull('cover');
|
||||
})
|
||||
->latest('sort')
|
||||
->latest('created_at')
|
||||
->take($take)
|
||||
->get();
|
||||
->whereHas('categories', function ($q) use ($ids) {
|
||||
$q->whereIn('id', $ids);
|
||||
})
|
||||
->when($hasCover, function ($q) {
|
||||
$q->whereNotNull('cover');
|
||||
})
|
||||
->latest('sort')
|
||||
->latest('created_at')
|
||||
->take($take)
|
||||
->get();
|
||||
}
|
||||
|
||||
return $articles;
|
||||
@@ -119,9 +121,9 @@ function getArticlesBYCate($categoryId, $take = 8, $mark = 'one', $hasCover = fa
|
||||
function getCateChild($categoryId)
|
||||
{
|
||||
return Category::where('status', 1)
|
||||
->where('parent_id', $categoryId)
|
||||
->orderBy('order', 'asc')
|
||||
->get();
|
||||
->where('parent_id', $categoryId)
|
||||
->orderBy('order', 'asc')
|
||||
->get();
|
||||
}
|
||||
|
||||
//获取顶级分类
|
||||
@@ -140,9 +142,9 @@ function getTopCate($categoryId)
|
||||
function getOneAdvertByCate($categoryId, $result = '')
|
||||
{
|
||||
$info = Advert::where('category_id', $categoryId)
|
||||
->latest('sort')
|
||||
->latest()
|
||||
->first();
|
||||
->latest('sort')
|
||||
->latest()
|
||||
->first();
|
||||
if ($info) {
|
||||
if ($result) {
|
||||
return $info->{$result};
|
||||
@@ -152,50 +154,57 @@ function getOneAdvertByCate($categoryId, $result = '')
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
|
||||
return new Advert;
|
||||
}
|
||||
|
||||
function getAdvertsByCate($categoryId, $take = 8)
|
||||
/**
|
||||
* Notes: 获取广告
|
||||
*
|
||||
* @Author: 玄尘
|
||||
* @Date: 2021/12/1 13:27
|
||||
* @param $categoryId
|
||||
* @param int $take
|
||||
* @return mixed
|
||||
*/
|
||||
function getAdvertsByCate($categoryId, int $take = 8)
|
||||
{
|
||||
return Advert::where('category_id', $categoryId)
|
||||
->latest('sort')
|
||||
->latest()
|
||||
->take($take)
|
||||
->get();
|
||||
->latest('sort')
|
||||
->latest()
|
||||
->take($take)
|
||||
->get();
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes: 根据分类id 获取文章
|
||||
*
|
||||
* @Author: 玄尘
|
||||
* @Date : 2021/5/21 9:45
|
||||
* @param int $take
|
||||
* @param int $take
|
||||
* @param false $hasCover
|
||||
* @return mixed
|
||||
*/
|
||||
function getArticlesByCateIds($take = 8, $hasCover = false)
|
||||
function getArticlesByCateIds(int $take = 8, $hasCover = false)
|
||||
{
|
||||
//分院新闻 媒体报道 科研动态 交流合作 党建文化 专题学习
|
||||
$ids = [7, 17, 8, 5, 12, 30];
|
||||
|
||||
$articles = Article::query()->where('status', 1)
|
||||
->whereHas('categories', function ($q) use ($ids) {
|
||||
$q->whereIn('id', $ids);
|
||||
})
|
||||
->latest('sort')
|
||||
->latest('created_at')
|
||||
->when($hasCover, function ($q) {
|
||||
$q->whereNotNull('cover')->orWhere('cover', '<>', '');
|
||||
})
|
||||
->take($take)
|
||||
->get();
|
||||
|
||||
return $articles;
|
||||
return Article::query()->where('status', 1)
|
||||
->whereHas('categories', function ($q) use ($ids) {
|
||||
$q->whereIn('id', $ids);
|
||||
})
|
||||
->latest('sort')
|
||||
->latest('created_at')
|
||||
->when($hasCover, function ($q) {
|
||||
$q->whereNotNull('cover')->orWhere('cover', '<>', '');
|
||||
})
|
||||
->take($take)
|
||||
->get();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes: 获取推荐文章
|
||||
*
|
||||
* @Author: 玄尘
|
||||
* @Date : 2021/4/16 13:31
|
||||
* @param $postion
|
||||
@@ -203,12 +212,27 @@ function getArticlesByCateIds($take = 8, $hasCover = false)
|
||||
*/
|
||||
function getArticlesByPosition($postion)
|
||||
{
|
||||
$articles = Article::ofPosition($postion)
|
||||
->latest('sort')
|
||||
->latest('created_at')
|
||||
->take(5)
|
||||
->get();
|
||||
|
||||
return $articles;
|
||||
return Article::ofPosition($postion)
|
||||
->latest('sort')
|
||||
->latest('created_at')
|
||||
->take(5)
|
||||
->get();
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes: 根据分类获取简历
|
||||
*
|
||||
* @Author: 玄尘
|
||||
* @Date: 2021/12/1 13:28
|
||||
* @param $category_id
|
||||
* @param int $take
|
||||
*/
|
||||
function getResumesByCate($category_id, $take = 8)
|
||||
{
|
||||
return Resume::query()
|
||||
->where('status', 1)
|
||||
->where('category_id', $category_id)
|
||||
->take($take)
|
||||
->get();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user