Bladeren bron

评论列表

wzq 5 jaren geleden
bovenliggende
commit
e3fc4bd99e

+ 4 - 0
app/Repositories/Post/PostRepository.php

@@ -241,6 +241,8 @@ class PostRepository
             'post_id' => $request['post_id'],
             'parent_id' => 0,
             'username' => $userInfo['username'],
+            'reply_uid' => 0,
+            'reply_username' => '',
             'avatar' => $userInfo['avatar'],
             'content' => $request['content'],
             'is_delete' => 0,
@@ -260,6 +262,8 @@ class PostRepository
                 ]);
             }
             $data['parent_id'] = $request['parent_id'];
+            $data['reply_uid'] = $comment->uid;
+            $data['reply_username'] = $comment->username;
         }
         DB::beginTransaction();
         try{

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

@@ -15,13 +15,20 @@ class CommentTransformer extends TransformerAbstract
 {
     public function transform(PostComment $postComment)
     {
+        if($postComment['is_delete']){
+            $content = '该评论已被删除';
+        }elseif($postComment['parent_id']){
+            $content = '回复 @'.subtext($postComment['reply_username'], 6).': '.$postComment['content'];
+        }else{
+            $content = $postComment['content'];
+        }
         return [
             'id' => $postComment['id'],
             'parent_id' => $postComment['parent_id'],
             'uid' => $postComment['uid'],
             'username' => $postComment['username'],
             'avatar' => $postComment['avatar'],
-            'content' => $postComment['is_delete'] == 1 ? '该评论已被删除' : $postComment['content'],
+            'content' => $content,
             'created_at' => Carbon::parse($postComment['created_at'])->toDateTimeString(),
             'is_delete' => $postComment['is_delete'],
         ];

+ 40 - 0
database/migrations/2019_06_14_092948_add_reply_uid_to_table_post_comment.php

@@ -0,0 +1,40 @@
+<?php
+
+use Illuminate\Support\Facades\Schema;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Database\Migrations\Migration;
+
+class AddReplyUidToTablePostComment extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::table('post_comment', function (Blueprint $table) {
+            $table->integer('reply_uid')
+                ->default(0)
+                ->after('username')
+                ->comment('回复对象uid');
+
+            $table->string('reply_username', 32)
+                ->default('')
+                ->after('reply_uid')
+                ->comment('回复对象昵称');
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::table('post_data', function (Blueprint $table) {
+            //
+        });
+    }
+}