소스 검색

修改获取头条新闻

15313670163 2 주 전
부모
커밋
79e38a1579
1개의 변경된 파일17개의 추가작업 그리고 15개의 파일을 삭제
  1. 17 15
      app/JsonRpc/NewsService.php

+ 17 - 15
app/JsonRpc/NewsService.php

@@ -288,6 +288,7 @@ class NewsService implements NewsServiceInterface
     */
     public function getWebsiteArticlett(array $data): array   
     {
+        // return Result::success($data['website_id']);
         $category = WebsiteCategory::where('website_id', $data['website_id'])->pluck('category_id');
         $category = array_values(array_unique($category->toArray()));
         $result = [];
@@ -318,14 +319,17 @@ class NewsService implements NewsServiceInterface
                             $catid = $article->catid;
                             $pinyin = '';
                             $category = WebsiteCategory::where('category_id', $catid)->where('website_category.website_id', $data['website_id'])->first();
-                            $pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
-                            if ($category->pid != 0 && !empty($category->aLIas_pinyin)) {
+                            if (!empty($category->aLIas_pinyin) && $category->pid != 0) {
                                 $childCategory = WebsiteCategory::where('category_id', $category->pid)->where('website_category.website_id', $data['website_id'])->first();
-                                $pinyin = $childCategory->aLIas_pinyin ?  $childCategory->aLIas_pinyin.'/'. $category->aLIas_pinyin : null;
+                                if ($childCategory && !empty($childCategory->aLIas_pinyin)) {
+                                    $pinyin = $childCategory->aLIas_pinyin ?  $childCategory->aLIas_pinyin.'/'. $category->aLIas_pinyin : null;
+                                }
+                            } else {
+                                $pinyin = $category->aLIas_pinyin ?  $category->aLIas_pinyin : null;
                             }
                             $article->pinyin = $pinyin;
                             return $article;
-                            });
+                        });
                         if (empty($result)) {
                             return Result::success([]);
                         }
@@ -367,17 +371,15 @@ class NewsService implements NewsServiceInterface
                 ->map(function ($article ) use ($data) {
                     $catid = $article->catid;
                     $pinyin = '';
-                    // $category = WebsiteCategory::whereIn('category_id', $catArrId)->where('website_category.website_id', $data['website_id'])->get()->all();
-                    // if ($catArrId) {
-                        // foreach ($catArrId as $categoryId) {
-                            $category = WebsiteCategory::where('category_id', $catid)->where('website_category.website_id', $data['website_id'])->first();
-                            $pinyin = $category->aLIas_pinyin ?  $category->aLIas_pinyin : null;
-                            if ($category->pid != 0 && !empty($category->aLIas_pinyin)) {
-                                $childCategory = WebsiteCategory::where('category_id', $category->pid)->where('website_category.website_id', $data['website_id'])->first();
-                                $pinyin = $childCategory->aLIas_pinyin ?  $childCategory->aLIas_pinyin.'/'. $category->aLIas_pinyin : null;
-                            }
-                        // }
-                    // }
+                    $category = WebsiteCategory::where('category_id', $catid)->where('website_category.website_id', $data['website_id'])->first();
+                    if (!empty($category->aLIas_pinyin) && $category->pid != 0) {
+                        $childCategory = WebsiteCategory::where('category_id', $category->pid)->where('website_category.website_id', $data['website_id'])->first();
+                        if ($childCategory && !empty($childCategory->aLIas_pinyin)) {
+                            $pinyin = $childCategory->aLIas_pinyin ?  $childCategory->aLIas_pinyin.'/'. $category->aLIas_pinyin : null;
+                        }
+                    } else {
+                        $pinyin = $category->aLIas_pinyin ?  $category->aLIas_pinyin : null;
+                    }
                     $article->pinyin = $pinyin;
                     return $article;
                 });