|
@@ -795,6 +795,7 @@ class NewsService implements NewsServiceInterface
|
|
|
*/
|
|
|
public function getWebsiteCatidArticle(array $data): array
|
|
|
{
|
|
|
+
|
|
|
$where = [
|
|
|
|
|
|
'website_category.category_id' => $data['catid'],
|
|
@@ -802,7 +803,51 @@ class NewsService implements NewsServiceInterface
|
|
|
|
|
|
];
|
|
|
|
|
|
- if (!empty($data['img_num'])) {
|
|
|
+ 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('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)
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ ->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)
|
|
@@ -813,7 +858,7 @@ class NewsService implements NewsServiceInterface
|
|
|
->get();
|
|
|
}
|
|
|
|
|
|
- if (!empty($data['text_num'])) {
|
|
|
+ if (isset($data['text_num']) && !empty($data['text_num'])) {
|
|
|
$category['text'] = WebsiteCategory::where($where)
|
|
|
->leftJoin('article', 'article.catid', 'website_category.category_id')
|
|
|
->where('article.status', 1)
|