|
@@ -10,6 +10,7 @@ namespace App\Transformers\Post;
|
|
|
use App\Models\PostComment;
|
|
|
use App\Traits\UserTrait;
|
|
|
use Carbon\Carbon;
|
|
|
+use Illuminate\Support\Facades\Log;
|
|
|
use Illuminate\Support\Facades\Redis;
|
|
|
use League\Fractal\TransformerAbstract;
|
|
|
|
|
@@ -23,8 +24,12 @@ class CommentTransformer extends TransformerAbstract
|
|
|
$replyData = Redis::GET($replyKey);
|
|
|
if($replyData){
|
|
|
$reply = json_decode($replyData);
|
|
|
+ foreach($reply as &$item){
|
|
|
+ $item->created_at = Carbon::parse($item->created_at)->diffForHumans();
|
|
|
+ }
|
|
|
}else{
|
|
|
$replies = PostComment::where('parent_id', $postComment['id'])->orderBy('id', 'desc')->limit(2)->get();
|
|
|
+ $redisReply = [];
|
|
|
foreach($replies as $val){
|
|
|
$userComment = $this->userInfo($val->uid);
|
|
|
$replyUsername = '';
|
|
@@ -41,8 +46,17 @@ class CommentTransformer extends TransformerAbstract
|
|
|
'created_at' => Carbon::parse($val->created_at)->diffForHumans(),
|
|
|
'is_delete' => $val->is_delete,
|
|
|
];
|
|
|
+ $redisReply[] = [
|
|
|
+ 'uid' => $val->uid,
|
|
|
+ 'username' => $userComment['username'],
|
|
|
+ 'avatar' => $userComment['avatar'],
|
|
|
+ 'reply_username' => $replyUsername,
|
|
|
+ 'content' => $val->is_delete?'该评论已被删除':$val->content,
|
|
|
+ 'created_at' => $val->created_at,
|
|
|
+ 'is_delete' => $val->is_delete,
|
|
|
+ ];
|
|
|
}
|
|
|
- Redis::SET($replyKey, json_encode($reply));
|
|
|
+ Redis::SET($replyKey, json_encode($redisReply));
|
|
|
Redis::EXPIRE($replyKey, 604800);
|
|
|
}
|
|
|
$user = $this->userInfo($postComment['uid']);
|
|
@@ -55,6 +69,7 @@ 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'],
|
|
|
];
|
|
|
}
|