15313670163 3 weken geleden
bovenliggende
commit
00b37c9b2d
1 gewijzigde bestanden met toevoegingen van 60 en 58 verwijderingen
  1. 60 58
      app/JsonRpc/NewsService.php

+ 60 - 58
app/JsonRpc/NewsService.php

@@ -1002,6 +1002,8 @@ class NewsService implements NewsServiceInterface
         return Result::success($result);
                 // return Result::success($data);
     }
+
+
     /**
      * 乡村网-获取特殊新闻模块
      * @param array $data
@@ -1009,68 +1011,68 @@ class NewsService implements NewsServiceInterface
      */
     public function getWebsiteArticles(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','aLIas_pinyin']);
-            if(empty($category)){
-                $imgArticles = [];
-                $textArticles = [];
-                // return Result::error("暂无此栏目",0);
-            }else{
-                // 查询图片新闻
-                $imgArticles = Article::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");
-                    })
-                    ->where('imgurl', '!=', '')
-                    ->whereRaw("JSON_CONTAINS(category_arr_id, '".intval($parentCatId)."')")
-                    ->leftJoin('website_category', 'website_category.category_id', 'article.catid','website_category.aLIas_pinyin')
-                    ->select('article.*','website_category.category_id','website_category.alias')
-                    ->orderBy('updated_at', 'desc')
-                    ->limit($parentImgNum)
-                    ->get()->all();
+        // 修正传入的字符串,将单引号替换为双引号 
+        $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','aLIas_pinyin']); 
+            if(empty($category)){ 
+                $imgArticles = []; 
+                $textArticles = []; 
+                // return Result::error("暂无此栏目",0); 
+            }else{ 
+                // 查询图片新闻 
+                $imgArticles = Article::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"); 
+                    }) 
+                    ->where('imgurl', '!=', '') 
+                    ->whereRaw("JSON_CONTAINS(category_arr_id, '".intval($parentCatId)."')") 
+                    ->leftJoin('website_category', 'website_category.category_id', 'article.catid','website_category.aLIas_pinyin') 
+                    ->select('article.*','website_category.category_id','website_category.alias') 
+                    ->orderBy('updated_at', 'desc') 
+                    ->limit($parentImgNum) 
+                    ->get()->all(); 
+                // 查询文字新闻 
+                $textArticles = Article::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"); 
+                    }) 
+                    ->whereRaw("JSON_CONTAINS(category_arr_id, '".intval($parentCatId)."')") 
+                    ->leftJoin('website_category', 'website_category.category_id', 'article.catid','website_category.aLIas_pinyin') 
+                    ->select('article.*','website_category.category_id','website_category.alias','website_category.aLIas_pinyin') 
+                    ->orderBy('updated_at', 'desc') 
+                    ->limit($parentTextNum) 
+                    ->get()->all(); 
+            } 
+            $resultItem = [ 
+                'alias' => $category ? $category->alias : null, 
+                'category_id' => $parentCatId, 
+                'pinyin' => $category->aLIas_pinyin ?? '', 
+                'imgnum' => $imgArticles, 
+                'textnum' => $textArticles, 
                 
+            ]; 
 
-                // 查询文字新闻
-                $textArticles = Article::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");
-                    })
-                    ->whereRaw("JSON_CONTAINS(category_arr_id, '".intval($parentCatId)."')")
-                    ->leftJoin('website_category', 'website_category.category_id', 'article.catid','website_category.aLIas_pinyin')
-                    ->select('article.*','website_category.category_id','website_category.alias','website_category.aLIas_pinyin')
-                    ->orderBy('updated_at', 'desc')
-                    ->limit($parentTextNum)
-                    ->get()->all();
-            }
-            $resultItem = [
-                'alias' => $category ? $category->alias : null,
-                'category_id' => $parentCatId,
-                'pinyin' => $category->aLIas_pinyin ?? '',
-                'imgnum' => $imgArticles,
-                'textnum' => $textArticles,
-                
-            ];
 
+            return $resultItem; 
+        }, $data); 
+        return Result::success($result); 
 
-            return $resultItem;
-        }, $data);
-        return Result::success($result);
     }
     
+
+
 }