wesmiler 2 bulan lalu
induk
melakukan
273a2d5748
1 mengubah file dengan 6 tambahan dan 4 penghapusan
  1. 6 4
      app/Services/Api/ArticleService.php

+ 6 - 4
app/Services/Api/ArticleService.php

@@ -181,13 +181,15 @@ class ArticleService extends BaseService
         }
 
         $limit = ConfigService::make()->getConfigByCode('index_article_num',3);
-        $datas = ArticleCateModel::with(['articles'=>function($q) use($limit){
-            $q->take($limit);
-        }])->where(['type'=>$type,'status'=>1,'mark'=>1])
+        $datas = ArticleCateModel::with(['articles'])->where(['type'=>$type,'status'=>1,'mark'=>1])
             ->select(['id','name','sort','type'])
-            ->get();
+            ->get()->keyBy('id');
         $datas = $datas? $datas->toArray() : [];
         if($datas){
+            foreach ($datas as &$item){
+                $item['articles'] = $item['articles']? array_slice($item['articles'],0,$limit) :[];
+            }
+            unset($item);
             RedisService::set($cacheKey, $datas, rand(300,600));
         }