Эх сурвалжийг харах

Merge branch 'web_sannong_fr'

15313670163 2 долоо хоног өмнө
parent
commit
f2869c1aa6
1 өөрчлөгдсөн 140 нэмэгдсэн , 63 устгасан
  1. 140 63
      app/JsonRpc/NewsService.php

+ 140 - 63
app/JsonRpc/NewsService.php

@@ -1316,19 +1316,31 @@ class NewsService implements NewsServiceInterface
                 $imgArticles = [];
                 $textArticles = [];
                 // return Result::error("暂无此栏目",0);
-            } else {
+            }else{
+                $parent_alias = $category->alias ?? '';
+                $parent_pinyin = $category->aLIas_pinyin ?'/'.$category->aLIas_pinyin.'/' : null;
                 // 查询图片新闻
                 $imgArticles = Article::where('catid', $parentCatId)
-                    ->where('status', 1)
-                    ->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");
-                    })
-                    ->where('imgurl', '!=', '')
-                    ->orderBy('updated_at', 'desc')
-                    ->limit($parentImgNum)
-                    ->get()->all();
+                ->where('status', 1)
+                ->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");
+                })
+                ->where('imgurl', '!=', '')
+                ->select(
+                    'article.id',
+                    'article.title',
+                    'article.imgurl',
+                    'article.author',
+                    'article.updated_at',
+                    'article.introduce',
+                    'article.islink',
+                    'article.linkurl',
+                    'article.copyfrom')
+                ->orderBy('updated_at', 'desc')
+                ->limit($parentImgNum)
+                ->get()->all();
 
                 // 查询文字新闻
                 $textArticles = Article::where('catid', $parentCatId)
@@ -1338,28 +1350,40 @@ class NewsService implements NewsServiceInterface
                             $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website['website_id']) . "') = 0");
                         })->orWhereNull("ignore_ids");
                     })
+                    ->select(
+                        'article.id',
+                        'article.title',
+                        'article.author',
+                        'article.updated_at',
+                        'article.introduce',
+                        'article.islink',
+                        'article.linkurl',
+                        'article.copyfrom')
                     ->orderBy('updated_at', 'desc')
                     ->limit($parentTextNum)
                     ->get()->all();
             }
             $resultItem = [
-                'alias' => $category ? $category->alias : null,
+                'alias' => $parent_alias,
                 'category_id' => $parentCatId,
-                'pinyin' => $category->aLIas_pinyin ?? '',
+                'pinyin' => $parent_pinyin,
                 'imgnum' => $imgArticles,
                 'textnum' => $textArticles,
 
             ];
 
             if (!empty($item['child']) && $item['child'] != "") {
-                // 查询第一个pid等于parent中第一个参数的category来获取child的category_id
-                $childCategory = WebsiteCategory::where('pid', $parentCatId)->where($website)->select('category_id', 'alias', 'aLIas_pinyin')->get()->all();
+                $parent_pinyin_str = is_string($parent_pinyin) ? $parent_pinyin : '';
+                $childCategory = WebsiteCategory::where('pid', $parentCatId)->where($website)
+                    ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin, '/') as aLIas_pinyin", [$parent_pinyin_str])
+                    ->get()->all();
                 if ($childCategory) {
                     list($childCatId, $childImgNum, $childTextNum) = explode(',', $item['child']);
                     // 查询子栏目名称
-                    $childCategoryInfo = WebsiteCategory::where('category_id', $childCatId)->where($website)->first(['alias', 'category_id', 'aLIas_pinyin']);
-                    // $childAllCartegory = WebsiteCategory::where('pid', $childCatId)->where($website)->first(['category_id']);
-                    if (empty($childCategoryInfo)) {
+                $childCategoryInfo = WebsiteCategory::where('category_id', $childCatId)->where($website)
+                    ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin, '/') as aLIas_pinyin", [$parent_pinyin])
+                    ->first();
+                    if(empty($childCategoryInfo)){
                         $childImgArticles = [];
                         $childTextArticles = [];
                     } else {
@@ -1371,6 +1395,16 @@ class NewsService implements NewsServiceInterface
                                     $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website['website_id']) . "') = 0");
                                 })->orWhereNull("ignore_ids");
                             })
+                            ->select(
+                                'article.id',
+                                'article.title',
+                                'article.imgurl',
+                                'article.author',
+                                'article.updated_at',
+                                'article.introduce',
+                                'article.islink',
+                                'article.linkurl',
+                                'article.copyfrom')
                             ->where('imgurl', '!=', '')
                             ->orderBy('updated_at', 'desc')
                             ->limit($childImgNum)
@@ -1383,6 +1417,15 @@ class NewsService implements NewsServiceInterface
                                     $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website['website_id']) . "') = 0");
                                 })->orWhereNull("ignore_ids");
                             })
+                            ->select(
+                                'article.id',
+                                'article.title',
+                                'article.author',
+                                'article.updated_at',
+                                'article.introduce',
+                                'article.islink',
+                                'article.linkurl',
+                                'article.copyfrom')
                             ->orderBy('updated_at', 'desc')
                             ->limit($childTextNum)
                             ->get()->all();
@@ -1413,60 +1456,94 @@ class NewsService implements NewsServiceInterface
      */
     public function getWebsiteArticles(array $data): array
     {
-        // 修正传入的字符串,将单引号替换为双引号
-        $input['id'] = $data['id'];
-        $input['website_id'] = $data['website_id'];
-        // 将 JSON 字符串转换为 PHP 数组
-        $data = json_decode($input['id'], true);
-        // 使用 array_map 处理每个元素
-        $result = array_map(function ($item) use ($input) {
-            list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
-            $website = [
-                'website_id' => $input['website_id'],
-            ];
-            // 查询栏目名称
-            $category = WebsiteCategory::where('category_id', $parentCatId)->where($website)->first(['alias', 'category_id', 'aLIas_pinyin']);
-            if (empty($category)) {
-                $imgArticles = [];
-                $textArticles = [];
-                // return Result::error("暂无此栏目",0);
-            } else {
-                // 查询图片新闻
-                $imgArticles = Article::where('status', 1)
-                    ->where(function ($query) use ($website) {
+        $input['id'] = $data['id']; 
+        $input['website_id'] = $data['website_id']; 
+        $data = json_decode($input['id'], true); 
+        // 使用 array_map 处理每个元素 
+        $result = array_map(function ($item) use ($input) { 
+            list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']); 
+            $website = [ 
+                'website_id' => $input['website_id']
+            ]; 
+            // 查询栏目名称 
+            $category = WebsiteCategory::where('category_id', $parentCatId)->where($website)->first(['alias', 'category_id','aLIas_pinyin']); 
+            $pinyin = $category->aLIas_pinyin ? '/'.$category->aLIas_pinyin.'/' : null;
+            if(empty($category)){ 
+                $imgArticles = []; 
+                $textArticles = []; 
+                // return Result::error("暂无此栏目",0); 
+            }else{ 
+                // 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");
                     })
-                    ->where('imgurl', '!=', '')
                     ->whereRaw("JSON_CONTAINS(category_arr_id, '" . intval($parentCatId) . "')")
                     ->leftJoin('website_category', 'website_category.category_id', 'article.catid')
-                    ->select('article.*', 'website_category.category_id', 'website_category.alias', 'website_category.aLIas_pinyin')
-                    ->orderBy('updated_at', 'desc')
-                    ->limit($parentImgNum)
-                    ->get()->all();
-                // 查询文字新闻
-                $textArticles = Article::where('status', 1)
-                    ->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) . "')")
-                    ->leftJoin('website_category', 'website_category.category_id', 'article.catid')
-                    ->select('article.*', 'website_category.category_id', 'website_category.alias', 'website_category.aLIas_pinyin')
-                    ->orderBy('updated_at', 'desc')
+                    ->where('website_category.website_id', $website['website_id'])
+                    ->where('article.status', 1);
+                    
+                 // 查询文字新闻
+                 $textArticles = clone $baseQuery;
+                 $textArticles = $textArticles
+                    ->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", [$pinyin])
+                    ->orderBy('article.updated_at', 'desc')
                     ->limit($parentTextNum)
-                    ->get()->all();
+                    ->get()
+                    ->all();
+                // 查询图片新闻
+                $imgArticles = clone $baseQuery;
+                $imgArticles = $imgArticles
+                    ->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", [$pinyin])
+                    ->orderBy('article.updated_at', 'desc')
+                    ->where('imgurl', '!=', '')
+                    ->limit($parentImgNum)
+                    ->get()
+                    ->all();
+
+               
             }
-            $resultItem = [
-                'alias' => $category ? $category->alias : null,
-                'category_id' => $parentCatId,
-                'pinyin' => $category->aLIas_pinyin ?? '',
-                'imgnum' => $imgArticles,
-                'textnum' => $textArticles,
+           
+            $resultItem = [ 
+                'alias' => $category ? $category->alias : null, 
+                'category_id' => $parentCatId, 
+                'pinyin' => $pinyin ? $pinyin : null, 
+                'imgnum' => $imgArticles ?? [], 
+                'textnum' => $textArticles ?? [], 
+                
+            ]; 
 
-            ];
 
             return $resultItem;
         }, $data);