瀏覽代碼

修改模块新闻加强plus版 一级栏目获取的新闻可能为父级或子级栏目的新闻并获取到了他的路由(修改了若是此子级栏目只有在该网站有才可以)

15313670163 4 天之前
父節點
當前提交
4af4493f79
共有 1 個文件被更改,包括 49 次插入34 次删除
  1. 49 34
      app/JsonRpc/NewsService.php

+ 49 - 34
app/JsonRpc/NewsService.php

@@ -1015,6 +1015,7 @@ class NewsService implements NewsServiceInterface
                 ];
                 // 查询栏目名称
                 $category = WebsiteCategory::where('category_id', $parentCatId)->where($website)->first(['alias', 'category_id','aLIas_pinyin']);
+               
                 if(empty($category)){
                     $parent_alias = '';
                     $parent_pinyin = null;
@@ -1023,14 +1024,22 @@ class NewsService implements NewsServiceInterface
                 }else{
                     $parent_alias = $category->alias ?? '';
                     $parent_pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
+                    // 查找子分类ID数组
+                    $childCategoryIds = WebsiteCategory::where('pid', $parentCatId)->where($website)->pluck('category_id')->toArray();
+                    array_push($childCategoryIds,$parentCatId);
+                    $childCategoryIds = json_encode(array_values(array_unique($childCategoryIds)));
                     if($parentImgNum!=0){
                         // 查询图片新闻
-                    $imgArticles = Article::where('article.status', 1)
-                        ->where(function ($query) use ($website, $parentCatId) {
-                            $query->where(function ($subQuery) use ($website, $parentCatId) {
+                        $imgArticles = Article::where('article.status', 1)
+                        ->where(function($query) use ($parentCatId) {
+                            $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$parentCatId\"')")
+                                    ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$parentCatId')");
+                        })
+                        ->where(function ($query) use ($website) {
+                            $query->where(function ($subQuery) use ($website) {
                                 $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '".intval($website['website_id'])."') = 0")
-                                ->whereRaw("JSON_CONTAINS(article.cat_arr_id, '".intval($parentCatId)."') = 0");
-                            })->orWhereNull("ignore_ids");
+                                    ->orWhereNull("ignore_ids");
+                            });
                         })
                         ->where('imgurl', '!=', '')
                         ->leftJoin('website_category', function($join) use ($website) {
@@ -1055,38 +1064,44 @@ class NewsService implements NewsServiceInterface
                         ->orderBy('updated_at', 'desc')
                         ->limit($parentImgNum)
                         ->get()->all();
-                        // 查询文字新闻
+                                                
+                            // 查询文字新闻
                     }
                     if($parentTextNum!=0){  
+                        $textArticles = [];
                         $textArticles = Article::where('article.status', 1)
-                        ->where(function ($query) use ($website, $parentCatId) {
-                            $query->where(function ($subQuery) use ($website, $parentCatId) {
-                                $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '".intval($website['website_id'])."') = 0")
-                                ->whereRaw("JSON_CONTAINS(article.cat_arr_id, '".intval($parentCatId)."') = 0");
-                            })->orWhereNull("ignore_ids");
-                        })
-                        ->leftJoin('website_category', function($join) use ($website) {
-                            $join->on('article.catid', '=', 'website_category.category_id')
-                                ->where('website_category.website_id', '=', $website['website_id']);
-                        })
-                        ->select(
-                            'article.id',
-                            'article.title',
-                            'article.imgurl',
-                            'article.author',
-                            'article.updated_at',
-                            'article.introduce',
-                            'article.islink',
-                            'article.linkurl',
-                            'article.copyfrom',
-                            'article.catid',
-                            'website_category.alias as category_name',
-                            DB::raw("CASE WHEN article.catid = $parentCatId THEN '$parent_pinyin' 
-                                    ELSE CONCAT('$parent_pinyin', '/', website_category.aLIas_pinyin) END as pinyin")
-                        )
-                        ->orderBy('updated_at', 'desc')
-                        ->limit($parentTextNum)
-                        ->get()->all();
+                            ->where(function($query) use ($parentCatId) {
+                                $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$parentCatId\"')")
+                                        ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$parentCatId')");
+                            })
+                            ->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");
+                                });
+                            })
+                            ->leftJoin('website_category', function($join) use ($website) {
+                                $join->on('article.catid', '=', 'website_category.category_id')
+                                    ->where('website_category.website_id', '=', $website['website_id']);
+                            })
+                            ->select(
+                                'article.id',
+                                'article.title',
+                                'article.imgurl',
+                                'article.author',
+                                'article.updated_at',
+                                'article.introduce',
+                                'article.islink',
+                                'article.linkurl',
+                                'article.copyfrom',
+                                'article.catid',
+                                'website_category.alias as category_name',
+                                DB::raw("CASE WHEN article.catid = $parentCatId THEN '$parent_pinyin' 
+                                        ELSE CONCAT('$parent_pinyin', '/', website_category.aLIas_pinyin) END as pinyin")
+                            )
+                            ->orderBy('updated_at', 'desc')
+                            ->limit($parentTextNum)
+                            ->get()->all();
                     }
                 }