post = $post; $this->postLike = $postLike; $this->postDislike = $postDislike; $this->postCollect = $postCollect; } /** * Execute the console command. * * @return mixed */ public function handle() { $this->line("开始更新内容用户状态"); $bar = $this->output->createProgressBar($this->post->withTrashed()->count()); $this->post->withTrashed()->chunk(100, function($posts) use ($bar){ foreach($posts as $post) { //点赞 $likeUid = $this->postLike->where('post_id', $post->id)->pluck('uid')->toArray(); if($likeUid){ $likeKey = 'post_like_'.$post->id; Redis::SADD($likeKey, $likeUid); } //不喜欢 $dislikeUid = $this->postDislike->where('post_id', $post->id)->pluck('uid')->toArray(); if($dislikeUid){ $unlikeKey = 'post_unlike_'.$post->id; Redis::SADD($unlikeKey, $dislikeUid); } //收藏 $collectUid = $this->postCollect->where('post_id', $post->id)->pluck('uid')->toArray(); if($collectUid){ $collectKey = 'post_collect_'.$post->id; Redis::SADD($collectKey, $collectUid); } $bar->advance(); } usleep(100000); }); $bar->finish(); $this->line("\n更新内容用户状态结束"); } }