wzq 5 anni fa
parent
commit
fb8d9bbdfc
2 ha cambiato i file con 44 aggiunte e 25 eliminazioni
  1. 43 24
      app/Http/Controllers/V1/PostController.php
  2. 1 1
      app/Traits/CmsTrait.php

+ 43 - 24
app/Http/Controllers/V1/PostController.php

@@ -24,6 +24,7 @@ use App\Transformers\Topic\TopicPostTransformer;
 use Illuminate\Http\Request;
 use Illuminate\Support\Carbon;
 use Illuminate\Support\Facades\Log;
+use Illuminate\Support\Facades\Redis;
 use Illuminate\Support\Facades\Validator;
 use Illuminate\Validation\Rule;
 use League\Fractal\Manager;
@@ -152,7 +153,7 @@ class PostController extends Controller
             Log::info('获取用户信息失败');
             return jsonError('获取用户信息失败');
         }
-        $floor = $this->getFloorInfo();
+
         $param = $request->all();
         $list = $this->postRepositories->suggestPost($param);
         $fractal = new Manager();
@@ -160,32 +161,50 @@ class PostController extends Controller
         $resource->setPaginator(new IlluminatePaginatorAdapter($list));
         $data = $fractal->createData($resource)->toArray();
 
-        if(!(isset($param['current_page']) && $param['current_page'] > 1) && $floor && $floor['data']){
-            $floor = array_column($floor['data'], null, 'floor_location');
-            $newData = [];
-            foreach($data['data'] as $key => $val){
-                if(isset($floor[$key+1])){
-                    if($floor[$key+1]['show_type'] == 'banner'){
-                        $newData[] = [
-                            'show_type' => 'banner',
-                        ];
-                    }elseif($floor[$key+1]['show_type'] == 'user'){
-                        $newData[] = [
-                            'show_type' => 'user',
-                        ];
-                    }elseif($floor[$key+1]['show_type'] == 'video'){
-                        $newData[] = [
-                            'show_type' => 'video',
-                        ];
-                    }elseif($floor[$key+1]['show_type'] == 'topic'){
-                        $newData[] = [
-                            'show_type' => 'topic',
-                        ];
+        if(!(isset($param['current_page']) && $param['current_page'] > 1)){
+            $key = 'suggest_post_floor';
+            $floor = Redis::get($key);
+            if(!$floor){
+                $floor = $this->getFloorInfo();
+                if($floor){
+                    Redis::set($key, json_encode($floor));
+                    Redis::expire($key, 600);
+                }
+
+            }else{
+                $floor = json_decode($floor, true);
+            }
+
+            if($floor){
+                $newData = [];
+                foreach($data['data'] as $key => $val){
+                    if(isset($floor[$key+1])){
+                        if($floor[$key+1]['show_type'] == 'banner'){
+                            $newData[] = [
+                                'show_type' => 'banner',
+                                'data' => $floor[$key+1]['data'],
+                            ];
+                        }elseif($floor[$key+1]['show_type'] == 'user'){
+                            $newData[] = [
+                                'show_type' => 'user',
+                                'data' => $floor[$key+1]['data'],
+                            ];
+                        }elseif($floor[$key+1]['show_type'] == 'video'){
+                            $newData[] = [
+                                'show_type' => 'video',
+                                'data' => $floor[$key+1]['data'],
+                            ];
+                        }elseif($floor[$key+1]['show_type'] == 'topic'){
+                            $newData[] = [
+                                'show_type' => 'topic',
+                                'data' => $floor[$key+1]['data'],
+                            ];
+                        }
                     }
+                    $newData[] = $val;
                 }
-                $newData[] = $val;
+                $data['data'] = $newData;
             }
-            $data['data'] = $newData;
         }
         return jsonSuccess($data);
     }

+ 1 - 1
app/Traits/CmsTrait.php

@@ -14,7 +14,7 @@ trait CmsTrait
     public function getFloorInfo() {
         try {
             $sign = generateSign([], config('customer.app_secret'));
-            $url = config("customer.app_service_url").'/cms/v2/floor/index';
+            $url = config("customer.app_service_url").'/cms/v2/floor/info';
             $array = [
                 'json' => ['sign' => $sign], 'query' => [], 'http_errors' => false,'headers'=>['Authorization'=>"Bearer ".JWTAuth::getToken()]
             ];