|
@@ -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){
|
|
@@ -45,6 +57,8 @@ 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[] = [
|
|
|
'uid' => $val->uid,
|
|
@@ -54,12 +68,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'],
|
|
@@ -71,6 +88,8 @@ class CommentTransformer extends TransformerAbstract
|
|
|
'reply' => $reply,
|
|
|
'replys' => $reply,
|
|
|
'is_delete' => $postComment['is_delete'],
|
|
|
+ 'is_like' => $commentLike['is_like'],
|
|
|
+ 'like_count' => $commentLike['like_count'],
|
|
|
];
|
|
|
}
|
|
|
}
|