Parcourir la source

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

caihongxingqiu il y a 5 ans
Parent
commit
0d358dac6c

+ 1 - 1
app/Repositories/BeanRepository.php

@@ -189,7 +189,7 @@ class BeanRepository
         $star_home['mybean']['yesterday_add_user'] = intval($user_bean['yesterday_add_user']) ?? 0;//昨日新增老板
         $star_home['mybean']['yesterday_quantity_issued'] = intval($yesterday_quantity_issued) ?? 0;//昨日发放总U米
 
-        $star_home['excellent_residents'] = $this->excellentResidents($request) ?? [];
+        //$star_home['excellent_residents'] = $this->excellentResidents($request) ?? [];
         $star_home['daily_news'] = $this->getNews($request);
         $star_home['tips'] = $this->getPlatformContent($id = 1);
 

+ 8 - 2
app/Traits/PostTrait.php

@@ -95,11 +95,14 @@ trait PostTrait
                 if($uid){
                     $isLike = Redis::ZSCORE($key, $uid.'_'.$item->id) ? 1 : 0;
                 }
+                $item->uid = intval($item->uid);
                 $item->is_like = $isLike;
                 $item->like_count = Redis::ZCOUNT($key, $item->id, $item->id);
+                $item->reply_count = 0;
+                $item->reply = [];
             }
         }else{
-            $comments = PostComment::where('post_id', $id)->where('parent_id', 0)->orderBy('like_count', 'desc')->orderBy('is_delete', 'asc')->orderBy('id', 'desc')->limit(2)->get();
+            $comments = PostComment::where('post_id', $id)->where('parent_id', 0)->where('is_delete', 0)->orderBy('like_count', 'desc')->orderBy('id', 'desc')->limit(2)->get();
             foreach($comments as $item){
                 $userComment = $this->userInfo($item->uid);
                 $isLike = 0;
@@ -109,15 +112,18 @@ trait PostTrait
                 $likeCount = Redis::ZCOUNT($key, $item->id, $item->id);
                 $comment[] = [
                     'id' => $item->id,
+                    'uid' => intval($userComment['uid']),
                     'username' => $userComment['username'],
                     'content' => $item->is_delete?'该评论已被删除':$item->content,
                     'is_delete' => $item->is_delete,
                     'is_like' => $isLike,
                     'like_count' => $likeCount,
+                    'reply_count' => 0,
+                    'reply' => [],
                 ];
             }
             Redis::SET($commentKey, json_encode($comment));
-            Redis::EXPIRE($commentKey, 3);
+            Redis::EXPIRE($commentKey, 300);
         }
         return $comment;
     }

+ 3 - 29
app/Transformers/Topic/TopicPostTransformer.php

@@ -12,6 +12,7 @@ use App\Models\PostCollect;
 use App\Models\PostComment;
 use App\Models\PostDislike;
 use App\Models\PostLike;
+use App\Traits\PostTrait;
 use App\Traits\UserTrait;
 use Carbon\Carbon;
 use League\Fractal\TransformerAbstract;
@@ -19,6 +20,7 @@ use League\Fractal\TransformerAbstract;
 class TopicPostTransformer extends TransformerAbstract
 {
     use UserTrait;
+    use PostTrait;
     public function __construct($uid, $invite_code)
     {
         $this->uid = $uid;
@@ -30,34 +32,6 @@ class TopicPostTransformer extends TransformerAbstract
         foreach($post->imgs as $img){
             $imgs[] = $img['img'];
         }
-        $comment = [];
-        $comments = PostComment::where('post_id', $post['id'])->where('parent_id', 0)->orderBy('id', 'desc')->limit(2)->get();
-        foreach($comments as $item){
-            $replyCount = $item->reply->count();
-            $replies = PostComment::where('parent_id', $item->id)->orderBy('id', 'desc')->limit(2)->get();
-            $reply = [];
-            foreach($replies as $val){
-                $userComment = $this->userInfo($val->uid);
-                $replyUsername = '';
-                if($val->reply_uid){
-                    $userReply = $this->userInfo($val->reply_uid);
-                    $replyUsername = $userReply['username'];
-                }
-                $reply[] = [
-                    'username' => $userComment['username'],
-                    'reply_username' => $replyUsername,
-                    'content' => $val->content,
-                ];
-            }
-            $userComment = $this->userInfo($item->uid);
-            $comment[] = [
-                'id' => $item->id,
-                'username' => $userComment['username'],
-                'content' => $item->content,
-                'reply_count' => $replyCount,
-                'reply' => $reply,
-            ];
-        }
         $topic = [];
         foreach($post->topic() as $key => $val){
             $topic[] = [
@@ -100,7 +74,7 @@ class TopicPostTransformer extends TransformerAbstract
             'is_like' => $isLike,
             'is_dislike' => $isDislike,
             'is_collect' => $isCollect,
-            'comment' => $comment,
+            'comment' => $this->getNewComment($post['id'], $this->uid),
             'is_follow' => $isFollow,
             'h5url' => config('customer.share_post_h5url')."?post_id={$post['id']}&invite_code={$this->invite_code}",
             'desc_url' => $post['type'] == 'html'?config('customer.app_service_url').'/community/fragment/detail/'.$post['id']:'',