Преглед на файлове

Merge branch 'web_sannong_fr'

15313670163 преди 2 седмици
родител
ревизия
5ce22a0f99
променени са 1 файла, в които са добавени 46 реда и са изтрити 12 реда
  1. 46 12
      app/JsonRpc/NewsService.php

+ 46 - 12
app/JsonRpc/NewsService.php

@@ -655,6 +655,7 @@ class NewsService implements NewsServiceInterface
     public function getWebsiteArticlett(array $data): array
     {
         $category = WebsiteCategory::where('website_id', $data['website_id'])->pluck('category_id');
+        $category = array_values(array_unique($category->toArray()));
         $result = [];
         if ($category) {
             $placeid = isset($data['placeid']) && !empty($data['placeid']) ? $data['placeid'] - 1 : 0;
@@ -673,14 +674,27 @@ class NewsService implements NewsServiceInterface
                     foreach ($keywordArray as $k => $v) {
                         $whereL7[] = ['keyword', 'like', '%' . $v . '%'];
                     }
+                    // 原始查询
                     $result = Article::where($whereL7)
                         ->offset($placeid)
                         ->limit($data['pageSize'])
                         ->orderBy('updated_at', 'desc')
-                        ->get();
-                    if (empty($result)) {
-                        return Result::success([]);
-                    }
+                        ->get()
+                        ->map(function ($article ) use ($data) {
+                            $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)) {
+                                $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;
+                            }
+                            $article->pinyin = $pinyin;
+                            return $article;
+                            });
+                        if (empty($result)) {
+                            return Result::success([]);
+                        }
                     return Result::success($result);
                 } else {
                     return Result::error("参数错误level=7,id不能为空", 0);
@@ -691,6 +705,8 @@ class NewsService implements NewsServiceInterface
             var_dump($where, 'where-----------------');
             $result = Article::where($where)
                 ->whereIn("catid", $category)
+                // ->leftJoin('website_category', 'article.catid', 'website_category.category_id')
+                // ->where('website_category.website_id', $data['website_id'])
                 ->where(function ($query) use ($data) {
                     $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
                         ->orWhereNull("ignore_ids");
@@ -702,17 +718,35 @@ class NewsService implements NewsServiceInterface
                         ->where('updated_at', '>', date("Y-m-d H:i:s", strtotime("-30 day")));
                 })
                 ->when($data['level'] == 4, function ($query) {
-                    $query->orderBy("updated_at", "desc");
+                    $query->orderBy("article.updated_at", "desc");
                 })
                 ->when(!empty($data['level']), function ($query) use ($data) {
                     if ($data['level'] != 4 && $data['level'] != 5) {
                         $query->whereRaw("JSON_CONTAINS(level, '" . intval($data['level']) . "') = 1")
-                            ->orderBy("updated_at", "desc");
+                            ->orderBy("article.updated_at", "desc");
                     }
                 })
+                ->select('article.*')
                 ->offset($placeid)
                 ->limit($data['pageSize'])
-                ->get();
+                ->get()
+                ->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;
+                            }
+                        // }
+                    // }
+                    $article->pinyin = $pinyin;
+                    return $article;
+                });
             if (empty($result)) {
                 return Result::error("暂无头条新闻", 0);
             }
@@ -1318,7 +1352,7 @@ class NewsService implements NewsServiceInterface
                 // return Result::error("暂无此栏目",0);
             }else{
                 $parent_alias = $category->alias ?? '';
-                $parent_pinyin = $category->aLIas_pinyin ?'/'.$category->aLIas_pinyin.'/' : null;
+                $parent_pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
                 // 查询图片新闻
                 $imgArticles = Article::where('catid', $parentCatId)
                 ->where('status', 1)
@@ -1376,15 +1410,15 @@ class NewsService implements NewsServiceInterface
             ];
 
             if (!empty($item['child']) && $item['child'] != "") {
-                $parent_pinyin_str = is_string($parent_pinyin) ? $parent_pinyin : '';
+                $parent_pinyin_str = is_string($parent_pinyin) ? $parent_pinyin.'/' : '';
                 $childCategory = WebsiteCategory::where('pid', $parentCatId)->where($website)
-                    ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin, '/') as aLIas_pinyin", [$parent_pinyin_str])
+                    ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin) as aLIas_pinyin", [$parent_pinyin_str])
                     ->get()->all();
                 if ($childCategory) {
                     list($childCatId, $childImgNum, $childTextNum) = explode(',', $item['child']);
                     // 查询子栏目名称
                 $childCategoryInfo = WebsiteCategory::where('category_id', $childCatId)->where($website)
-                    ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin, '/') as aLIas_pinyin", [$parent_pinyin])
+                    ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin) as aLIas_pinyin", [$parent_pinyin_str])
                     ->first();
                 $child_pinyin = $childCategoryInfo->aLIas_pinyin ? $childCategoryInfo->aLIas_pinyin : null;
                     if(empty($childCategoryInfo)){
@@ -1473,7 +1507,7 @@ class NewsService implements NewsServiceInterface
             ]; 
             // 查询栏目名称 
             $category = WebsiteCategory::where('category_id', $parentCatId)->where($website)->first(['alias', 'category_id','aLIas_pinyin']); 
-            $pinyin = $category->aLIas_pinyin ? '/'.$category->aLIas_pinyin.'/' : null;
+            $pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
             if(empty($category)){ 
                 $imgArticles = []; 
                 $textArticles = [];