behavior = $behavior; $this->commentRecord = $commentRecord; $this->generalRecord = $generalRecord; $this->registeredRecord = $registeredRecord; $this->releaseRecord = $releaseRecord; } private function _condition($model) { return $model->select(DB::raw('count(*) as count'),'generation_quantity','content_author_id','related_content_id') ->where('created_at', '>=', Carbon::now()->startOfDay()->toDateTimeString()) ->groupBy('generation_quantity','related_content_id','content_author_id') ->orderBy('generation_quantity','desc') ->limit(10) ->get(); } /** * Execute the console command. * * @return mixed */ public function handle() { $this->line("开始统计排行榜相关内容"); $time = Carbon::now()->startOfDay()->toDateTimeString(); //昨日拉新最多前十人 $registered_most = $this->registeredRecord ->where('created_at', '>=',$time) ->select(DB::raw('count(*) as count'),'superior_uid as content_author_id') ->groupBy('content_author_id')->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->commentRecord); $general_best_author = $general_author->toArray(); foreach ($general_best_author as $k=>$v){ $general_best_author[$k]['type'] = 'general'; } $release_author = $this->releaseRecord ->where('created_at', '>=', $time) ->select(DB::raw('count(*) as count'),'generation_quantity','uid as content_author_id','related_content_id') ->groupBy('generation_quantity','content_author_id','related_content_id')->orderBy('generation_quantity','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); $arr_sort = array(); foreach($all_best_author as $key => $value){ foreach($value as $k=>$v){ $arr_sort[$k][$key] = $v; } } array_multisort($arr_sort['generation_quantity'], 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', $registered_most); Redis::set('yesterday_best_author', $all_best_author); $this->line("统计昨日排行榜内容结束"); } }