Explorar o código

c端:优化并修改乡村网专用-获取新闻的接口;修改获取新闻列表、搜索新闻的接口;

15313670163 hai 6 días
pai
achega
8f82f8122a
Modificáronse 1 ficheiros con 288 adicións e 321 borrados
  1. 288 321
      app/JsonRpc/NewsService.php

+ 288 - 321
app/JsonRpc/NewsService.php

@@ -922,57 +922,66 @@ class NewsService implements NewsServiceInterface
     return Result::success($result);
     return Result::success($result);
   }
   }
 
 
-  /**
-   *获取新闻列表 
-   * @param array $data
-   * @return array
-   */
-  public function getWebsiteArticleList(array $data): array
-  {
-    // return Result::success($data);
-    $where[] = ['status', '=', 1];
-    if (isset($data['catid']) && !empty($data['catid'])) {
-      $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($where)
-      ->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.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 = [
-      'rows' => $rep->toArray(),
-      'count' => $count,
-    ];
+    /**
+     *获取新闻列表 
+     * @param array $data
+     * @return array
+     */
+    public function getWebsiteArticleList(array $data): array 
+    {
+        // return Result::success($data);
+        $where[] = ['status', '=', 1];
+        $website_id = $data['website_id'];
+        if (isset($data['catid']) && !empty($data['catid'])) {
+            $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $data['catid'])->pluck('category_id');
+            if (empty($category)) {
+                return Result::error("此网站暂无此栏目", 0);
+            }
+            array_push($where, ['catid', '=', $data['catid']]);
+            
+        }
+        // return Result::success($where);
+        $query = Article::where($where)
+            ->leftJoinSub(function ($query) use ($website_id) {
+                $query->from('article_ignore')
+                    ->where('website_id', $website_id);
+            }, 'article_ignore', function ($join) {
+                $join->on('article_ignore.article_id', '=', 'article.id');
+            })
+            ->where(function ($query) use ($website_id) {
+                $query->whereNull('article_ignore.article_id')
+                    ->orWhere('article_ignore.website_id', '!=', $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');
+        $count = $query->count();
+       $rep = $query->orderBy("updated_at", "desc")
+        ->offset(($data['page'] - 1) * $data['pageSize'])
+        ->limit($data['pageSize'])
+        ->get()->all();
+        $categorys = $this->processArticlePro($website_id);
+        $cat_1st_arr = $categorys['cat_1st_arr'];
+        $catiall = $categorys['catiall'];
+        // $web['website_id'] = $data['website_id'];
+        foreach ($rep as $k => $v) {
+            $rep[$k]->category_name = $catiall[$v->catid]['alias'];
+            $rep[$k]->pinyin = $catiall[$v->catid]['pinyin'];
+        }
+        // $rep = $this->processArticles($rep,$web);
+        $data = [
+            'rows' => $rep,
+            'count' => $count,
+        ];
 
 
     if (empty($rep)) {
     if (empty($rep)) {
       return Result::error("没有信息数据");
       return Result::error("没有信息数据");
@@ -1291,137 +1300,147 @@ class NewsService implements NewsServiceInterface
     return Result::success($result);
     return Result::success($result);
   }
   }
 
 
-  /**
-   * 前端-搜索新闻列表
-   * @param array $data
-   * @return array
-   */
-  public function selectWebsiteArticle(array $data): array
-  {
-    $category = WebsiteCategory::where('website_id', $data['website_id'])->pluck('category_id');
-    $query = Article::where('status', 1)
-      ->whereIn('catid', $category)
-      ->where(function ($query) use ($data) {
-        $query->where(function ($subQuery) use ($data) {
-          $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0");
-        })->orWhereNull("ignore_ids");
-      });
-    // return Result::success($all_articles);
-    if (isset($data['cityid']) && !empty($data['cityid'])) {
-      $query->whereRaw("JSON_CONTAINS(city_arr_id, '" . intval($data['cityid']) . "')");
-    }
-    if (isset($data['department_id']) && !empty($data['department_id'])) {
-      $query->whereRaw("JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "')");
-    }
-    if (isset($data['keyword']) && !empty($data['keyword'])) {
-      $query->where('title', 'like', '%' . $data['keyword'] . '%');
-    }
-    // 计算总数
-    $count = $query->count();
-    // 分页查询
-    $articles = $query
-      ->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',
-        'article.department_arr_id',
-        'article.city_arr_id',
-      )
-      ->orderBy("updated_at", "desc")
-      ->offset(($data['page'] - 1) * $data['pageSize'])
-      ->limit($data['pageSize'])
-      ->get();
-    $web['website_id'] = $data['website_id'];
-    $articles = $this->processArticles($articles, $web);
-    if (empty($articles)) {
-      return Result::error("没有符合条件的资讯数据");
+     /**
+     * 前端-搜索新闻列表
+     * @param array $data
+     * @return array
+     */
+    public function selectWebsiteArticle(array $data): array
+    {
+        $category = WebsiteCategory::where('website_id', $data['website_id'])->pluck('category_id');
+         $website_id = $data['website_id'];
+        $categorys = $this->processArticlePro($website_id); 
+        $catiall = $categorys['catiall'];
+        $query = Article::where('status', 1)
+            ->whereIn('catid', $category)
+            ->leftJoinSub(function ($query) use ($website_id) {
+                $query->from('article_ignore')
+                    ->where('website_id', $website_id);
+            }, 'article_ignore', function ($join) {
+                $join->on('article_ignore.article_id', '=', 'article.id');
+            })
+            ->where(function ($query) use ($website_id) {
+                $query->whereNull('article_ignore.article_id')
+                    ->orWhere('article_ignore.website_id', '!=', $website_id);
+            });
+        // return Result::success($all_articles);
+        if (isset($data['cityid']) && !empty($data['cityid'])) {
+            $query->whereRaw("JSON_CONTAINS(city_arr_id, '" . intval($data['cityid']) . "')");
+        }
+        if (isset($data['department_id']) && !empty($data['department_id'])) {
+            $query->whereRaw("JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "')");
+        }
+        if (isset($data['keyword']) && !empty($data['keyword'])) {
+            $query->where('title', 'like', '%' . $data['keyword'] . '%');
+        }
+        // 计算总数
+        $count = $query->count();
+        // 分页查询
+        $articles = $query
+            ->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',
+                'article.department_arr_id',
+                'article.city_arr_id',)
+            ->orderBy("updated_at", "desc")
+            ->offset(($data['page'] - 1) * $data['pageSize'])
+            ->limit($data['pageSize'])
+            ->get();
+       
+        foreach ($articles as $k => $v) {
+            $articles[$k]->category_name = $catiall[$v->catid]['alias'];
+            $articles[$k]->pinyin = $catiall[$v->catid]['pinyin'];
+        }
+        if (empty($articles)) {
+            return Result::error("没有符合条件的资讯数据");
+        }
+        $result = [
+            'rows' => $articles,
+            'count' => $count,
+        ];
+        return Result::success($result);
     }
     }
-    $result = [
-      'rows' => $articles,
-      'count' => $count,
-    ];
-    return Result::success($result);
-  }
 
 
-  /**
-   * 模块新闻加强版
-   * @param array $data
-   * @return array
-   */
-  public function getWebsiteCatidArticle(array $data): array
-  {
-    $where = [
-      'website_category.category_id' => $data['catid'],
-      'website_category.website_id' => $data['website_id'],
-    ];
-    // $category = WebsiteCategory::where($where);
-    if (isset($data['child_catnum']) && !empty($data['child_catnum'])) {
-      $child_catnum = $data['child_catnum'] ?? 1;
-      $category['child'] = WebsiteCategory::where('pid', $data['catid'])->where('website_id', $data['website_id'])->select('category_id', 'alias')->limit($child_catnum)->get()->toArray();
-      $childCategoryIds = array_column($category['child'], 'category_id');
-      if (empty($childCategoryIds)) {
-        return Result::error("暂无子栏目", 0);
-      }
-      $imgArticles = [];
-      $textArticles = [];
-      // return Result::success($childCategoryIds);
-      if (isset($data['child_imgnum']) && !empty($data['child_imgnum']) && $data['child_imgnum'] != 0) {
-        // 初始化子分类图片新闻和文字新闻数组
-
-        // 查询所有子级栏目的图文新闻
-        $imgArticles = Article::where('catid', $childCategoryIds[0])
-          ->where(function ($query) use ($data) {
-            $query->where(function ($subQuery) use ($data) {
-              $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0");
-            })->orWhereNull("ignore_ids");
-          })
-          ->where('status', 1)
-          ->where('imgurl', '!=', '')
-          ->select('*')
-          ->orderBy('updated_at', 'desc')
-          ->limit($data['child_imgnum'])
-          ->get();
-      }
-      if (isset($data['child_textnum']) && !empty($data['child_textnum']) && $data['child_textnum'] != 0) {
-        // 查询所有子级栏目的文字新闻
-        $textArticles = Article::where('catid', $childCategoryIds[0])
-          ->where('status', 1)
-          ->where(function ($query) use ($data) {
-            $query->where(function ($subQuery) use ($data) {
-              $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0");
-            })->orWhereNull("ignore_ids");
-          })
-          ->select('*')
-          ->orderBy('updated_at', 'desc')
-          ->limit($data['child_textnum'])
-          ->get();
-      }
-      // 遍历子分类,将图文新闻和文字新闻分别添加到子分类中
-      $category['child'] = array_map(function ($child) use ($imgArticles, $textArticles) {
-        $child['img'] = $imgArticles ? $imgArticles->where('catid', $child['category_id']) : [];
-        $child['text'] = $textArticles ? $textArticles->where('catid', $child['category_id']) : [];
-        return $child;
-      }, $category['child']);
-    }
-    // }
-    if (isset($data['img_num']) && !empty($data['img_num'])) {
-      $category['img'] = WebsiteCategory::where($where)
-        ->leftJoin('article', 'article.catid', 'website_category.category_id')
-        ->where('article.status', 1)
-        ->where('article.imgurl', '!=', '')
-        ->select('article.*', 'website_category.category_id', 'website_category.alias')
-        ->orderBy('article.updated_at', 'desc')
-        ->limit($data['img_num'])
-        ->get();
-    }
+    
+    /**
+     * 模块新闻加强版 
+     * @param array $data
+     * @return array
+    */
+    public function getWebsiteCatidArticle(array $data): array
+    {
+        $where = [
+            'website_category.category_id' => $data['catid'],
+            'website_category.website_id' => $data['website_id'],
+        ];
+        if(isset($data['child_catnum']) && !empty($data['child_catnum'])){
+            $child_catnum = $data['child_catnum']?? 1;
+            $category['child'] = WebsiteCategory::where('pid',$data['catid'])->where('website_id',$data['website_id'])->select('category_id','alias')->limit($child_catnum)->get()->toArray();
+            $childCategoryIds = array_column($category['child'], 'category_id');
+            if(empty($childCategoryIds)){
+                return Result::error("暂无子栏目",0);
+            }
+            $imgArticles = [];
+            $textArticles = [];
+            if(isset($data['child_imgnum']) && !empty($data['child_imgnum']) && $data['child_imgnum']!=0){
+                // 初始化子分类图片新闻和文字新闻数组
+                
+                // 查询所有子级栏目的图文新闻
+                $imgArticles = Article::where('catid', $childCategoryIds[0])
+                    ->where(function ($query) use ($data) {
+                        $query->where(function ($subQuery) use ($data) {
+                            $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '".intval($data['website_id'])."') = 0");
+                        })->orWhereNull("ignore_ids");
+                    })
+                    ->where('status', 1)
+                    ->where('imgurl', '!=', '')
+                    ->select('*')
+                    ->orderBy('updated_at', 'desc')
+                    ->limit($data['child_imgnum'])
+                    ->get();
+            }
+            if( isset($data['child_textnum']) && !empty($data['child_textnum']) && $data['child_textnum']!=0){
+                // 查询所有子级栏目的文字新闻
+                $textArticles = Article::where('catid', $childCategoryIds[0])
+                    ->where('status', 1)
+                    ->where(function ($query) use ($data) {
+                        $query->where(function ($subQuery) use ($data) {
+                            $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '".intval($data['website_id'])."') = 0");
+                        })->orWhereNull("ignore_ids");
+                    })
+                    ->select('*')
+                    ->orderBy('updated_at', 'desc')
+                    ->limit($data['child_textnum'])
+                    ->get();
+            }
+            // 遍历子分类,将图文新闻和文字新闻分别添加到子分类中
+            $category['child'] = array_map(function ($child) use ($imgArticles, $textArticles) {
+                $child['img'] = $imgArticles? $imgArticles->where('catid', $child['category_id']) : [];
+                $child['text'] = $textArticles? $textArticles->where('catid', $child['category_id']) : [];
+                return $child;
+            }, $category['child']);
+            
+        }
+        // }
+        if (isset($data['img_num']) && !empty($data['img_num'])) {
+            $category['img'] = WebsiteCategory::where($where)
+                ->leftJoin('article', 'article.catid', 'website_category.category_id')
+                ->where('article.status', 1)
+                ->where('article.imgurl', '!=', '')
+                ->select('article.*','website_category.category_id','website_category.alias')
+                ->orderBy('article.updated_at', 'desc')
+                ->limit($data['img_num'])
+                ->get();
+        }
 
 
     if (isset($data['text_num']) && !empty($data['text_num'])) {
     if (isset($data['text_num']) && !empty($data['text_num'])) {
       $category['text'] = WebsiteCategory::where($where)
       $category['text'] = WebsiteCategory::where($where)
@@ -1682,151 +1701,99 @@ class NewsService implements NewsServiceInterface
     $articles = $query->get();
     $articles = $query->get();
 
 
     return !empty($articles) ? $this->processArticles($articles, $website) : [];
     return !empty($articles) ? $this->processArticles($articles, $website) : [];
-  }
-  /**
-   * 乡村网-获取特殊新闻模块
-   * @param array $data
-   * @return array
-   */
-  public function getWebsiteArticles(array $data): array
-  {
-    $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 {
-        $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");
-        })
-
-          ->where('article.status', 1)
-          ->leftJoin('website_category', 'website_category.category_id', 'article.catid')
-          ->where('website_category.website_id', $website['website_id']);
+}
+    /**
+     * 乡村网-获取特殊新闻模块
+     * @param array $data
+     * @return array
+     */
+    public function getWebsiteArticles(array $data): array
+    {
+        $website_id = $data['website_id'];
+        $catids = json_decode($data['id'], true); 
+        $parent_category = array_column($catids, 'parent');
+        if(!empty($parent_category) && is_array($parent_category)){
+            $categorys = $this->processArticlePro($website_id);
+            $catiall = $categorys['catiall'];
+            $cat_1st_arr = $categorys['cat_1st_arr'];
+            //  return Result::success($categorys);
+            foreach($parent_category as $key => $value){
+                $arr = array_map('intval', explode(',', $value));
+                $parent_category = $arr[0] ?? 0;
+                $article_imgnum = $arr[1] ?? 0;
+                $article_textnum = $arr[2] ?? 0;
+                if($parent_category != 0){
+                    $category_arr = array_merge([$parent_category], $cat_1st_arr[$parent_category] ?? [0]);
+                    // return Result::success($category_arr);
+                    if($article_imgnum != 0){
+                        $img_article = Article::whereIn('catid', $category_arr)
+                            ->where('status',1)
+                            ->where('imgurl','!=', '')
+                            ->leftJoinSub(function ($query) use ($website_id) {
+                                $query->from('article_ignore')
+                                    ->where('website_id', $website_id);
+                            }, 'article_ignore', function ($join) {
+                                $join->on('article_ignore.article_id', '=', 'article.id');
+                            })
+                            ->where(function ($query) use ($website_id) {
+                                $query->whereNull('article_ignore.article_id')
+                                    ->orWhere('article_ignore.website_id', '!=', $website_id);
+                            })
+                            ->select('id','title','imgurl','author','updated_at','introduce',
+                            'islink','linkurl','copyfrom','cat_arr_id','catid as category_id')
+                            ->orderBy('updated_at', 'desc')
+                            ->limit($article_imgnum)
+                            ->get()->all();
+                            
+                        foreach ($img_article as $k => $v) {
+                            $img_article[$k]->alias = $catiall[$v->category_id]['alias'];
+                            // return Result::success($v);
 
 
-        // 查询文字新闻
-        $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',
-              // '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();
-        }
-        // 查询图片新闻
-        $imgArticles = clone $baseQuery;
-        $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')
-            ->limit($parentImgNum)
-            ->get()
-            ->all();
+                            $img_article[$k]->aLIas_pinyin = $catiall[$v->category_id]['pinyin'];
+                            
+                        }
+                        
+                    }else{
+                        $img_article = [];
+                    }
+                    if($article_textnum != 0){
+                        $text_article = Article::whereIn('catid', $category_arr)
+                            ->where('status',1)
+                            ->leftJoinSub(function ($query) use ($website_id) {
+                                $query->from('article_ignore')
+                                    ->where('website_id', $website_id);
+                            }, 'article_ignore', function ($join) {
+                                $join->on('article_ignore.article_id', '=', 'article.id');
+                            })
+                            ->where(function ($query) use ($website_id) {
+                                $query->whereNull('article_ignore.article_id')
+                                    ->orWhere('article_ignore.website_id', '!=', $website_id);
+                            })
+                            ->select('id','title','author','updated_at','introduce','islink',
+                            'linkurl','copyfrom','cat_arr_id','catid as category_id')
+                            ->orderBy('updated_at', 'desc')
+                            ->limit($article_textnum)
+                            ->get()->all();
+                        foreach ($text_article as $k => $v) {
+                            $text_article[$k]->alias = $catiall[$v->category_id]['alias'];
+                            $text_article[$k]->aLIas_pinyin = $catiall[$v->category_id]['pinyin'];
+                            // $text_article[$k]->alias = $catiall[$v->catid]['alias'];
+                        }
+                    }else{
+                        $text_article = [];
+                    }
+                    $catiall[$parent_category]['imgnum'] = $img_article ?? [];
+                    $catiall[$parent_category]['textnum'] = $text_article ?? [];
+                    $parent[$key] = $catiall[$parent_category];              
+                }else{
+                    $parent[$key] = [];
+                }
+            }
         }
         }
-      }
-      $resultItem = [
-        'alias' => $category ? $category->alias : null,
-        'category_id' => $parentCatId,
-        'pinyin' => $pinyin ? $pinyin : null,
-        'imgnum' => $imgArticles ?? [],
-        'textnum' => $textArticles ?? [],
-
-      ];
 
 
+        return Result::success($parent); 
 
 
-      return $resultItem;
-    }, $data);
-    return Result::success($result);
-  }
+    }
 
 
 
 
   // 封装处理商品的路由问题
   // 封装处理商品的路由问题