浏览代码

Merge branch 'web_sannong_fr'

15313670163 4 天之前
父节点
当前提交
346d0e6e44
共有 1 个文件被更改,包括 31 次插入31 次删除
  1. 31 31
      app/JsonRpc/NewsService.php

+ 31 - 31
app/JsonRpc/NewsService.php

@@ -2456,7 +2456,6 @@ class NewsService implements NewsServiceInterface
             return Result::error("查询失败", 0);
         }
         $catid = $data['id'];
-        // 此处代码在原逻辑中会依赖外部变量 $data、$catid,需确保这些变量在作用域内
         $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id',$catid)->orderBy('sort')->first(['pid','category_id','aLias_pinyin']);
         $parent_categpory = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id',$category['pid'])->orderBy('sort')->first(['aLias_pinyin']);
         $parent_pinyin = $parent_categpory ? $parent_categpory->aLias_pinyin ?? '' : '';
@@ -2465,7 +2464,8 @@ class NewsService implements NewsServiceInterface
         $categorys = WebsiteCategory::where('website_id', $data['website_id'])
             ->where('pid',$category['pid'])
             ->select(
-                '*',
+                'category_id','alias','aLIas_pinyin','pid','sort','is_url','web_url',
+                'seo_title','seo_keywords','seo_description',
                 DB::raw("CONCAT('$parent_pinyin', '/', aLIas_pinyin) as pinyin")
             )
             ->orderBy('sort')
@@ -2513,10 +2513,6 @@ class NewsService implements NewsServiceInterface
         if(empty($web)){
             return Result::error("查询失败", 0);
         }
-        // $category = WebsiteCategory::where('website_id', $data['website_id'])->where('pid',$data['id'])->orderBy('sort')->first(['pid','category_id']);
-        // if(empty($category)){
-        //     return Result::error("查询失败", 0);
-        // }
         $book = Book::where('status', 2)
             ->where('website_id', $data['website_id'])
             ->where('id', $data['id'])
@@ -2528,15 +2524,31 @@ class NewsService implements NewsServiceInterface
         if(empty($book)){
             return Result::error("查询失败", 0);
         }
-        // $categorys = WebsiteCategory::where('website_id', $data['website_id'])
-        // ->where('pid',$book['cat_id'])
-        // ->select('category_id','alias','aLIas_pinyin')
-        // ->orderBy('sort')->get()->all();
-        // $result = [
-        //     // 'category' => $categorys,
-        //     'books' => $book,
-        // ];
-        return Result::success($book);
+        // 先查询当前分类的 pid
+        $carpid = WebsiteCategory::where('website_id', $data['website_id'])
+            ->where('category_id', $book['cat_id'])
+            ->first(['pid','category_id']);
+        $query = WebsiteCategory::where('website_id', $data['website_id']);
+        if(!empty($carpid)){
+            if($carpid->pid!=0){
+                $pid = $carpid['pid'];
+                // $parent_pinyin = '';
+            }else{
+                $pid = $carpid['category_id'];
+                // $parent_pinyin = $currentCategory->aLias_pinyin?? '';
+            }
+        }
+        $categorys = $query->where('pid', $pid)
+            ->select('category_id','alias','aLIas_pinyin','pid','sort','is_url','web_url','category_arr_id as cat_arr_id',
+            )
+            ->orderBy('sort')
+            ->get();
+        $category = $this->processArticle($categorys, $data);
+        $result = [
+            'category' => $category,
+            'books' => $book,
+        ];
+        return Result::success($result);
     }
      /**
      * 尝试
@@ -2582,32 +2594,20 @@ class NewsService implements NewsServiceInterface
      * 封装处理文章的路由问题
      *  */
     function processArticle($article, $data) {
-        $article['img'] = Article::where('article.status', 1)
-            ->whereIn('article.id', $$article[0])
-            ->where(function ($query) use ($data) {
-                $query->where(function ($subQuery) use ($data) {
-                    $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '".intval($data['website_id'])."') = 0");
-                })->orWhereNull("ignore_ids");
-            })
-            ->select(
-                'article.id',
-                'article.title',
-                'article.imgurl',
-                'article.author',
-            );
          return $article->map(function ($article) use ($data) {
             $catid = $article->cat_arr_id?? '';
             $level = json_decode($catid, true);
             $pinyin = '';
-            $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $data['website_id'])->first();
-            if (!empty($category->pid) && $category->pid!= 0) {
+            // $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $data['website_id'])->first();
+            if (!empty($level) && is_array($level)) {
                 $pinyin = WebsiteCategory::whereIn('category_id', $level)
+                    ->where('website_id', $data['website_id'])
                     ->orderByRaw('FIELD(category_id, '. implode(',', $level). ')')
                     ->get(['aLIas_pinyin'])
                     ->pluck('aLIas_pinyin')
                     ->implode('/');
             } else {
-                $pinyin = $category->aLIas_pinyin ?? '';
+                $pinyin = '';
             }
             $article->pinyin = $pinyin;
             return $article;