wzq vor 5 Jahren
Ursprung
Commit
84b0444768

+ 24 - 0
app/Models/TopicGroup.php

@@ -0,0 +1,24 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: Administrator
+ * Date: 2019/6/19
+ * Time: 14:34
+ */
+namespace App\Models;
+
+use Illuminate\Database\Eloquent\Model;
+use Illuminate\Database\Eloquent\SoftDeletes;
+
+class TopicGroup extends Model
+{
+    //
+    use SoftDeletes;
+    protected $table = 'topic_group';
+    protected $guarded = [];
+
+    public function info()
+    {
+        return $this->hasMany('App\Models\TopicGroupInfo', 'id', 'topic_group_id');
+    }
+}

+ 19 - 0
app/Models/TopicGroupInfo.php

@@ -0,0 +1,19 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: Administrator
+ * Date: 2019/6/19
+ * Time: 14:35
+ */
+namespace App\Models;
+
+use Illuminate\Database\Eloquent\Model;
+use Illuminate\Database\Eloquent\SoftDeletes;
+
+class TopicGroupInfo extends Model
+{
+    //
+    use SoftDeletes;
+    protected $table = 'topic_group_info';
+    protected $guarded = [];
+}

+ 30 - 2
app/Repositories/FloorRepository.php

@@ -1,6 +1,8 @@
 <?php
 namespace App\Repositories;
 use App\Models\Floor;
+use App\Models\TopicGroup;
+use App\Models\TopicGroupInfo;
 use App\Traits\UserTrait;
 use Illuminate\Support\Facades\Log;
 use Symfony\Component\HttpKernel\Exception\HttpException;
@@ -18,9 +20,13 @@ use Illuminate\Database\QueryException;
 class FloorRepository
 {
     use UserTrait;
-    public function __construct(Floor $floor)
+    public function __construct(Floor $floor,
+                                TopicGroup $topicGroup,
+                                TopicGroupInfo $topicGroupInfo)
     {
         $this->floor = $floor;
+        $this->topicGroup = $topicGroup;
+        $this->topicGroupInfo = $topicGroupInfo;
     }
 
     public function index($request)
@@ -38,7 +44,7 @@ class FloorRepository
         if(!$userInfo){
             return jsonError('获取用户信息失败');
         }
-        return $floor = $this->floor
+        $floor = $this->floor
             ->where('is_open', 1)
             ->whereIn('floor_type', [0,1,2,3])
             ->whereBetween('floor_location', [1,20])
@@ -47,14 +53,36 @@ class FloorRepository
         foreach($floor as $item){
             if($item->floor_type == 0){
                 //banner
+                $banner = $this->getBanner($item->group_ids);
+                if($banner){
+                    $data[$item->floor_location] = [
+                        'show_type' => 'banner',
+                        'data' => $banner
+                    ];
+                }
             }elseif($item->floor_type == 1){
                 //user
             }elseif($item->floor_type == 2){
                 //video
             }elseif($item->floor_type == 3){
                 //topic
+                $topicIds = $this->topicGroup
+                    ->join('topic_group_info', 'topic_group_info.topic_group_id', '=', 'topic_group.id')
+                    ->where('topic_group.id', $item->group_ids)
+                    ->limit(20)
+                    ->pluck('topic_group_info.topic_id')
+                    ->toArray();
+                $topicIds = implode($topicIds, ',');
+                $topic = $this->getTopic($topicIds);
+                if($topic){
+                    $data[$item->floor_location] = [
+                        'show_type' => 'topic',
+                        'data' => $topic
+                    ];
+                }
             }
         }
+        return $data;
     }
 
 }

+ 28 - 0
app/Traits/UserTrait.php

@@ -26,6 +26,34 @@ trait UserTrait
 
     }
 
+    public function getBanner($ids) {
+        try {
+            $sign = generateSign([], config('customer.app_secret'));
+            $url = config("customer.app_service_url").'/config/v2/bannerSet/lists';
+            $array = [
+                'json' => ['sign' => $sign, 'ids' => $ids], 'query' => [], 'http_errors' => false,'headers'=>['Authorization'=>"Bearer ".JWTAuth::getToken()]
+            ];
+            return http($url,$array,'get');
+        } catch (\Exception $e) {
+            return [];
+        }
+
+    }
+
+    public function getTopic($ids) {
+        try {
+            $sign = generateSign([], config('customer.app_secret'));
+            $url = config("customer.app_service_url").'/community/topic/group';
+            $array = [
+                'json' => ['sign' => $sign, 'ids' => $ids], 'query' => [], 'http_errors' => false,'headers'=>['Authorization'=>"Bearer ".JWTAuth::getToken()]
+            ];
+            return http($url,$array,'get');
+        } catch (\Exception $e) {
+            return [];
+        }
+
+    }
+
     public function getFollowStatus($uid, $followUid) {
         try {
             $sign = generateSign([], config('customer.app_secret'));