$request['type']], config('customer.app_secret')); $url = config("customer.app_service_url") . '/user/v2/beanDetail'; $array = [ 'json' => ['sign' => $sign, 'type' => $request['type']], 'query' => [], 'http_errors' => false, 'headers' => ['Authorization' => "Bearer " . JWTAuth::getToken()] ]; return http($url, $array, 'get'); } catch (\Exception $e) { Log::debug("beanDetail:".$e->getMessage()); return []; } } public function getBean($request) { $user_bean = []; $user_bean['user_count'] = Redis::get('user_count');//已入驻居民 $user_bean['yesterday_add_user'] = Redis::get('yesterday_add_user');//昨日新增居民 $user_bean['yesterday_add_bean'] = Redis::get('yesterday_add_bean');//昨日发放彩虹豆 $user_bean['yesterday_quantity_issued'] = Redis::get('yesterday_quantity_issued');//昨日发放总彩虹豆 return $user_bean; } public function excellentResidents($request) { // $get_excellent = Redis::get('yesterday_excellent_residents'); // $excellent_residents = json_decode($get_excellent); //文章被评论最多用户 $comment = CommentRecord:: // where('created_at', '>=', $time) select(DB::raw('count(*) as count'), 'content_author_id', 'related_content_id') ->groupBy('related_content_id', 'content_author_id')->orderBy('count', 'desc')->limit(1)->get(); $comment = $comment->toArray(); foreach ($comment as $k=>$v){ $comment[$k]['type'] = 'comment';//类型 } //昨日拉新最多用户 $registered = RegisteredRecord:: // ->where('created_at', '>=', $time) select(DB::raw('count(*) as count'), 'superior_uid as content_author_id')//作为用户ID ->groupBy('superior_uid')->orderBy('count', 'desc')->limit(1)->get(); $registered = $registered->toArray(); foreach ($registered as $k=>$v){ $registered[$k]['type'] = 'registered'; } //文章被收藏最多用户 $virus_id = Behavior:: select('virus_behavior_id') ->where('behavior_identification', 'collect') ->first(); $collent = GeneralRecord:: where('virus_behavior_id', $virus_id->virus_behavior_id) // ->where('created_at', '>=', $time) ->select(DB::raw('count(*) as count'), 'content_author_id', 'related_content_id') ->groupBy('related_content_id', 'content_author_id')->orderBy('count', 'desc')->limit(1)->get(); $collent = $collent->toArray(); foreach ($collent as $k=>$v){ $collent[$k]['type'] = 'collent'; } //文章被喜欢最多用户 $virus_id = Behavior:: select('virus_behavior_id') ->where('behavior_identification', 'like') ->first(); $like = GeneralRecord:: where('virus_behavior_id', $virus_id->virus_behavior_id) // ->where('created_at', '>=', $time) ->select(DB::raw('count(*) as count'), 'content_author_id', 'related_content_id') ->groupBy('related_content_id', 'content_author_id')->orderBy('count', 'desc')->limit(1)->get(); $like = $like->toArray(); foreach ($like as $k=>$v){ $like[$k]['type'] = 'like'; } //文章被转发最多用户 $virus_id = Behavior:: select('virus_behavior_id') ->where('behavior_identification', 'forward') ->first(); $forward = GeneralRecord:: where('virus_behavior_id', $virus_id->virus_behavior_id) // ->where('created_at', '>=', $time) ->select(DB::raw('count(*) as count'), 'content_author_id', 'related_content_id') ->groupBy('related_content_id', 'content_author_id')->orderBy('count', 'desc')->limit(1)->get(); $forward = $forward->toArray(); foreach ($forward as $k=>$v){ $forward[$k]['type'] = 'forward'; } //文章被阅读最多用户 $virus_id = Behavior:: select('virus_behavior_id') ->where('behavior_identification', 'read') ->first(); $read = GeneralRecord:: where('virus_behavior_id', $virus_id->virus_behavior_id) // ->where('created_at', '>=', $time) ->select(DB::raw('count(*) as count'), 'content_author_id', 'related_content_id') ->groupBy('related_content_id', 'content_author_id')->orderBy('count', 'desc')->limit(1)->get(); $read = $read->toArray(); foreach ($read as $k=>$v){ $read[$k]['type'] = 'read'; } $excellent_residents = array_merge($comment, $registered, $collent, $like, $forward, $read); // $excellent_residents = json_encode($all_merge); //获取评论内容 $post_ids = array_column($excellent_residents,'related_content_id'); $comment_content = Post::select('id', 'title', 'content')->whereIn('id', $post_ids)->get(); foreach ($comment_content->toArray() as $value) { foreach ($excellent_residents as $k=>$v) { if (isset($v['related_content_id']) && $v['related_content_id'] == $value['id']) { if (!empty($value['title'])) { $excellent_residents[$k]['post_title'] = $value['title']; } if (empty($value['title']) && !empty($value['content'])){ $content = strip_tags($value['content']); $excellent_residents[$k]['post_title'] = mb_substr($content, 0, 20); } } } } $content_author_id = array_column($excellent_residents,'content_author_id'); $uids = implode(',', array_unique($content_author_id)); $author_data = $this->getFollowMembersStatus($uids); if ($author_data){ foreach ($excellent_residents as $k=>$v){ if(!isset($author_data[$v['content_author_id']])) continue; $excellent_residents[$k]['follow_status'] = $author_data[$v['content_author_id']]['follow_status']; $excellent_residents[$k]['username'] = $author_data[$v['content_author_id']]['username']; $excellent_residents[$k]['avatar'] = $author_data[$v['content_author_id']]['avatar']; } } return $excellent_residents; } public function rankingList($request) { $time = Carbon::now()->startOfDay()->toDateTimeString(); if ($request['type'] == 0){//排行榜赚豆达人 $all_bean = Redis::get('yesterday_all_bean'); $all_beans = json_decode($all_bean,true); }elseif ($request['type'] == 1){//排行榜人脉达人 // $registered_most = Redis::get('yesterday_registered_most'); // $registered_mosts = json_decode($registered_most,true); //昨日拉新最多前十人 $registered_most = RegisteredRecord:: // where('created_at', '>=',$time) select(DB::raw('count(*) as count'),'superior_uid') ->groupBy('superior_uid')->orderBy('count','desc')->limit(10)->get(); $registered_most = $registered_most->toArray(); $superior_uid = array_column($registered_most,'superior_uid'); $uids = implode(',', array_unique($superior_uid)); $user_data = $this->getFollowMembersStatus($uids); if ($user_data){ foreach ($registered_most as $k=>$v){ if(!isset($user_data[$v['superior_uid']])) continue; $registered_most[$k]['follow_status'] = $user_data[$v['superior_uid']]['follow_status']; $registered_most[$k]['username'] = $user_data[$v['superior_uid']]['username']; $registered_most[$k]['avatar'] = $user_data[$v['superior_uid']]['avatar']; } } return $registered_most; }else{//排行榜最佳作者 // $all_best_author = Redis::get('yesterday_best_author'); // $all_best_authors = json_decode($all_best_author,true); //昨日文章产生彩虹豆最多前十人 $comment_author = CommentRecord::select(DB::raw('count(*) as count'),'generation_quantity','content_author_id','related_content_id')->groupBy('generation_quantity','related_content_id','content_author_id') ->orderBy('generation_quantity','desc') ->limit(10) ->get();; $comment_best_author = $comment_author->toArray(); foreach ($comment_best_author as $k=>$v){ $comment_best_author[$k]['type'] = 'comment'; } $general_author = GeneralRecord::select(DB::raw('count(*) as count'),'generation_quantity','content_author_id','related_content_id')->groupBy('generation_quantity','related_content_id','content_author_id') ->orderBy('generation_quantity','desc') ->limit(10) ->get();;; $general_best_author = $general_author->toArray(); foreach ($general_best_author as $k=>$v){ $general_best_author[$k]['type'] = 'general'; } $release_author =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); $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); $content_author_id = array_column($all_best_author,'content_author_id'); $uids = implode(',', array_unique($content_author_id)); $user_data = $this->getFollowMembersStatus($uids); if ($user_data){ foreach ($all_best_author as $k=>$v){ if(!isset($user_data[$v['content_author_id']])) continue; $all_best_author[$k]['follow_status'] = $user_data[$v['content_author_id']]['follow_status']; $all_best_author[$k]['username'] = $user_data[$v['content_author_id']]['username']; $all_best_author[$k]['avatar'] = $user_data[$v['content_author_id']]['avatar']; } } return $all_best_author; } } function getFollowMembersStatus($uids) { try { $url = config("customer.app_service_url").'/user/v2/member/getMemberIds'; $array = [ 'json' => ['uids' => $uids], 'query' => [], 'http_errors' => false,'headers'=>['Authorization'=>"Bearer ".JWTAuth::getToken()] ]; return http($url,$array,'get'); } catch (\Exception $e) { Log::debug($e->getMessage()); return []; } } }