소스 검색

获取所有模块的新闻及栏目

15313670163 3 주 전
부모
커밋
fedac54310
2개의 변경된 파일82개의 추가작업 그리고 0개의 파일을 삭제
  1. 77 0
      app/JsonRpc/NewsService.php
  2. 5 0
      app/JsonRpc/NewsServiceInterface.php

+ 77 - 0
app/JsonRpc/NewsService.php

@@ -879,4 +879,81 @@ class NewsService implements NewsServiceInterface
         }
         return Result::success($category);
     }
+     /**
+     * 模块新闻加强plus版 
+     * @param array $data
+     * @return array
+    */
+    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) {
+            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']);
+
+            // 查询图片新闻
+            $imgArticles = Article::where('catid', $parentCatId)
+                ->where('imgurl', '!=', '')
+                // ->where($website)
+                ->limit($parentImgNum)
+                ->get();
+
+            // 查询文字新闻
+            $textArticles = Article::where('catid', $parentCatId)
+                // ->where($website)
+                ->limit($parentTextNum)
+                ->get();
+
+            $resultItem = [
+                'alias' => $category ? $category->alias : null,
+                'category_id' => $parentCatId,
+                'imgnum' => $imgArticles->toArray(),
+                'textnum' => $textArticles->toArray()
+            ];
+
+            if (!empty($item['child']) && $item['child'] != "") {
+                // 查询第一个pid等于parent中第一个参数的category来获取child的category_id
+                $childCategory = WebsiteCategory::where('pid', $parentCatId)->where($website)->first();
+                if ($childCategory) {
+                    list($childCatId, $childImgNum, $childTextNum) = explode(',', $item['child']);
+
+                    // 查询子栏目名称
+                    $childCategoryInfo = WebsiteCategory::where('category_id', $childCatId)->where($website)->first(['alias', 'category_id']);
+
+                    // 查询子栏目图片新闻
+                    $childImgArticles = Article::where('catid', $childCatId)
+                        ->where('imgurl', '!=', '')
+                        // ->where($website)
+                        ->limit($childImgNum)
+                        ->get();
+
+                    // 查询子栏目文字新闻
+                    $childTextArticles = Article::where('catid', $childCatId)
+                        // ->where($website)
+                        ->limit($childTextNum)
+                        ->get();
+
+                    $resultItem['child'] = [
+                        'alias' => $childCategoryInfo ? $childCategoryInfo->alias : null,
+                        'category_id' => $childCatId,
+                        'imgnum' => $childImgArticles->toArray(),
+                        'textnum' => $childTextArticles->toArray()
+                    ];
+                }
+            }
+
+            return $resultItem;
+        }, $data);
+        return Result::success($result);
+                // return Result::success($data);
+    }
 }

+ 5 - 0
app/JsonRpc/NewsServiceInterface.php

@@ -132,4 +132,9 @@ interface NewsServiceInterface
      * @return array
      */
     public function getWebsiteCatidArticle(array $data):array;
+    /**
+     * @param array $data
+     * @return array
+     */
+    public function getWebsiteAllArticle(array $data):array;
 }