|
@@ -1175,6 +1175,7 @@ class NewsService implements NewsServiceInterface
|
|
*/
|
|
*/
|
|
public function getWebsiteCatidArticle(array $data): array
|
|
public function getWebsiteCatidArticle(array $data): array
|
|
{
|
|
{
|
|
|
|
+ // return Result::success($data);
|
|
$where = [
|
|
$where = [
|
|
// 'category.status' => 1,
|
|
// 'category.status' => 1,
|
|
'website_category.category_id' => $data['catid'],
|
|
'website_category.category_id' => $data['catid'],
|
|
@@ -1182,7 +1183,51 @@ class NewsService implements NewsServiceInterface
|
|
// 'article.status' => 1,
|
|
// 'article.status' => 1,
|
|
];
|
|
];
|
|
// $category = WebsiteCategory::where($where);
|
|
// $category = WebsiteCategory::where($where);
|
|
- if (!empty($data['img_num'])) {
|
|
|
|
|
|
+ if(isset($data['child_catnum']) && !empty($data['child_catnum'])){
|
|
|
|
+ $child_catnum = $data['child_catnum']?? 1;
|
|
|
|
+ $category['child'] = WebsiteCategory::where('pid',$data['catid'])->where('website_id',$data['website_id'])->select('category_id','alias')->limit($child_catnum)->get()->toArray();
|
|
|
|
+ $childCategoryIds = array_column($category['child'], 'category_id');
|
|
|
|
+ if(empty($childCategoryIds)){
|
|
|
|
+ return Result::error("暂无子栏目",0);
|
|
|
|
+ }
|
|
|
|
+ $imgArticles = [];
|
|
|
|
+ $textArticles = [];
|
|
|
|
+ // return Result::success($childCategoryIds);
|
|
|
|
+ if(isset($data['child_imgnum']) && !empty($data['child_imgnum']) && $data['child_imgnum']!=0){
|
|
|
|
+ // 初始化子分类图片新闻和文字新闻数组
|
|
|
|
+
|
|
|
|
+ // 查询所有子级栏目的图文新闻
|
|
|
|
+ $imgArticles = Article::where('catid', $childCategoryIds[0])
|
|
|
|
+ ->where('status', 1)
|
|
|
|
+ ->where('imgurl', '!=', '')
|
|
|
|
+ ->select('*')
|
|
|
|
+ ->orderBy('updated_at', 'desc')
|
|
|
|
+ ->limit($data['child_imgnum'])
|
|
|
|
+ ->get();
|
|
|
|
+ }
|
|
|
|
+ if( isset($data['child_textnum']) && !empty($data['child_textnum']) && $data['child_textnum']!=0){
|
|
|
|
+ // 查询所有子级栏目的文字新闻
|
|
|
|
+ $textArticles = Article::where('catid', $childCategoryIds[0])
|
|
|
|
+ ->where('status', 1)
|
|
|
|
+ // ->where(function ($query) {
|
|
|
|
+ // $query->whereNull('imgurl')
|
|
|
|
+ // ->orWhere('imgurl', '');
|
|
|
|
+ // })
|
|
|
|
+ ->select('*')
|
|
|
|
+ ->orderBy('updated_at', 'desc')
|
|
|
|
+ ->limit($data['child_textnum'])
|
|
|
|
+ ->get();
|
|
|
|
+ }
|
|
|
|
+ // 遍历子分类,将图文新闻和文字新闻分别添加到子分类中
|
|
|
|
+ $category['child'] = array_map(function ($child) use ($imgArticles, $textArticles) {
|
|
|
|
+ $child['img'] = $imgArticles? $imgArticles->where('catid', $child['category_id']) : [];
|
|
|
|
+ $child['text'] = $textArticles? $textArticles->where('catid', $child['category_id']) : [];
|
|
|
|
+ return $child;
|
|
|
|
+ }, $category['child']);
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ // }
|
|
|
|
+ if (isset($data['img_num']) && !empty($data['img_num'])) {
|
|
$category['img'] = WebsiteCategory::where($where)
|
|
$category['img'] = WebsiteCategory::where($where)
|
|
->leftJoin('article', 'article.catid', 'website_category.category_id')
|
|
->leftJoin('article', 'article.catid', 'website_category.category_id')
|
|
->where('article.status', 1)
|
|
->where('article.status', 1)
|
|
@@ -1193,7 +1238,7 @@ class NewsService implements NewsServiceInterface
|
|
->get();
|
|
->get();
|
|
}
|
|
}
|
|
|
|
|
|
- if (!empty($data['text_num'])) {
|
|
|
|
|
|
+ if (isset($data['text_num']) && !empty($data['text_num'])) {
|
|
$category['text'] = WebsiteCategory::where($where)
|
|
$category['text'] = WebsiteCategory::where($where)
|
|
->leftJoin('article', 'article.catid', 'website_category.category_id')
|
|
->leftJoin('article', 'article.catid', 'website_category.category_id')
|
|
->where('article.status', 1)
|
|
->where('article.status', 1)
|