|
@@ -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);
|
|
|
+ }
|
|
|
}
|