浏览代码

Merge branch 'develop' of http://git.caihongxingqiu.net/rainbow/community-service into develop

xielin 5 年之前
父节点
当前提交
6dfe488d63

+ 12 - 6
app/Repositories/FeedRepositories.php

@@ -14,6 +14,7 @@ use App\Models\Feed;
 use App\Models\PostComment;
 use Carbon\Carbon;
 use Illuminate\Support\Facades\Log;
+use Illuminate\Support\Facades\Redis;
 use Tymon\JWTAuth\Facades\JWTAuth;
 use App\Models\PostDislike;
 use App\Models\PostLike;
@@ -134,12 +135,17 @@ class FeedRepositories
                 }
                 if($value['type'] == 5){
                     $value['content'] = null;
-                    $relate_data = $this->getFollowMemberFans($value['relate_id']);
-                    if($relate_data){
-                        if(!empty($relate_data['username'])){
-                            $relate_data['username'] = subtext($relate_data['username'],10);
-                        }
-                        $value['relate_data'] = $relate_data;
+                    $user = Redis::HGETALL('userInfo:'.$value['relate_id']);
+                    if(!$user){
+                        $user = $this->userInfo($value['relate_id']);
+                    }
+                    if($user){
+                        $value['relate_data'] = [
+                            'uid' => $user['uid'],
+                            'username' => subtext($user['username'],10),
+                            'avatar' => $user['avatar'],
+                            'follow_status' => $this->getFollowStatus($userInfo['uid'],$value['relate_id']),
+                        ];
                     }else{
                         unset($data[$key]);
                     }

+ 13 - 4
app/Repositories/MusicRepository.php

@@ -7,8 +7,8 @@
  */
 namespace App\Repositories;
 
-use App\Models\PostMusic;
 use App\Models\PostMusicCategoryRel;
+use Illuminate\Support\Facades\Cache;
 
 class MusicRepository
 {
@@ -21,16 +21,25 @@ class MusicRepository
     public function lists($request)
     {
         $perPage = isset($request['per_page']) ? $request['per_page'] : 20;
+        $music_key = config('constants.MUSIC_LIST');
+        if (Cache::has($music_key)) {
+            return Cache::store('redis')->get($music_key);
+        }
 
-        $this->postMusicCategoryRel = $this->postMusicCategoryRel
+        $category_name = '热门';
+        $postMusicCategoryRel = $this->postMusicCategoryRel
             ->join('post_music_category', 'post_music_category.id', '=', 'post_music_category_rel.music_category_id')
             ->join('post_music', 'post_music.id', '=', 'post_music_category_rel.mid')
             ->select('post_music.*')
-            ->where('post_music_category.id', 11)
+            ->where('post_music_category.name', 'like', "%{$category_name}%")
             ->orderBy('id', 'desc')
             ->paginate($perPage);
 
-        return $this->postMusicCategoryRel;
+        if (!Cache::has($music_key)) {
+            Cache::store('redis')->put($music_key, $postMusicCategoryRel, 604800);//一周过期
+        }
+
+        return $postMusicCategoryRel;
     }
 
 

+ 7 - 0
app/Repositories/PostRepositories.php

@@ -66,6 +66,9 @@ class PostRepositories
         if (empty($userInfo)) {
             return jsonError('获取用户信息失败');
         }
+        if(!$userInfo['sns_status']){
+            return jsonError('您已被禁言');
+        }
         $isValid = 0;
         if($userInfo['strength']){
             $isValid = 1;
@@ -208,6 +211,10 @@ class PostRepositories
             return jsonError('获取用户信息失败');
         }
 
+        if(!$userInfo['sns_status']){
+            return jsonError('您已被禁言');
+        }
+
         $oneHourTime = Carbon::now()->addHours(-1)->toDateTimeString();
         $oneHourCommentCount = $this->postComment->where('uid', $userInfo['uid'])->where('created_at', '>', $oneHourTime)->count();
         if($oneHourCommentCount > 59){

+ 16 - 0
app/Traits/UserTrait.php

@@ -27,6 +27,22 @@ trait UserTrait
         }
 
     }
+
+    //获取用户信息
+    public function userInfo($uid) {
+        try {
+            $sign = generateSign(['uid' => $uid], config('customer.app_secret'));
+            $url = config("customer.app_service_url").'/user/getUserInfo';
+            $array = [
+                'json' => ['sign' => $sign,'uid' => $uid], 'query' => [], 'http_errors' => false,'headers'=>['Authorization'=>"Bearer ".JWTAuth::getToken()]
+            ];
+            return http($url,$array,'get');
+        } catch (\Exception $e) {
+            return [];
+        }
+
+    }
+
     //获取关注状态
     public function getFollowStatus($uid, $followUid)
     {

+ 1 - 0
app/Transformers/Post/ListTransformer.php

@@ -27,6 +27,7 @@ class ListTransformer extends TransformerAbstract
             'username' => subtext($post['username'], 10),
             'avatar' => $post['avatar'],
             'title' => $post['title'],
+            'content' => subtext($post['content'], 20),
             'img' => $post['img'],
             'praise_count' => $post->data->praise_count,
             'is_like' => PostLike::where('post_id', $post['id'])->where('uid', $this->uid)->exists()?1:0,

+ 1 - 0
bootstrap/app.php

@@ -34,6 +34,7 @@ $app->configure('database');
 $app->configure('elasticsearch');
 $app->configure('aliyun');
 $app->configure('aliyunvod');
+$app->configure('constants');
 /*
 |--------------------------------------------------------------------------
 | Register Container Bindings

+ 9 - 0
config/constants.php

@@ -0,0 +1,9 @@
+<?php
+
+/**
+ * 常量配置
+ */
+
+return [
+    'MUSIC_LIST' => env('REDIS_MUSIC_LIST', 'music_list'),
+];