behavior = $behavior; $this->commentRecord = $commentRecord; $this->generalRecord = $generalRecord; $this->registeredRecord = $registeredRecord; $this->releaseRecord = $releaseRecord; } private function _condition($model) { $yesterday_start = Carbon::now()->addDays(-1)->startOfDay()->toDateTimeString(); $yesterday_end = Carbon::now()->addDays(-1)->endOfDay()->toDateTimeString(); return $model->select(DB::raw('count(*) as num'), 'generation_quantity', 'content_author_id', DB::raw('sum(generation_quantity) as count')) ->whereBetween('created_at', [$yesterday_start, $yesterday_end]) ->groupBy('generation_quantity', 'content_author_id') ->orderBy('count', 'desc') ->limit(10) ->get(); } /** * Execute the console command. * * @return mixed */ public function handle() { $this->line("开始统计排行榜相关内容"); $yesterday_start = Carbon::now()->addDays(-1)->startOfDay()->toDateTimeString(); $yesterday_end = Carbon::now()->addDays(-1)->endOfDay()->toDateTimeString(); //昨日拉新最多前十人 $registered_most = $this->registeredRecord ->whereBetween('created_at', [$yesterday_start, $yesterday_end]) ->select(DB::raw('count(*) as count'), 'superior_uid') ->groupBy('superior_uid')->orderBy('count', 'desc')->limit(10)->get(); $registered_most = $registered_most->toArray(); //昨日文章产生彩虹豆最多前十人 $comment_author = $this->_condition($this->commentRecord); $comment_best_author = $comment_author->toArray(); foreach ($comment_best_author as $k => $v) { $comment_best_author[$k]['type'] = 'comment'; } $general_author = $this->_condition($this->generalRecord); $general_best_author = $general_author->toArray(); foreach ($general_best_author as $k => $v) { $general_best_author[$k]['type'] = 'general'; } $release_author = $this->releaseRecord ->whereBetween('created_at', [$yesterday_start, $yesterday_end]) ->select(DB::raw('count(*) as num'), 'generation_quantity', 'uid as content_author_id', DB::raw('sum(generation_quantity) as count')) ->groupBy('generation_quantity', 'content_author_id')->orderBy('count', 'desc')->limit(10)->get(); $release_best_author = $release_author->toArray(); foreach ($release_best_author as $k => $v) { $release_best_author[$k]['type'] = 'release'; } $all_best_author = array_merge($comment_best_author, $general_best_author, $release_best_author); $column = array_column($all_best_author, 'generation_quantity'); array_multisort($column, SORT_DESC, $all_best_author); $all_best_author = array_slice($all_best_author, 0, 10); Log::debug('昨日拉新最多前十人' . json_encode($registered_most)); Log::debug('昨日文章产生彩虹豆最多前十人' . json_encode($all_best_author)); Redis::set('yesterday_registered_most', json_encode($registered_most)); Redis::set('yesterday_best_author', json_encode($all_best_author)); $this->line("统计昨日排行榜内容结束"); } }