Prechádzať zdrojové kódy

Merge branch 'web_sannong_fr'

15313670163 4 dní pred
rodič
commit
51110bca18
1 zmenil súbory, kde vykonal 228 pridanie a 337 odobranie
  1. 228 337
      app/JsonRpc/NewsService.php

+ 228 - 337
app/JsonRpc/NewsService.php

@@ -750,9 +750,8 @@ class NewsService implements NewsServiceInterface
         // return Result::success($data['website_id']);
         $category = WebsiteCategory::where('website_id', $data['website_id'])->pluck('category_id');
         $category = array_values(array_unique($category->toArray()));
-
+        $web['website_id'] = $data['website_id'];
         if ($category) {
-            $placeid = isset($data['placeid']) && !empty($data['placeid']) ? $data['placeid'] - 1 : 0;
             $where = [
                 'status' => 1,
             ];
@@ -782,25 +781,11 @@ class NewsService implements NewsServiceInterface
                                 ->limit($data['textnum']);
                         })
                         ->orderBy('updated_at', 'desc')
-                        ->get()
-                        ->map(function ($article) use ($data) {
-                            $catid = $article->catid;
-                            $pinyin = '';
-                            $category = WebsiteCategory::where('category_id', $catid)->where('website_category.website_id', $data['website_id'])->first();
-                            if (!empty($category->aLIas_pinyin) && $category->pid != 0) {
-                                $childCategory = WebsiteCategory::where('category_id', $category->pid)->where('website_category.website_id', $data['website_id'])->first();
-                                if ($childCategory && !empty($childCategory->aLIas_pinyin)) {
-                                    $pinyin = $childCategory->aLIas_pinyin ?  $childCategory->aLIas_pinyin . '/' . $category->aLIas_pinyin : null;
-                                }
-                            } else {
-                                $pinyin = $category->aLIas_pinyin ?  $category->aLIas_pinyin : null;
-                            }
-                            $article->pinyin = $pinyin;
-                            return $article;
-                        });
-                    if (empty($result)) {
-                        return Result::success();
-                    }
+                        ->get();
+                        $result['level7'] = $this->processArticle($result['level7'],$web);
+                        if (empty($result)) {
+                            return Result::success();
+                        }
                     return Result::success($result);
                 } else {
                     return Result::error("参数错误level=7,id不能为空", 0);
@@ -841,74 +826,42 @@ class NewsService implements NewsServiceInterface
                     $imgQuery->setBindings([]);
                 }
                 $result['img'] = $imgQuery->where('article.imgurl', '!=', '')
-                    ->select(
-                        'article.id',
-                        'article.title',
-                        'article.imgurl',
-                        'article.author',
-                        'article.updated_at',
-                        'article.introduce',
-                        'article.islink',
-                        'article.linkurl',
-                        'article.copyfrom',
-                        'article.catid'
-                    )
+                    ->select('article.id',
+                    'article.title',
+                    'article.imgurl',
+                    'article.author',
+                    'article.updated_at',
+                    'article.introduce',
+                    'article.islink',
+                    'article.linkurl',
+                    'article.copyfrom',
+                    'article.cat_arr_id',
+                    'article.catid')
                     ->offset($data['placeid'])
                     ->limit($data['imgnum'])
-                    ->get()
-                    ->map(function ($article) use ($data) {
-                        $catid = $article->catid;
-                        $pinyin = '';
-                        $category = WebsiteCategory::where('category_id', $catid)->where('website_category.website_id', $data['website_id'])->first();
-                        if (!empty($category->aLIas_pinyin) && $category->pid != 0) {
-                            $childCategory = WebsiteCategory::where('category_id', $category->pid)->where('website_category.website_id', $data['website_id'])->first();
-                            if ($childCategory && !empty($childCategory->aLIas_pinyin)) {
-                                $pinyin = $childCategory->aLIas_pinyin ?  $childCategory->aLIas_pinyin . '/' . $category->aLIas_pinyin : null;
-                            }
-                        } else {
-                            $pinyin = $category->aLIas_pinyin ?  $category->aLIas_pinyin : null;
-                        }
-                        $article->pinyin = $pinyin;
-                        return $article;
-                    });
-                // $result['img'] = $this->processArticles($img_article, $input); 
+                    ->get();
+                $result['img'] = $this->processArticles( $result['img'], $web); 
             }
 
             // 处理文字新闻查询
             if (!empty($data['textnum'])) {
                 $textQuery = clone $query;
                 $result['text'] = $textQuery
-                    ->select(
-                        'article.id',
-                        'article.title',
-                        'article.imgurl',
-                        'article.author',
-                        'article.updated_at',
-                        'article.introduce',
-                        'article.islink',
-                        'article.linkurl',
-                        'article.copyfrom',
-                        'article.catid'
-                    )
+                ->select('article.id',
+                    'article.title',
+                    'article.imgurl',
+                    'article.author',
+                    'article.updated_at',
+                    'article.introduce',
+                    'article.islink',
+                    'article.linkurl',
+                    'article.copyfrom',
+                    'article.cat_arr_id',
+                    'article.catid')
                     ->offset($data['placeid'])
                     ->limit($data['textnum'])
-                    ->get()
-                    ->map(function ($article) use ($data) {
-                        $catid = $article->catid;
-                        $pinyin = '';
-                        $category = WebsiteCategory::where('category_id', $catid)->where('website_category.website_id', $data['website_id'])->first();
-                        if (!empty($category->aLIas_pinyin) && $category->pid != 0) {
-                            $childCategory = WebsiteCategory::where('category_id', $category->pid)->where('website_category.website_id', $data['website_id'])->first();
-                            if ($childCategory && !empty($childCategory->aLIas_pinyin)) {
-                                $pinyin = $childCategory->aLIas_pinyin ?  $childCategory->aLIas_pinyin . '/' . $category->aLIas_pinyin : null;
-                            }
-                        } else {
-                            $pinyin = $category->aLIas_pinyin ?  $category->aLIas_pinyin : null;
-                        }
-                        $article->pinyin = $pinyin;
-                        return $article;
-                    });
-                // $result['text'] = $this->processArticles($text_article, $input); 
+                    ->get();
+                $result['text'] = $this->processArticles($result['text'], $web); 
             }
 
             if (empty($result) || count($result) == 0) {
@@ -975,68 +928,40 @@ class NewsService implements NewsServiceInterface
         // return Result::success($data);
         $where[] = ['status', '=', 1];
         if (isset($data['catid']) && !empty($data['catid'])) {
-            if (is_array($data['catid'])) {
-                $category = WebsiteCategory::where('website_id', $data['website_id'])->whereIn('category_id', $data['catid'])->pluck('category_id');
-                array_push($where, ['catid', 'in', $data['catid']]);
-            } else {
                 $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $data['catid'])->pluck('category_id');
                 array_push($where, ['catid', '=', $data['catid']]);
-            }
             if (empty($category)) {
                 return Result::error("此网站暂无此栏目", 0);
             }
         }
         // return Result::success($where);
-        $rep = Article::where(function ($query) use ($where) {
-            foreach ($where as $condition) {
-                if ($condition[1] === 'in') {
-                    $query->whereIn($condition[0], $condition[2]);
-                } else {
-                    $query->where($condition[0], $condition[1], $condition[2]);
-                }
-            }
+        $rep = Article::where($where)
+        ->where(function ($query) use ($data) {
+            $query->whereRaw("JSON_CONTAINS(ignore_ids, '".intval($data['website_id'])."') = 0")
+                  ->orWhereNull("ignore_ids");
         })
-            ->where(function ($query) use ($data) {
-                $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['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',
-                'article.catid'
-            )
-            ->orderBy("updated_at", "desc")
-            ->offset(($data['page'] - 1) * $data['pageSize'])
-            ->limit($data['pageSize'])
-            ->get()
-            ->map(function ($article) use ($data) {
-                $catid = $article->catid ?? 0;
-                $pinyin = '';
-                $category = WebsiteCategory::where('category_id', $catid)->where('website_category.website_id', $data['website_id'])->first();
-                $pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
-                if ($category->pid != 0 && !empty($category->aLIas_pinyin)) {
-                    $childCategory = WebsiteCategory::where('category_id', $category->pid)->where('website_category.website_id', $data['website_id'])->first();
-                    $pinyin = $childCategory->aLIas_pinyin ?  $childCategory->aLIas_pinyin . '/' . $category->aLIas_pinyin : null;
-                }
-                $article->pinyin = $pinyin;
-                return $article;
-            });
-
-        $count = Article::where(function ($query) use ($where) {
-            foreach ($where as $condition) {
-                if ($condition[1] === 'in') {
-                    $query->whereIn($condition[0], $condition[2]);
-                } else {
-                    $query->where($condition[0], $condition[1], $condition[2]);
-                }
-            }
+        ->select(
+            'article.id',
+            'article.title',
+            'article.imgurl',
+            'article.author',
+            'article.updated_at',
+            'article.introduce',
+            'article.islink',
+            'article.linkurl',
+            'article.copyfrom',
+            'article.cat_arr_id',
+            'article.catid')
+        ->orderBy("updated_at", "desc")
+        ->offset(($data['page'] - 1) * $data['pageSize'])
+        ->limit($data['pageSize'])
+        ->get();
+        $web['website_id'] = $data['website_id'];
+        $rep = $this->processArticles($rep,$web);
+        $count = Article::where($where)
+        ->where(function ($query) use ($data) {
+            $query->whereRaw("JSON_CONTAINS(ignore_ids, '".intval($data['website_id'])."') = 0")
+                  ->orWhereNull("ignore_ids");
         })->count();
 
         $data = [
@@ -1366,8 +1291,6 @@ class NewsService implements NewsServiceInterface
      */
     public function selectWebsiteArticle(array $data): array
     {
-        $where = [];
-        // 初始化查询构造器
         $category = WebsiteCategory::where('website_id', $data['website_id'])->pluck('category_id');
         $query = Article::where('status', 1)
             ->whereIn('catid', $category)
@@ -1377,15 +1300,12 @@ class NewsService implements NewsServiceInterface
                 })->orWhereNull("ignore_ids");
             });
         // return Result::success($all_articles);
-        // 检查是否存在 cityid 参数
         if (isset($data['cityid']) && !empty($data['cityid'])) {
             $query->whereRaw("JSON_CONTAINS(city_arr_id, '" . intval($data['cityid']) . "')");
         }
-        // 检查是否存在 department_id 参数
         if (isset($data['department_id']) && !empty($data['department_id'])) {
             $query->whereRaw("JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "')");
         }
-        // 检查是否存在 keyword 参数
         if (isset($data['keyword']) && !empty($data['keyword'])) {
             $query->where('title', 'like', '%' . $data['keyword'] . '%');
         }
@@ -1403,6 +1323,7 @@ class NewsService implements NewsServiceInterface
                 'article.islink',
                 'article.linkurl',
                 'article.copyfrom',
+                'article.cat_arr_id',
                 'article.catid',
                 'article.department_arr_id',
                 'article.city_arr_id',
@@ -1410,27 +1331,17 @@ class NewsService implements NewsServiceInterface
             ->orderBy("updated_at", "desc")
             ->offset(($data['page'] - 1) * $data['pageSize'])
             ->limit($data['pageSize'])
-            ->get()
-            ->map(function ($article) use ($data) {
-                $catid = $article->catid ?? 0;
-                $pinyin = '';
-                $category = WebsiteCategory::where('category_id', $catid)->where('website_category.website_id', $data['website_id'])->first();
-                $pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
-                if ($category->pid != 0 && !empty($category->aLIas_pinyin)) {
-                    $childCategory = WebsiteCategory::where('category_id', $category->pid)->where('website_category.website_id', $data['website_id'])->first();
-                    $pinyin = $childCategory->aLIas_pinyin ?  $childCategory->aLIas_pinyin . '/' . $category->aLIas_pinyin : null;
-                }
-                $article->pinyin = $pinyin;
-                return $article;
-            });
+            ->get();
+        $web['website_id'] = $data['website_id'];
+        $articles = $this->processArticles($articles,$web);
         if (empty($articles)) {
             return Result::error("没有符合条件的资讯数据");
         }
-        $data = [
+        $result = [
             'rows' => $articles,
             'count' => $count,
         ];
-        return Result::success($data);
+        return Result::success($result);
     }
 
     /**
@@ -1529,196 +1440,165 @@ class NewsService implements NewsServiceInterface
      */
     public function getWebsiteAllArticle(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) {
-            // 检查parent元素是否存在且不是undefined
-            if (isset($item['parent']) && $item['parent'] != 'undefined' && $item['parent'] != "") {
-                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)) {
-                    $parent_alias = '';
-                    $parent_pinyin = null;
-                    $imgArticles = [];
-                    $textArticles = [];
-                } 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) {
-                        // 查询图片新闻
+            // 修正传入的字符串,将单引号替换为双引号
+            $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) {
+                // 检查parent元素是否存在且不是undefined
+                if (isset($item['parent']) && $item['parent'] != 'undefined' && $item['parent']!= "" ) {
+                    $count = explode(',', $item['parent']);
+                    if(count($count)!=3){
+                        return Result::error("父级栏目:缺少必需参数错误",0);
+                    }
+                    list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
+                    $website = [
+                        'website_id' => $input['website_id'],
+                    ];
+                    // 查询栏目名称
+                    $categroy = WebsiteCategory::where('category_id', $parentCatId)->where($website)->first(['alias', 'category_id','aLIas_pinyin','type']);
+                    // 查询图片新闻
+                    if(isset($parentImgNum) && $parentImgNum!=0 && !empty($categroy)){
                         $imgArticles = Article::where('article.status', 1)
-                            ->where(function ($query) use ($parentCatId) {
-                                $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$parentCatId\"')")
+                        ->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");
-                                });
-                            })
-                            ->where('imgurl', '!=', '')
-                            ->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($parentImgNum)
-                            ->get()->all();
-
-                        // 查询文字新闻
+                        })
+                        ->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', '!=', '')
+                        ->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.cat_arr_id',
+                            'article.catid','website_category.alias as category_name',
+                        )
+                        ->orderBy('updated_at', 'desc')
+                        ->limit($parentImgNum)
+                        ->get();    
+                        //调取封装路由的方法,处理新闻路由   
+                        if(!empty($imgArticles)){
+                            $imgArticles = $this->processArticles($imgArticles , $website);
+                        }
                     }
-                    if ($parentTextNum != 0) {
+                    // 查询文字新闻
+                    if(isset($parentTextNum) && $parentTextNum!=0 && !empty($categroy)){  
                         $textArticles = [];
                         $textArticles = Article::where('article.status', 1)
-                            ->where(function ($query) use ($parentCatId) {
+                            ->where(function($query) use ($parentCatId) {
                                 $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$parentCatId\"')")
-                                    ->orWhereRaw("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")
+                                    $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '".intval($website['website_id'])."') = 0")
                                         ->orWhereNull("ignore_ids");
                                 });
                             })
-                            ->leftJoin('website_category', function ($join) use ($website) {
+                            ->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")
+                                'article.id','article.title','article.author','article.updated_at','article.cat_arr_id',
+                                'article.introduce','article.islink','article.linkurl','article.copyfrom',
+                                'article.catid','website_category.alias as category_name',
                             )
                             ->orderBy('updated_at', 'desc')
                             ->limit($parentTextNum)
-                            ->get()->all();
+                            ->get();
+                        if(!empty($textArticles)){
+                            $textArticles = $this->processArticles($textArticles , $website);
+                        }
                     }
                 }
-            }
-            $resultItem = [
-                'alias' => $parent_alias ?? '',
-                'category_id' => $parentCatId ?? 0,
-                'pinyin' => $parent_pinyin ?? null,
-                'imgnum' => $imgArticles ?? [],
-                'textnum' => $textArticles ?? [],
-            ];
-            if (isset($item['child']) && $item['child'] != 'undefined' && $item['child'] != "") {
-                $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 (!empty($childCategory)) {
+                $resultItem = [
+                    'alias' =>  $categroy ? $categroy->alias : null,
+                    'category_id' =>  $categroy ? $categroy->category_id : null,
+                    'pinyin' =>  $categroy ? $categroy->aLIas_pinyin : null,
+                    'imgnum' => $imgArticles ?? [],
+                    'textnum' => $textArticles ?? [],
+                ];
+                // 子级栏目
+                if(isset($item['child']) && $item['child'] != 'undefined' && $item['child'] != ""){
+                    $count = explode(',', $item['child']);
+                    if(count($count)!=3){
+                        return Result::error("子级栏目:缺少必需参数错误",0);
+                    }
                     list($childCatId, $childImgNum, $childTextNum) = explode(',', $item['child']);
-                    // 查询子栏目名称
-                    $childCategoryInfo = WebsiteCategory::where('category_id', $childCatId)->where($website)
-                        ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin) as aLIas_pinyin", [$parent_pinyin_str])
-                        ->first();
-                    if (empty($childCategoryInfo) || ($childImgNum == 0 && $childTextNum == 0)) {
-                        $childImgArticles = [];
-                        $childTextArticles = [];
-                        $resultItem['child'] = [];
-                    } else {
-                        $child_pinyin = $childCategoryInfo->aLIas_pinyin ? $childCategoryInfo->aLIas_pinyin : null;
+                    $childCategory = WebsiteCategory::where($website)
+                        ->where("category_id", $childCatId)
+                        ->whereRaw("JSON_CONTAINS(category_arr_id, '".intval($childCatId)."') = 1")
+                        ->first(['alias', 'category_id','aLIas_pinyin','pid','category_arr_id as cat_arr_id']);
+                    if (!empty($childCategory)) {
+                        $childCategory = $this->processArticles($childCategory, $website);
+                        // 查询此层级的所有子栏目
+                        $all_childcat = WebsiteCategory::where($website)
+                        ->where("pid", $childCategory['pid'])
+                        // ->whereRaw("JSON_CONTAINS(category_arr_id, '".intval($childCatId)."') = 1")
+                        ->get(['alias', 'category_id','aLIas_pinyin','pid','category_arr_id as cat_arr_id']);
+                        $all_childcat = $this->processArticles($all_childcat, $website);
                         // 查询子栏目图片新闻
-                        $childImgArticles = Article::where('catid', $childCatId)
-                            ->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");
-                            })
-                            ->select(
-                                'article.id',
-                                'article.title',
-                                'article.imgurl',
-                                'article.author',
-                                'article.updated_at',
-                                'article.introduce',
-                                'article.islink',
-                                'article.linkurl',
-                                'article.copyfrom',
-                                DB::raw("'$child_pinyin' as pinyin")
-                            )
-                            ->where('imgurl', '!=', '')
-                            ->orderBy('updated_at', 'desc')
-                            ->limit($childImgNum)
-                            ->get()->all();
+                        if( isset($childImgNum) && $childImgNum!=0 ){
+                            $childImgArticles = Article::where(function($query) use ($childCatId) {
+                                $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$childCatId\"')")
+                                        ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$childCatId')");
+                                })
+                                ->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");
+                                })
+                                ->select('article.id','article.title','article.imgurl','article.author',
+                                    'article.updated_at','article.introduce','article.islink','article.linkurl',
+                                    'article.catid','article.cat_arr_id','article.copyfrom',)
+                                ->where('imgurl', '!=', '')
+                                ->orderBy('updated_at', 'desc')
+                                ->limit($childImgNum)
+                                ->get();
+                            $childImgArticles = $this->processArticles($childImgArticles, $website);
+                        }
                         // 查询子栏目文字新闻
-                        $childTextArticles = Article::where('catid', $childCatId)
-                            ->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");
-                            })
-                            ->select(
-                                'article.id',
-                                'article.title',
-                                'article.author',
-                                'article.updated_at',
-                                'article.introduce',
-                                'article.islink',
-                                'article.linkurl',
-                                'article.copyfrom',
-                                DB::raw("'$child_pinyin' as pinyin")
-                            )
-                            ->orderBy('updated_at', 'desc')
-                            ->limit($childTextNum)
-                            ->get()->all();
-                        $resultItem['child'] = [
-                            'alias' => $childCategoryInfo ? $childCategoryInfo->alias : null,
-                            'category_id' => $childCatId,
-                            'pinyin' => $childCategoryInfo->aLIas_pinyin ?? '',
-                            'all_childcat' => $childCategory,
-                            'imgnum' => $childImgArticles,
-                            'textnum' => $childTextArticles,
-                        ];
+                        if( isset($childTextNum) && $childTextNum!=0 ){
+                            $childTextArticles = Article::where(function($query) use ($childCatId) {
+                                $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$childCatId\"')")
+                                        ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$childCatId')");
+                                })
+                                ->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");
+                                })
+                                ->select('article.id','article.title','article.author','article.updated_at','article.introduce',
+                                    'article.islink','article.linkurl','article.catid','article.cat_arr_id','article.copyfrom',)
+                                ->orderBy('updated_at', 'desc')
+                                ->limit($childTextNum)
+                                ->get();
+                            $childTextArticles = $this->processArticles($childTextArticles, $website); 
+                        }
                     }
-
-                    // $resultItem['pinyin'] = $childCategoryInfo->aLIas_pinyin ?? '';
+                    $resultItem['child'] = [
+                        'alias' => $childCategory ? $childCategory->alias : null,
+                        'category_id' => $childCategory ? $childCategory->category_id : null,
+                        'pinyin' => $childCategory ? $childCategory->pinyin : null,
+                        'all_childcat' => $all_childcat ?? [],
+                        'imgnum' => $childImgArticles ?? [],
+                        'textnum' => $childTextArticles ?? [],
+                    ];  
+                }else{
+                    $resultItem['child'] = [];
                 }
-            } else {
-                $resultItem['child'] = [];
-            }
             return $resultItem;
         }, $data);
         return Result::success($result);
@@ -2153,31 +2033,42 @@ class NewsService implements NewsServiceInterface
     /**
      * 封装处理文章的路由问题
      *  */
-    function processArticles($articles, $data)
-    {
-        if (!is_array($data)) {
-            // 可以根据实际情况进行日志记录或抛出异常
-            // 这里简单输出错误信息
-            echo "Error: \$data is not an array in processArticles. It is of type " . gettype($data) . PHP_EOL;
-            return $articles;
-        }
-        return $articles->map(function ($article) use ($data) {
-            $catid = $article->cat_arr_id ?? '';
-            $level = json_decode($catid, true);
-            $pinyin = '';
-            $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $data['website_id'])->first();
-            if (!empty($category->pid) && $category->pid != 0) {
+    function processArticles($articles, $data) {
+        // 检查 $articles 是否为数组或可迭代对象
+        if (is_array($articles) || is_iterable($articles) &&!empty($articles)) {
+            return $articles->map(function ($article) use ($data) {
+                $catid = $article->cat_arr_id?? '';
+                $level = json_decode($catid, true);
+                if (!is_array($level)) {
+                    return $article;
+                } else {
+                    $level = array_map('intval', $level);
+                }
                 $pinyin = WebsiteCategory::whereIn('category_id', $level)
-                    ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
-                    ->get(['aLIas_pinyin'])
+                    ->where($data)
+                    ->orderByRaw('FIELD(category_id, '. implode(',', $level). ')')
                     ->pluck('aLIas_pinyin')
                     ->implode('/');
+                $article->pinyin = $pinyin ?? '';
+                return $article;
+            });
+        } else {
+            // 若 $articles 不是数组或可迭代对象,直接处理单条数据
+            $catid = $articles->cat_arr_id?? '';
+            $level = json_decode($catid, true);
+            if (!is_array($level)) {
+                return $articles;
             } else {
-                $pinyin = $category->aLIas_pinyin ?? '';
+                $level = array_map('intval', $level);
             }
-            $article->pinyin = $pinyin;
-            return $article;
-        });
+            $pinyin = WebsiteCategory::whereIn('category_id', $level)
+                ->where($data)
+                ->orderByRaw('FIELD(category_id, '. implode(',', $level). ')')
+                ->pluck('aLIas_pinyin')
+                ->implode('/');
+            $articles->pinyin = $pinyin ?? '';
+            return $articles;
+        }
     }
     // 封装处理由问题
     function processJob($job, $data)