Browse Source

修改获取乡村网新闻特殊接口修改

15313670163 1 week ago
parent
commit
df185c7604
2 changed files with 70 additions and 27 deletions
  1. 1 1
      .env
  2. 69 26
      app/JsonRpc/NewsService.php

+ 1 - 1
.env

@@ -2,7 +2,7 @@ APP_NAME=news_producer
 APP_ENV=dev
 HOST = http://101.254.114.211:13306/
 DB_DRIVER=mysql
-DB_HOST=192.168.1.123
+DB_HOST=192.168.1.234
 DB_PORT=13306
 DB_DATABASE=hyperf
 DB_USERNAME=root

+ 69 - 26
app/JsonRpc/NewsService.php

@@ -1181,6 +1181,7 @@ class NewsService implements NewsServiceInterface
                 $textArticles = []; 
                 // return Result::error("暂无此栏目",0); 
             }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);
                 // 查询图片新闻 
@@ -1190,14 +1191,35 @@ class NewsService implements NewsServiceInterface
                             $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website['website_id']) . "') = 0");
                         })->orWhereNull("ignore_ids");
                     })
-                    ->whereRaw("JSON_CONTAINS(category_arr_id, '" . intval($parentCatId) . "')")
-                    ->leftJoin('website_category', 'website_category.category_id', 'article.catid')
                     ->where('website_category.website_id', $website['website_id'])
-                    ->where('article.status', 1);
+                    ->where('article.status', 1)
+                    ->leftJoin('website_category', 'website_category.category_id', 'article.catid');
                     
                  // 查询文字新闻
                  $textArticles = clone $baseQuery;
-                 $textArticles = $textArticles
+                 $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',
@@ -1217,33 +1239,54 @@ 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,