Browse Source

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

xielin 5 years ago
parent
commit
3b6964362e

+ 62 - 0
app/Console/Commands/DelPostNewReply.php

@@ -0,0 +1,62 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: Administrator
+ * Date: 2019/8/13
+ * Time: 10:59
+ */
+namespace App\Console\Commands;
+
+
+use App\Models\PostComment;
+use Illuminate\Console\Command;
+use Illuminate\Support\Facades\Redis;
+
+class DelPostNewReply extends Command
+{
+    /**
+     * The name and signature of the console command.
+     *
+     * @var string
+     */
+    protected $signature = 'post:del_post_new_reply';
+
+    /**
+     * The console command description.
+     *
+     * @var string
+     */
+    protected $description = '删除内容新回复缓存';
+
+    /**
+     * Create a new command instance.
+     *
+     * @return void
+     */
+    public function __construct(PostComment $postComment)
+    {
+        parent::__construct();
+        $this->postComment = $postComment;
+    }
+
+    /**
+     * Execute the console command.
+     *
+     * @return mixed
+     */
+    public function handle()
+    {
+        $this->line("开始删除内容新回复缓存");
+
+        $max = $this->postComment->max('id');
+        $bar = $this->output->createProgressBar($max);
+        for($i=1;$i<=$max;$i++){
+            Redis::DEL('post_new_reply_'.$i);
+            $bar->advance();
+            usleep(10000);
+        }
+        $bar->finish();
+        $this->line("\n删除内容新回复缓存结束");
+
+    }
+}

+ 2 - 0
app/Console/Kernel.php

@@ -7,6 +7,7 @@ use App\Console\Commands\BehaviorRecord;
 use App\Console\Commands\CalcPostWeight;
 use App\Console\Commands\ContentFeedCreate;
 use App\Console\Commands\ContentFeedDelete;
+use App\Console\Commands\DelPostNewReply;
 use App\Console\Commands\ExcellentResidents;
 use App\Console\Commands\RankingList;
 use Illuminate\Console\Scheduling\Schedule;
@@ -26,6 +27,7 @@ class Kernel extends ConsoleKernel
         ContentFeedCreate::class,
         ContentFeedDelete::class,
         ExcellentResidents::class,
+        DelPostNewReply::class,
         RankingList::class
     ];
 

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

@@ -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'],
         ];
     }