Pārlūkot izejas kodu

Merge branch 'develop'

xielin 5 gadi atpakaļ
vecāks
revīzija
571eccccbc

+ 58 - 0
app/Console/Commands/Tem/DelPostNewComment.php

@@ -0,0 +1,58 @@
+<?php
+namespace App\Console\Commands\Tem;
+
+
+use App\Models\Post;
+use Illuminate\Console\Command;
+use Illuminate\Support\Facades\Redis;
+
+class DelPostNewComment extends Command
+{
+    /**
+     * The name and signature of the console command.
+     *
+     * @var string
+     */
+    protected $signature = 'post:del_post_new_comment';
+
+    /**
+     * The console command description.
+     *
+     * @var string
+     */
+    protected $description = '删除内容最火评论缓存';
+
+    /**
+     * Create a new command instance.
+     *
+     * @return void
+     */
+    public function __construct(Post $post)
+    {
+        parent::__construct();
+        $this->post = $post;
+    }
+
+    /**
+     * Execute the console command.
+     *
+     * @return mixed
+     */
+    public function handle()
+    {
+        $this->line("开始删除内容最火评论缓存");
+
+        $count = $this->post->withTrashed()->count();
+        $bar = $this->output->createProgressBar($count);
+        $this->post->withTrashed()->chunk(100, function ($posts) use ($bar){
+            foreach($posts as $post){
+                Redis::DEL('post_new_comment_'.$post->id);
+                $bar->advance();
+            }
+            usleep(50000);
+        });
+        $bar->finish();
+        $this->line("\n删除内容最火评论缓存结束");
+
+    }
+}

+ 2 - 0
app/Console/Kernel.php

@@ -10,6 +10,7 @@ use App\Console\Commands\ContentFeedDelete;
 use App\Console\Commands\DelPostNewReply;
 use App\Console\Commands\ExcellentResidents;
 use App\Console\Commands\RankingList;
+use App\Console\Commands\Tem\DelPostNewComment;
 use Illuminate\Console\Scheduling\Schedule;
 use Laravel\Lumen\Console\Kernel as ConsoleKernel;
 
@@ -28,6 +29,7 @@ class Kernel extends ConsoleKernel
         ContentFeedDelete::class,
         ExcellentResidents::class,
         DelPostNewReply::class,
+        DelPostNewComment::class,
         RankingList::class
     ];
 

+ 15 - 2
app/Http/Controllers/V1/PostController.php

@@ -310,9 +310,15 @@ class PostController extends Controller
         if (!$exists) {
             return jsonError('内容飞走了');
         }
+        $userInfo = $this->getUserInfo();
+        if ($userInfo) {
+            $uid = $userInfo['uid'];
+        }else{
+            $uid = 0;
+        }
         $list = $this->postRepositories->commentList($request->all());
         $fractal = new Manager();
-        $resource = new Collection($list, new CommentTransformer());
+        $resource = new Collection($list, new CommentTransformer($request['post_id'], $uid));
         $resource->setPaginator(new IlluminatePaginatorAdapter($list));
         $data = $fractal->createData($resource)->toArray();
 
@@ -332,9 +338,16 @@ class PostController extends Controller
             return jsonError($validator->errors()->first());
         }
 
+        $userInfo = $this->getUserInfo();
+        if ($userInfo) {
+            $uid = $userInfo['uid'];
+        }else{
+            $uid = 0;
+        }
+        $postId = $this->postRepositories->getPostId($request['id']);
         $list = $this->postRepositories->replyList($request->all());
         $fractal = new Manager();
-        $resource = new Collection($list, new ReplyTransformer());
+        $resource = new Collection($list, new ReplyTransformer($postId, $uid));
         $resource->setPaginator(new IlluminatePaginatorAdapter($list));
         $data = $fractal->createData($resource)->toArray();
 

+ 18 - 0
app/Models/PostCommentLike.php

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

+ 59 - 9
app/Repositories/BeanRepository.php

@@ -189,21 +189,21 @@ 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);
 
         $backyard = $this->backyard($uid);
 
         $star_home['backyard']['backyard_imgs'] = [
-            "http://oss.caihongxingqiu.com/h5/planet/cover_01.png",
-            "http://oss.caihongxingqiu.com/h5/planet/cover_02.png",
-            "http://oss.caihongxingqiu.com/h5/planet/cover_03.png",
-            "http://oss.caihongxingqiu.com/h5/planet/cover_04.png",
-            "http://oss.caihongxingqiu.com/h5/planet/cover_05.png",
-            "http://oss.caihongxingqiu.com/h5/planet/cover_06.png",
-            "http://oss.caihongxingqiu.com/h5/planet/cover_07.png",
-            "http://oss.caihongxingqiu.com/h5/planet/cover_08.png"
+            "http://oss.uptoyo.com/h5/planet/cover_01.png",
+            "http://oss.uptoyo.com/h5/planet/cover_02.png",
+            "http://oss.uptoyo.com/h5/planet/cover_03.png",
+            "http://oss.uptoyo.com/h5/planet/cover_04.png",
+            "http://oss.uptoyo.com/h5/planet/cover_05.png",
+            "http://oss.uptoyo.com/h5/planet/cover_06.png",
+            "http://oss.uptoyo.com/h5/planet/cover_07.png",
+            "http://oss.uptoyo.com/h5/planet/cover_08.png"
         ];
         if ($backyard) {
             $star_home['backyard']['backyard_open'] = $backyard['backyard_open'];
@@ -219,6 +219,31 @@ class BeanRepository
         $star_home['battle']['start'] = $activityInfo['start'];
         $star_home['battle']['end'] = $activityInfo['end'];
         $star_home['battle']['news'] = Redis::get('battle_latest_info_'.$activityInfo['id'])??'战场四平八稳,劳驾老板亲自去战场督战';
+
+        //聊天室
+        $tmpChatroom = Redis::get('user_service_chatroom');
+        $chatrooms = $tmpChatroom?json_decode($tmpChatroom,true):[];
+        $current = Carbon::now()->format('H:i:s');
+        foreach ($chatrooms as &$chatroom) {
+            if ($chatroom['start']<$chatroom['end']) {
+                if ($current<$chatroom['start'] || $current>$chatroom['end']) {
+                    $chatroom['is_open'] = 0;
+                } else {
+                    $chatroom['is_open'] = 1;
+                }
+            } elseif ($chatroom['start']>$chatroom['end']) {
+                if ($current<$chatroom['end']) {
+                    $chatroom['is_open'] = 0;
+                } else {
+                    $chatroom['is_open'] = 1;
+                }
+            } else {
+                $chatroom['is_open'] = 1;
+            }
+        }
+        $star_home['chatroom'] = $chatrooms;
+        $star_home['is_show'] = intval(config('customer.exchange_shop_is_show'));
+
         return $star_home;
 
     }
@@ -348,6 +373,8 @@ class BeanRepository
         $star_detail['daily_news'] = $this->getNews($request);
         $star_detail['exchange'] = $exchange;
 
+
+
         return $star_detail;
 
     }
@@ -384,6 +411,29 @@ class BeanRepository
         $star_lists['daily_news'] = $this->getNews($request);
         $star_lists['tips'] = $this->getPlatformContent($id = 1);
 
+        //聊天室
+        $tmpChatroom = Redis::get('user_service_chatroom');
+        $chatrooms = $tmpChatroom?json_decode($tmpChatroom,true):[];
+        $current = Carbon::now()->format('H:i:s');
+        foreach ($chatrooms as &$chatroom) {
+            if ($chatroom['start']<$chatroom['end']) {
+                if ($current<$chatroom['start'] || $current>$chatroom['end']) {
+                    $chatroom['is_open'] = 0;
+                } else {
+                    $chatroom['is_open'] = 1;
+                }
+            } elseif ($chatroom['start']>$chatroom['end']) {
+                if ($current<$chatroom['end']) {
+                    $chatroom['is_open'] = 0;
+                } else {
+                    $chatroom['is_open'] = 1;
+                }
+            } else {
+                $chatroom['is_open'] = 1;
+            }
+        }
+        $star_lists['chatroom'] = $chatrooms;
+
         return $star_lists;
     }
 

+ 7 - 1
app/Repositories/BehaviorRecordRepositories.php

@@ -48,7 +48,8 @@ class BehaviorRecordRepositories
             'unlike' => 'general_ledger_record',
             'forward' => 'general_ledger_record',
             'collect' => 'general_ledger_record',
-            'comment' => 'comment_account_record'
+            'comment' => 'comment_account_record',
+            'comment_like' => 'general_ledger_record'
         ];
         return isset($tables[$behavior]) ? $tables[$behavior] : false;
     }
@@ -183,6 +184,11 @@ class BehaviorRecordRepositories
             if ($general['trigger_type']) {
                 $behavior->effective_trigger += 1;
             }
+            //评论点赞  存储当前评论的ID以及评论发布人ID
+            if ('comment_like' == $general['behavior_flag']) {
+                $data['related_content_id'] = $general['cl_comment_id'];
+                $data['content_author_id'] = $general['cl_comment_uid'];
+            }
             $behavior->save();
             DB::commit();
             //统计用户所有动态当天被阅读数

+ 1 - 1
app/Repositories/FeedRepositories.php

@@ -225,7 +225,7 @@ class FeedRepositories
             'comment_count' => $postInfo['comment_count'],
             'available_bean' => $postInfo['available_bean'],
             'will_collect_bean' => $postInfo['will_collect_bean'],
-            'post_comment' => $this->getNewComment($postInfo['id']),
+            'post_comment' => $this->getNewComment($postInfo['id'], $uid),
             'is_like' => Redis::SISMEMBER('post_like_' . $postInfo['id'], $uid),
             'is_dislike' => Redis::SISMEMBER('post_unlike_' . $postInfo['id'], $uid),
             'is_collect' => Redis::SISMEMBER('post_collect_' . $postInfo['id'], $uid),

+ 37 - 2
app/Repositories/PostRepositories.php

@@ -15,6 +15,7 @@ use App\Models\MemberFollowTopic;
 use App\Models\Post;
 use App\Models\PostCollect;
 use App\Models\PostComment;
+use App\Models\PostCommentLike;
 use App\Models\PostData;
 use App\Models\PostDislike;
 use App\Models\PostImgs;
@@ -511,7 +512,7 @@ class PostRepositories
         }
 
         $topicIds = [];
-        if(isset($request['category_id']) && $request['category_id']){
+        if (isset($request['category_id']) && $request['category_id']) {
             $topicIds = $this->categoryTopic->where('category_id', $request['category_id'])->pluck('topic_id')->toArray();
         }
 
@@ -563,6 +564,7 @@ class PostRepositories
         return $this->postComment
             ->where('post_id', $request['post_id'])
             ->where('parent_id', 0)
+            ->orderBy('like_count', 'desc')
             ->orderBy('id', 'desc')
             ->paginate($perPage);
     }
@@ -580,6 +582,16 @@ class PostRepositories
             ->paginate($perPage);
     }
 
+    /**
+     * 根据评论id获取内容id
+     */
+    public function getPostId($commentId)
+    {
+        return $this->postComment
+            ->where('id', $commentId)
+            ->value('post_id');
+    }
+
     /**
      * 话题列表
      */
@@ -647,6 +659,7 @@ class PostRepositories
         $postInfoKey = "post_info_" . $postId;
         $post = PostData::where('post_id', $postId)->first();
         if (!$post) return true;
+        $row = false;
         if (isset($request['behavior_flag']) && $request['behavior_flag'] == 'read') {
             $post->pv += 1;
             $post->pv_real += 1;
@@ -659,6 +672,7 @@ class PostRepositories
                     $this->topic->where('id', $id)->increment('pv');
                 }
             }
+            $row = $post->save();
             Log::debug("帖子:" . $postId . "被阅读,pv +1");
         } elseif (isset($request['behavior_flag']) && $request['behavior_flag'] == 'unlike') {
             //用户不喜欢帖子key
@@ -667,6 +681,7 @@ class PostRepositories
             PostDislike::create(['uid' => $request['target_id'], 'post_id' => $request['post_id']]);
             Redis::sadd($postUnLikeKey, $request['target_id']);
             Redis::HINCRBY($postInfoKey, 'dislike_count', 1);
+            $row = $post->save();
             Log::debug("帖子:" . $postId . "被不喜欢,unlike +1");
         } elseif (isset($request['behavior_flag']) && $request['behavior_flag'] == 'like') {
             //用户点赞帖子
@@ -686,6 +701,23 @@ class PostRepositories
                 Redis::HINCRBY($postInfoKey, 'praise_count', -1);
                 Log::debug("帖子:" . $postId . "被取消点赞,praise_count -1");
             }
+            $row = $post->save();
+        } elseif (isset($request['behavior_flag']) && $request['behavior_flag'] == 'comment_like') {
+            //用户点赞评论
+            $comment = PostComment::where('id', $request['comment_id'])->first();
+            $postLikeKey = "comment_like_" . $postId;
+            if ($request['behavior_value']) {
+                $comment->like_count += 1;
+                PostCommentLike::create(['uid' => $request['target_id'], 'comment_id' => $request['comment_id']]);
+                Redis::zadd($postLikeKey, $request['comment_id'], $request['target_id'] . '_' . $request['comment_id']);
+                Log::debug("评论:" . $request['comment_id'] . "被点赞,like_count +1");
+            } else {
+                $comment->like_count -= 1;
+                PostCommentLike::where(['uid' => $request['target_id'], 'comment_id' => $request['comment_id']])->delete();
+                Redis::zrem($postLikeKey, $request['target_id'] . '_' . $request['comment_id']);
+                Log::debug("评论:" . $request['comment_id'] . "被取消点赞,like_count -1");
+            }
+            $row = $comment->save();
         } elseif (isset($request['behavior_flag']) && $request['behavior_flag'] == 'forward') {
             $post->share_count += 1;
             $post->share_real_count += 1;
@@ -696,10 +728,12 @@ class PostRepositories
             } else {
                 PostShare::create(['uid' => $request['target_id'], 'post_id' => $request['post_id']]);
             }
+            $row = $post->save();
             Log::debug("帖子:" . $postId . "被分享,share_count +1");
         } elseif (isset($request['behavior_flag']) && $request['behavior_flag'] == 'comment') {
             $post->comment_count += 1;
             Redis::HINCRBY($postInfoKey, 'comment_count', 1);
+            $row = $post->save();
             Log::debug("帖子:" . $postId . "被评论,comment_count +1");
         } elseif (isset($request['behavior_flag']) && $request['behavior_flag'] == 'collect') {
             //用户收藏帖子
@@ -719,9 +753,10 @@ class PostRepositories
                 Redis::HINCRBY($postInfoKey, 'collect_count', -1);
                 Log::debug("帖子:" . $postId . "被取消收藏,collect_count -1");
             }
+            $row = $post->save();
         }
         $this->collectPostId($request['post_id']);
-        return $post->save();
+        return $row;
     }
 
     /**

+ 41 - 3
app/Traits/PostTrait.php

@@ -10,6 +10,7 @@ namespace App\Traits;
 
 use App\Models\Post;
 use App\Models\PostComment;
+use Illuminate\Support\Facades\Log;
 use Illuminate\Support\Facades\Redis;
 
 trait PostTrait
@@ -81,27 +82,64 @@ trait PostTrait
     }
 
     //获取内容最新评论
-    public function getNewComment($id)
+    public function getNewComment($id, $uid = 0)
     {
         $comment = [];
+        $key = 'comment_like_'.$id;
         $commentKey = 'post_new_comment_'.$id;
         $commentData = Redis::GET($commentKey);
         if($commentData){
             $comment = json_decode($commentData);
+            foreach($comment as &$item){
+                $isLike = 0;
+                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('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;
+                if($uid){
+                    $isLike = Redis::ZSCORE($key, $uid.'_'.$item->id) ? 1 : 0;
+                }
+                $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, 604800);
+            Redis::EXPIRE($commentKey, 300);
         }
         return $comment;
     }
+
+    //获取评论点赞数、点赞状态
+    public function getCommentLike($postId, $commentId, $uid = 0)
+    {
+        $key = 'comment_like_'.$postId;
+        $isLike = 0;
+        if($uid){
+            $isLike = Redis::ZSCORE($key, $uid.'_'.$commentId) ? 1 : 0;
+        }
+        $likeCount = Redis::ZCOUNT($key, $commentId, $commentId);
+        return [
+            'is_like' => $isLike,
+            'like_count' => $likeCount
+        ];
+    }
 }

+ 21 - 1
app/Transformers/Post/CommentTransformer.php

@@ -8,6 +8,7 @@
 namespace  App\Transformers\Post;
 
 use App\Models\PostComment;
+use App\Traits\PostTrait;
 use App\Traits\UserTrait;
 use Carbon\Carbon;
 use Illuminate\Support\Facades\Log;
@@ -17,6 +18,13 @@ use League\Fractal\TransformerAbstract;
 class CommentTransformer extends TransformerAbstract
 {
     use UserTrait;
+    use PostTrait;
+    public function __construct($postId, $uid)
+    {
+        $this->postId = $postId;
+        $this->uid = $uid;
+    }
+
     public function transform(PostComment $postComment)
     {
         $reply = [];
@@ -26,11 +34,15 @@ class CommentTransformer extends TransformerAbstract
             $reply = json_decode($replyData);
             foreach($reply as &$item){
                 $item->created_at = Carbon::parse($item->created_at)->diffForHumans();
+                $replyLike = $this->getCommentLike($this->postId, $item->id, $this->uid);
+                $item->is_like = $replyLike['is_like'];
+                $item->like_count = $replyLike['like_count'];
             }
         }else{
             $replies = PostComment::where('parent_id', $postComment['id'])->orderBy('id', 'desc')->limit(2)->get();
             $redisReply = [];
             foreach($replies as $val){
+                $replyLike = $this->getCommentLike($this->postId, $val->id, $this->uid);
                 $userComment = $this->userInfo($val->uid);
                 $replyUsername = '';
                 if($val->reply_uid){
@@ -38,6 +50,7 @@ class CommentTransformer extends TransformerAbstract
                     $replyUsername = $userReply['username'];
                 }
                 $reply[] = [
+                    'id' => $val->id,
                     'uid' => $val->uid,
                     'username' => $userComment['username'],
                     'avatar' => $userComment['avatar'],
@@ -45,8 +58,11 @@ class CommentTransformer extends TransformerAbstract
                     'content' => $val->is_delete?'该评论已被删除':$val->content,
                     'created_at' => Carbon::parse($val->created_at)->diffForHumans(),
                     'is_delete' => $val->is_delete,
+                    'is_like' => $replyLike['is_like'],
+                    'like_count' => $replyLike['like_count'],
                 ];
                 $redisReply[] = [
+                    'id' => $val->id,
                     'uid' => $val->uid,
                     'username' => $userComment['username'],
                     'avatar' => $userComment['avatar'],
@@ -54,12 +70,15 @@ class CommentTransformer extends TransformerAbstract
                     'content' => $val->is_delete?'该评论已被删除':$val->content,
                     'created_at' => $val->created_at,
                     'is_delete' => $val->is_delete,
+                    'is_like' => $replyLike['is_like'],
+                    'like_count' => $replyLike['like_count'],
                 ];
             }
             Redis::SET($replyKey, json_encode($redisReply));
             Redis::EXPIRE($replyKey, 604800);
         }
         $user = $this->userInfo($postComment['uid']);
+        $commentLike = $this->getCommentLike($this->postId, $postComment['id'], $this->uid);
         return [
             'id' => $postComment['id'],
             'uid' => $postComment['uid'],
@@ -69,8 +88,9 @@ class CommentTransformer extends TransformerAbstract
             'created_at' => Carbon::parse($postComment['created_at'])->diffForHumans(),
             'reply_count' => $postComment['reply_count'],
             'reply' => $reply,
-            'replys' => $reply,
             'is_delete' => $postComment['is_delete'],
+            'is_like' => $commentLike['is_like'],
+            'like_count' => $commentLike['like_count'],
         ];
     }
 }

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

@@ -40,6 +40,7 @@ class ListTransformer extends TransformerAbstract
             'title' => $post['title'],
             'content' => subtext($post['content'], 100),
             'img' => $post['img'],
+            'topic' => $this->getTopic($post['topic_ids']),
             'praise_count' => $postInfo['praise_count'],
             'is_like' => $isLike,
             'h5url' => config('customer.share_post_h5url')."?post_id={$post['id']}&invite_code={$this->invite_code}",

+ 11 - 0
app/Transformers/Post/ReplyTransformer.php

@@ -8,6 +8,7 @@
 namespace  App\Transformers\Post;
 
 use App\Models\PostComment;
+use App\Traits\PostTrait;
 use App\Traits\UserTrait;
 use Carbon\Carbon;
 use League\Fractal\TransformerAbstract;
@@ -15,6 +16,13 @@ use League\Fractal\TransformerAbstract;
 class ReplyTransformer extends TransformerAbstract
 {
     use UserTrait;
+    use PostTrait;
+    public function __construct($postId, $uid)
+    {
+        $this->postId = $postId;
+        $this->uid = $uid;
+    }
+
     public function transform(PostComment $postComment)
     {
         $user = $this->userInfo($postComment['uid']);
@@ -23,6 +31,7 @@ class ReplyTransformer extends TransformerAbstract
             $userReply = $this->userInfo($postComment['reply_uid']);
             $replyUsername = $userReply['username'];
         }
+        $commentLike = $this->getCommentLike($this->postId, $postComment['id'], $this->uid);
         return [
             'id' => $postComment['id'],
             'uid' => $postComment['uid'],
@@ -32,6 +41,8 @@ class ReplyTransformer extends TransformerAbstract
             'content' => $postComment['is_delete']?'该回复已被删除':$postComment['content'],
             'created_at' => Carbon::parse($postComment['created_at'])->diffForHumans(),
             'is_delete' => $postComment['is_delete'],
+            'is_like' => $commentLike['is_like'],
+            'like_count' => $commentLike['like_count'],
         ];
     }
 }

+ 1 - 1
app/Transformers/Post/SuggestTransformer.php

@@ -61,7 +61,7 @@ class SuggestTransformer extends TransformerAbstract
             'is_like' => $isLike,
             'is_dislike' => $isDislike,
             'is_collect' => $isCollect,
-            'comment' => $this->getNewComment($post['id']),
+            'comment' => $this->getNewComment($post['id'], $this->uid),
             'is_follow' => $this->getFollowStatus($this->uid, $post['uid']),
             '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']:'',

+ 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']:'',

+ 1 - 0
config/customer.tpl

@@ -10,4 +10,5 @@ return [
     'category_hot_img' => '{category_hot_img}',
     'category_my_img' => '{category_my_img}',
     'battle_activity_info' => '{battle_activity_info}',
+    'exchange_shop_is_show' => '{exchange_shop_is_show}',
 ];