Forráskód Böngészése

Merge branch 'web_sannong_fr'

15313670163 3 hete
szülő
commit
9ecb5cad02
1 módosított fájl, 15 hozzáadás és 3 törlés
  1. 15 3
      app/JsonRpc/WebsiteService.php

+ 15 - 3
app/JsonRpc/WebsiteService.php

@@ -602,9 +602,11 @@ class WebsiteService implements WebsiteServiceInterface
         // 初始化 $pid 数组
         // $pid = [];
         // 以下注释掉的代码是之前的逻辑,用于获取非顶级分类的 pid
-        $pid = WebsiteCategory::where($website_id)
+        $pidQuery = WebsiteCategory::where($website_id)
             ->where('pid', '!=', 0)
-            ->pluck('pid');
+            ->orderBy('sort')
+            ->select('pid','category_id','alias');
+        $pid = $pidQuery->pluck('pid');
         $pid = array_values(array_unique($pid->toArray()));
 
         // 构建查询语句
@@ -625,12 +627,22 @@ class WebsiteService implements WebsiteServiceInterface
         // 执行查询
         $placeid = $data['placeid'] - 1;
         $result = $query->offset($placeid)->limit($data['num'])->get();
+
         if (!empty($result)) {
+            $pidResults = $pidQuery->get();
+            $pidMap = $pidResults->keyBy('pid');
+            $result->each(function ($record) use ($pidMap) {
+                if ($pidMap->has($record->category_id)) {
+                    $pidResult = $pidMap->get($record->category_id);
+                    $record->chilid_id = $pidResult->category_id;
+                    $record->chilid_alias = $pidResult->alias;
+                }
+            });
             return Result::success($result);
         } else {
             return Result::error("本网站暂无栏目", 0);
         }
-    }
+    } 
 
     /**
      * 获取友情链接