duqinya лет назад: 5
Родитель
Сommit
d03175fde9

+ 121 - 0
app/Console/Commands/RankingList.php

@@ -0,0 +1,121 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: durong
+ * Date: 2019/6/20
+ * Time: 下午2:27
+ */
+namespace App\Console\Commands;
+
+
+use App\Models\Behavior;
+use App\Models\CommentRecord;
+use App\Models\GeneralRecord;
+use App\Models\RegisteredRecord;
+use App\Models\ReleaseRecord;
+use Illuminate\Console\Command;
+use Illuminate\Support\Carbon;
+use Illuminate\Support\Facades\DB;
+use Illuminate\Support\Facades\Log;
+use Illuminate\Support\Facades\Redis;
+
+class RankingList extends Command
+{
+    /**
+     * The name and signature of the console command.
+     *
+     * @var string
+     */
+    protected $signature = 'ranking:list';
+
+    /**
+     * The console command description.
+     *
+     * @var string
+     */
+    protected $description = '昨日排行榜统计';
+
+    /**
+     * Create a new command instance.
+     *
+     * @return void
+     */
+    public function __construct(Behavior $behavior, RegisteredRecord $registeredRecord,
+                                CommentRecord $commentRecord,
+                                GeneralRecord $generalRecord,
+                                ReleaseRecord $releaseRecord)
+    {
+        parent::__construct();
+        $this->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("统计昨日排行榜内容结束");
+    }
+}

+ 64 - 6
app/Http/Controllers/V1/BeanDetailController.php

@@ -1,6 +1,6 @@
 <?php
 namespace App\Http\Controllers\V1;
-use App\Repositories\MemberRepository;
+use App\Repositories\BeanRepository;
 use Illuminate\Http\Request;
 use Illuminate\Support\Facades\Validator;
 use Illuminate\Validation\Rule;
@@ -13,9 +13,9 @@ use Illuminate\Validation\Rule;
 
 class BeanDetailController extends Controller
 {
-    public function __construct(MemberRepository $memberRepository)
+    public function __construct(BeanRepository $beanRepository)
     {
-        $this->memberRepository = $memberRepository;
+        $this->beanRepository = $beanRepository;
     }
 
     //获取指定时间彩虹豆收支明细
@@ -28,7 +28,7 @@ class BeanDetailController extends Controller
             return $this->jsonError($validator->errors()->first());
         }
 
-        $beanDetail = $this->memberRepository->beanDetail($request->all());
+        $beanDetail = $this->beanRepository->beanDetail($request->all());
         if ($beanDetail){
             return $this->jsonSuccess($beanDetail);
         }else{
@@ -39,7 +39,65 @@ class BeanDetailController extends Controller
     //获取星球-用户彩虹豆相关信息
     public function getBean(Request $request)
     {
-        $user_bean = $this->memberRepository->getBean($request->all());
-        return jsonSuccess($user_bean);
+        $user_bean = $this->beanRepository->getBean($request->all());
+        if ($user_bean){
+            return $this->jsonSuccess($user_bean);
+        }else{
+            return $this->jsonError('没有找到星球彩虹豆信息');
+        }
+    }
+
+    //昨日优秀居民
+    public function excellentResidents(Request $request)
+    {
+        $excellent_residents = $this->beanRepository->excellentResidents($request->all());
+        if ($excellent_residents){
+            return $this->jsonSuccess($excellent_residents);
+        }else{
+            return $this->jsonError('没有找到昨日优秀居民相关信息');
+        }
+    }
+
+    //昨日拉新最多前十人
+    public function registeredMost(Request $request)
+    {
+        $registered_most = $this->beanRepository->registeredMost($request->all());
+        if ($registered_most){
+            return $this->jsonSuccess($registered_most);
+        }else{
+            return $this->jsonError('没有找到昨日拉新最多人相关信息');
+        }
+
+    }
+
+    //昨日文章产生彩虹豆最多前十人
+    public function bestAuthor(Request $request)
+    {
+        $best_author = $this->beanRepository->bestAuthor($request->all());
+        if ($best_author){
+            return $this->jsonSuccess($best_author);
+        }else{
+            return $this->jsonError('没有找到昨日最佳作者相关信息');
+        }
+
+    }
+
+    //获取关注关系列表
+    public function followDetail(Request $request)
+    {
+        $validator = Validator::make($request->all(), [
+            'content_author_id' => 'required',
+        ]);
+        if ($validator->fails()) {
+            return $this->jsonError($validator->errors()->first());
+        }
+
+        $follow_detail = $this->beanRepository->followDetail($request->all());
+        if ($follow_detail){
+            return $this->jsonSuccess($follow_detail);
+        }else{
+            return $this->jsonError('没有找到对应关注关系');
+        }
+
     }
 }

+ 30 - 5
app/Models/Behavior.php

@@ -1,20 +1,45 @@
 <?php
 /**
  * Created by PhpStorm.
- * User: wangzhiqiang
- * Date: 2019/4/24
- * Time: 15:21
+ * User: durong
+ * Date: 2019/6/10
+ * Time: 11:22
  */
 
 namespace App\Models;
-
 use Illuminate\Database\Eloquent\Model;
 
 class Behavior extends Model
 {
-    //
     protected $table = 'behavior';
     protected $guarded = [];
+    /**
+     * 可被批量赋值的字段
+     * @var array
+     */
+    protected $fillable =
+        ['virus_behavior_id','name','behavior_level','behavior_cycle_type','behavior_action_id','behavior_cycle','is_open','behavior_binding_users','physical_strength',
+        'rainbow_beans','remarks','behavioral_cycle_start_time','behavioral_cycle_end_time','allotted_quantity_rule','behavior_identification','relative_series','trigger_times',
+         'effective_trigger', 'absolute_progression','grant_rainbow_beans'
+        ];
+
+    public function RegisteredRecord()
+    {
+        return $this->hasMany('App\Models\RegisteredRecord','virus_behavior_id','virus_behavior_id');
+    }
+
+    public function CommentRecord()
+    {
+        return $this->hasMany('App\Models\CommentRecord','virus_behavior_id','virus_behavior_id');
+    }
 
+    public function ReleaseRecord()
+    {
+        return $this->hasMany('App\Models\ReleaseRecord','virus_behavior_id','virus_behavior_id');
+    }
 
+    public function GeneralRecord()
+    {
+        return $this->hasMany('App\Models\GeneralRecord','virus_behavior_id','virus_behavior_id');
+    }
 }

+ 0 - 20
app/Models/CommentAccountRecord.php

@@ -1,20 +0,0 @@
-<?php
-/**
- * Created by PhpStorm.
- * User: wangzhiqiang
- * Date: 2019/4/24
- * Time: 15:21
- */
-
-namespace App\Models;
-
-use Illuminate\Database\Eloquent\Model;
-
-class CommentAccountRecord extends Model
-{
-    //
-    protected $table = 'comment_account_record';
-    protected $guarded = [];
-
-
-}

+ 22 - 0
app/Models/CommentRecord.php

@@ -0,0 +1,22 @@
+<?php
+namespace App\Models;
+use Illuminate\Database\Eloquent\Model;
+
+/**
+ * Created by PhpStorm.
+ * User: durong
+ * Date: 2019/6/14
+ * Time: 下午6:01
+ */
+
+class CommentRecord extends Model
+{
+    //评论账本
+    protected $table = 'comment_account_record';
+    protected $guarded = [];
+
+    public function Behavior()
+    {
+        return $this->belongsTo('App\Models\Behavior','virus_behavior_id','virus_behavior_id');
+    }
+}

+ 23 - 0
app/Models/GeneralRecord.php

@@ -0,0 +1,23 @@
+<?php
+namespace App\Models;
+use Illuminate\Database\Eloquent\Model;
+
+/**
+ * Created by PhpStorm.
+ * User: durong
+ * Date: 2019/6/14
+ * Time: 上午11:25
+ */
+
+class GeneralRecord extends Model
+{
+    //分享、收藏等普通行为账本表
+    protected $table = 'general_ledger_record';
+    protected $guarded = [];
+
+    public function Behavior()
+    {
+        return $this->belongsTo('App\Models\Behavior','virus_behavior_id','virus_behavior_id');
+    }
+
+}

+ 23 - 0
app/Models/RegisteredRecord.php

@@ -0,0 +1,23 @@
+<?php
+namespace App\Models;
+use Illuminate\Database\Eloquent\Model;
+
+/**
+ * Created by PhpStorm.
+ * User: durong
+ * Date: 2019/6/14
+ * Time: 上午11:25
+ */
+
+class RegisteredRecord extends Model
+{
+    //新用户注册账本表
+    protected $table = 'registered_accounts_record';
+    protected $guarded = [];
+
+    public function Behavior()
+    {
+        return $this->belongsTo('App\Models\Behavior','virus_behavior_id','virus_behavior_id');
+    }
+
+}

+ 11 - 11
app/Models/ReleaseRecord.php

@@ -1,22 +1,22 @@
 <?php
+namespace App\Models;
+use Illuminate\Database\Eloquent\Model;
+
 /**
  * Created by PhpStorm.
- * User: wangzhiqiang
- * Date: 2019/4/24
- * Time: 15:21
+ * User: durong
+ * Date: 2019/6/14
+ * Time: 下午8:15
  */
 
-namespace App\Models;
-
-use Illuminate\Database\Eloquent\Model;
-use Illuminate\Database\Eloquent\SoftDeletes;
-
 class ReleaseRecord extends Model
 {
-    //
-    use SoftDeletes;
+    //发布账本
     protected $table = 'release_record';
     protected $guarded = [];
 
-
+    public function Behavior()
+    {
+        return $this->belongsTo('App\Models\Behavior','virus_behavior_id','virus_behavior_id');
+    }
 }

+ 57 - 3
app/Repositories/BeanRepository.php

@@ -1,8 +1,6 @@
 <?php
 namespace App\Repositories;
-
-
-use App\Service\RabbitMqUtil;
+use App\Models\Post;
 use Illuminate\Support\Facades\Log;
 use Tymon\JWTAuth\Facades\JWTAuth;
 use Illuminate\Support\Facades\Redis;
@@ -29,6 +27,62 @@ class BeanRepository
         $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);
+        //获取评论内容
+        $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);
+                    }
+                }
+            }
+        }
+        return $excellent_residents;
+    }
+
+    public function registeredMost($request)
+    {
+        $registered_most = Redis::get('yesterday_registered_most');
+
+        return $registered_most;
+
+    }
+
+    public function bestAuthor($request)
+    {
+        $all_best_author = Redis::get('yesterday_best_author');
+
+        return $all_best_author;
+
+    }
+
+   public function followDetail($request)
+    {
+        try {
+            $url = config("customer.app_service_url") . '/user/v2/member/getMemberIds';
+            $array = [
+                'json' => ['uids' => $request['content_author_id']], 'query' => [], 'http_errors' => false, 'headers' => ['Authorization' => "Bearer " . JWTAuth::getToken()]
+            ];
+            return http($url, $array, 'get');
+        } catch (\Exception $e) {
+            Log::debug("followDetail:".$e->getMessage());
+            return [];
+        }
+    }
 }

+ 7 - 0
routes/api.php

@@ -69,6 +69,13 @@ $api->version('v1', [
         $api->get('beanDetail', 'BeanDetailController@beanDetail');
         //用户彩虹豆信息获取
         $api->get('getBean', 'BeanDetailController@getBean');
+
+        //优秀居民信息获取
+        $api->get('excellentResidents', 'BeanDetailController@excellentResidents');
+        //排行榜拉新最多
+        $api->get('registeredMost', 'BeanDetailController@registeredMost');
+        //排行榜最佳作者
+        $api->get('bestAuthor', 'BeanDetailController@bestAuthor');
     });
 
 });