|
@@ -1,6 +1,11 @@
|
|
|
<?php
|
|
|
namespace App\Repositories;
|
|
|
+use App\Models\Behavior;
|
|
|
+use App\Models\CommentRecord;
|
|
|
+use App\Models\GeneralRecord;
|
|
|
use App\Models\Post;
|
|
|
+use App\Models\RegisteredRecord;
|
|
|
+use Illuminate\Support\Facades\DB;
|
|
|
use Illuminate\Support\Facades\Log;
|
|
|
use Tymon\JWTAuth\Facades\JWTAuth;
|
|
|
use Illuminate\Support\Facades\Redis;
|
|
@@ -24,18 +29,101 @@ class BeanRepository
|
|
|
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');
|
|
|
+ $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);
|
|
|
+// $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();
|
|
@@ -53,6 +141,21 @@ class BeanRepository
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ $user_ids = array_column($excellent_residents,'content_author_id');
|
|
|
+ $request['content_author_id'] = array_unique($user_ids);
|
|
|
+ $author_data = $this->followDetail($request);
|
|
|
+ if (count($author_data)>0){
|
|
|
+ foreach ($author_data as $key=>$val){
|
|
|
+ foreach ($excellent_residents as $k=>$v){
|
|
|
+ if (isset($key) && $key == $v['content_author_id']){
|
|
|
+ $excellent_residents[$k]['follow_status'] = $v['follow_status'];
|
|
|
+ $excellent_residents[$k]['username'] = $v['username'];
|
|
|
+ $excellent_residents[$k]['avatar'] = $v['avatar'];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
return $excellent_residents;
|
|
|
}
|
|
|
|
|
@@ -72,7 +175,7 @@ class BeanRepository
|
|
|
|
|
|
}
|
|
|
|
|
|
- public function followDetail($request)
|
|
|
+ function followDetail($request)
|
|
|
{
|
|
|
try {
|
|
|
$url = config("customer.app_service_url") . '/user/v2/member/getMemberIds';
|