gq 8 anos atrás
pai
commit
bdbf35a0dd

+ 7 - 8
server/app/Http/Controllers/Api/V1/IndexController.php

xqd
@@ -87,24 +87,23 @@ class IndexController extends Controller
      */
     public function home(Request $request)
     {
+        $arr1 =DreamInfoModel::orderBy('score','desc')->limit(20)->select('id')->get()->toArray();
+        $id_arr1 = array_column($arr1,'id');
+        $arr2 =DreamInfoModel::orderBy('score','desc')->limit(120)->select('id')->get()->toArray();
+        $id_arr2 = array_column($arr2,'id');
         $users = [];
         $type = $request->type;
         if ($type == 'trend') {
-            $dreams = DreamInfoModel::orderBy('score','desc')->with('user')->offset(20)->limit(100)->paginate(15);
-//            dd($dreams);
-
+            $dreams = DreamInfoModel::orderBy('score','desc')->with('user')->whereNotIn('id', $id_arr1)->limit(100)->paginate(20);
             $this->dreams($dreams);
             return $this->api(compact('users','dreams'));
         } elseif ($type == 'news') {
-            $dreams = DreamInfoModel::orderBy('score','desc')->orderBy('created_at','desc')->with('user')->limit(500)->offset(100)->paginate(15);
-//            dd($dreams);
-
+            $dreams = DreamInfoModel::orderBy('score','desc')->orderBy('created_at','desc')->with('user')->whereNotIn('id', $id_arr2)->limit(500)->paginate(20);
             $this->dreams($dreams);
             return $this->api(compact('users','dreams'));
         } else{
             $banners = $this->getBanner();
-            $dreams = DreamInfoModel::orderBy('score','desc')->with('user')->limit(20)->paginate(15);
-//            dd($dreams);
+            $dreams = DreamInfoModel::orderBy('score','desc')->with('user')->limit(20)->paginate(20);
             $this->dreams($dreams);
             return $this->api(compact('banners','users','dreams'));
         }