Browse Source

Merge branch 'web_sannong_fr'

15313670163 1 week ago
parent
commit
8ab35e408c
1 changed files with 88 additions and 42 deletions
  1. 88 42
      app/JsonRpc/NewsService.php

+ 88 - 42
app/JsonRpc/NewsService.php

@@ -1587,24 +1587,47 @@ class NewsService implements NewsServiceInterface
                 $imgArticles = [];
                 $textArticles = [];
                 // return Result::error("暂无此栏目",0); 
-            } else {
-                $parent_alias = $category->aLIas_pinyin ? $category->aLIas_pinyin . '/' : null;
+            }else{ 
+                $child_category = WebsiteCategory::where('pid', $parentCatId)->where($website)->pluck('category_id')->toArray();
+                $parent_alias = $category->aLIas_pinyin ? $category->aLIas_pinyin.'/' : null;
                 // return Result::success($website);
                 // 查询图片新闻 
                 // 合并查询条件
                 $baseQuery = Article::where(function ($query) use ($website) {
-                    $query->where(function ($subQuery) use ($website) {
-                        $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website['website_id']) . "') = 0");
-                    })->orWhereNull("ignore_ids");
-                })
-                    ->whereRaw("JSON_CONTAINS(category_arr_id, '" . intval($parentCatId) . "')")
+                        $query->where(function ($subQuery) use ($website) {
+                            $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website['website_id']) . "') = 0");
+                        })->orWhereNull("ignore_ids");
+                    })
+                    
+                    ->where('article.status', 1)
                     ->leftJoin('website_category', 'website_category.category_id', 'article.catid')
-                    ->where('website_category.website_id', $website['website_id'])
-                    ->where('article.status', 1);
-
-                // 查询文字新闻
-                $textArticles = clone $baseQuery;
-                $textArticles = $textArticles
+                    ->where('website_category.website_id', $website['website_id']);
+                    
+                 // 查询文字新闻
+                 $textArticles = clone $baseQuery;
+                 $textArticles = $textArticles->whereIn('catid',$child_category)
+                 ->select(
+                    'article.id',
+                    'article.title',
+                    // 'article.imgurl',
+                    'article.author',
+                    'article.updated_at',
+                    'article.introduce',
+                    'article.islink',
+                    'article.linkurl',
+                    'article.copyfrom',
+                    'website_category.category_id',
+                    'website_category.alias',
+                    'website_category.aLIas_pinyin'
+                )
+                ->selectRaw("CONCAT(?, aLIas_pinyin) as aLIas_pinyin", [$parent_alias])
+                ->orderBy('article.updated_at', 'desc')
+                ->limit($parentTextNum)
+                ->get()
+                ->all();
+                 if(empty($textArticles)){
+                    $textArticles = clone $baseQuery;
+                    $textArticles = $textArticles->where('catid',$parentCatId)
                     ->select(
                         'article.id',
                         'article.title',
@@ -1624,39 +1647,62 @@ class NewsService implements NewsServiceInterface
                     ->limit($parentTextNum)
                     ->get()
                     ->all();
+                }
                 // 查询图片新闻
                 $imgArticles = clone $baseQuery;
-                $imgArticles = $imgArticles
+                $imgArticles = $imgArticles->where('imgurl', '!=', '')->whereIn('catid',$child_category)
+                ->select(
+                    'article.id',
+                    'article.title',
+                    'article.imgurl',
+                    'article.author',
+                    'article.updated_at',
+                    'article.introduce',
+                    'article.islink',
+                    'article.linkurl',
+                    'article.copyfrom',
+                    'website_category.category_id',
+                    'website_category.alias',
+                    'website_category.aLIas_pinyin'
+                )
+                ->selectRaw("CONCAT(?, aLIas_pinyin) as aLIas_pinyin", [$parent_alias])
+                ->orderBy('article.updated_at', 'desc')
+                ->limit($parentImgNum)
+                ->get()
+                ->all();
+                if(empty($imgArticles)){
+                    $imgArticles = clone $baseQuery;
+                    $imgArticles = $imgArticles->where('imgurl', '!=', '')->where('catid',$parentCatId)
                     ->select(
-                        'article.id',
-                        'article.title',
-                        'article.imgurl',
-                        'article.author',
-                        'article.updated_at',
-                        'article.introduce',
-                        'article.islink',
-                        'article.linkurl',
-                        'article.copyfrom',
-                        'website_category.category_id',
-                        'website_category.alias',
-                        'website_category.aLIas_pinyin'
-                    )
-                    ->selectRaw("CONCAT(?, aLIas_pinyin ) as aLIas_pinyin", [$parent_alias])
-                    ->orderBy('article.updated_at', 'desc')
-                    ->where('imgurl', '!=', '')
-                    ->limit($parentImgNum)
-                    ->get()
-                    ->all();
+                            'article.id',
+                            'article.title',
+                            'article.imgurl',
+                            'article.author',
+                            'article.updated_at',
+                            'article.introduce',
+                            'article.islink',
+                            'article.linkurl',
+                            'article.copyfrom',
+                            'website_category.category_id',
+                            'website_category.alias',
+                            'website_category.aLIas_pinyin'
+                        )
+                        ->selectRaw("CONCAT(?, aLIas_pinyin) as aLIas_pinyin", [$parent_alias])
+                        ->orderBy('article.updated_at', 'desc')
+                        ->limit($parentImgNum)
+                        ->get()
+                        ->all(); 
+                }
+               
             }
-
-            $resultItem = [
-                'alias' => $category ? $category->alias : null,
-                'category_id' => $parentCatId,
-                'pinyin' => $pinyin ? $pinyin : null,
-                'imgnum' => $imgArticles ?? [],
-                'textnum' => $textArticles ?? [],
-
-            ];
+            $resultItem = [ 
+                'alias' => $category ? $category->alias : null, 
+                'category_id' => $parentCatId, 
+                'pinyin' => $pinyin ? $pinyin : null, 
+                'imgnum' => $imgArticles ?? [], 
+                'textnum' => $textArticles ?? [], 
+                
+            ]; 
 
 
             return $resultItem;