post = $post; $this->memberFollowTopic = $memberFollowTopic; $this->topic = $topic; } /** * Execute the console command. * * @return mixed */ public function handle() { $this->line("开始更新话题数据"); $bar = $this->output->createProgressBar($this->topic->count()); $this->topic->chunk(10, function($topics) use ($bar){ foreach($topics as $topic) { $topic->follow_count = $this->memberFollowTopic->where('topic_id', $topic->id)->count(); $topic->pv = $this->post->withTrashed() ->join('post_data', 'post_data.post_id', '=', 'post.id') ->select('post_data.pv') ->whereRaw('FIND_IN_SET('.$topic->id.', topic_ids)') ->sum('pv'); $topic->save(); $bar->advance(); } usleep(100000); }); $bar->finish(); $this->line("\n更新话题数据结束"); } }