|
@@ -0,0 +1,169 @@
|
|
|
|
+<?php
|
|
|
|
+/**
|
|
|
|
+ * Created by PhpStorm.
|
|
|
|
+ * User: Administrator
|
|
|
|
+ * Date: 2019-06-21
|
|
|
|
+ * Time: 17:34
|
|
|
|
+ */
|
|
|
|
+
|
|
|
|
+namespace App\Repositories;
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+use App\Models\Behavior;
|
|
|
|
+use App\Models\CommentRecord;
|
|
|
|
+use App\Models\CommunityMemberStatistics;
|
|
|
|
+use App\Models\GeneralRecord;
|
|
|
|
+use App\Models\ReleaseRecord;
|
|
|
|
+use Illuminate\Support\Carbon;
|
|
|
|
+
|
|
|
|
+class CommunityMemberStatisticsRepository {
|
|
|
|
+ public function __construct(CommunityMemberStatistics $communityMemberStatistics,
|
|
|
|
+ CommentRecord $commentRecord,
|
|
|
|
+ GeneralRecord $generalRecord,
|
|
|
|
+ ReleaseRecord $releaseRecord,
|
|
|
|
+ Behavior $behavior) {
|
|
|
|
+ $this->communityMemberStatistics = $communityMemberStatistics;
|
|
|
|
+ $this->commentRecord = $commentRecord;
|
|
|
|
+ $this->generalRecord = $generalRecord;
|
|
|
|
+ $this->releaseRecord = $releaseRecord;
|
|
|
|
+ $this->behavior = $behavior;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //统计前一天数据
|
|
|
|
+ public function statistics() {
|
|
|
|
+ $yesterdayStart = Carbon::yesterday()->startOfDay()->toDateTimeString();
|
|
|
|
+ $yesterdayEnd = Carbon::yesterday()->endOfDay()->toDateTimeString();
|
|
|
|
+ $sData = [
|
|
|
|
+ 'post_count' => 0,
|
|
|
|
+ 'read_count' => 0,
|
|
|
|
+ 'share_count' => 0,
|
|
|
|
+ 'like_count' => 0,
|
|
|
|
+ 'unlike_count' => 0,
|
|
|
|
+ 'collect_count' => 0,
|
|
|
|
+ 'comment_count' => 0,
|
|
|
|
+ ];
|
|
|
|
+ $statisticsData = [];
|
|
|
|
+ //评论行为
|
|
|
|
+ $commentAccountRecord = $this->commentRecord
|
|
|
|
+ //->where([['created_at', '>=', $yesterdayStart], ['created_at', '<=', $yesterdayEnd]])
|
|
|
|
+ //->where('uid',617)
|
|
|
|
+ ->get();
|
|
|
|
+ //统计评论行为
|
|
|
|
+ if($commentAccountRecord){
|
|
|
|
+ $comment_count = [];
|
|
|
|
+ foreach ($commentAccountRecord as $k=>$v){
|
|
|
|
+ if(!isset($comment_count[$v['uid']])){
|
|
|
|
+ $comment_count[$v['uid']] = 0;
|
|
|
|
+ }
|
|
|
|
+ $statisticsData[$v['uid']] = $sData;
|
|
|
|
+ $statisticsData[$v['uid']]['comment_count'] = ++$comment_count[$v['uid']];
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ //行为 read阅读 like点赞 unlike不喜欢 forward分享 collect收藏
|
|
|
|
+ $statisticsData = $this->getBehavior($statisticsData,$sData);
|
|
|
|
+ //发布行为
|
|
|
|
+ $releaseRecordData = $this->releaseRecord
|
|
|
|
+ //->where([['created_at', '>=', $yesterdayStart], ['created_at', '<=', $yesterdayEnd]])
|
|
|
|
+ //->where('uid',90)
|
|
|
|
+ ->get();
|
|
|
|
+ if($releaseRecordData){
|
|
|
|
+ $post_count = [];
|
|
|
|
+ foreach ($releaseRecordData as $kk=>$vv){
|
|
|
|
+ if(!isset($post_count[$vv['uid']])){
|
|
|
|
+ $post_count[$vv['uid']] = 0;
|
|
|
|
+ }
|
|
|
|
+ if(empty($statisticsData[$vv['uid']])){
|
|
|
|
+ $statisticsData[$vv['uid']] = $sData;
|
|
|
|
+ }
|
|
|
|
+ $statisticsData[$vv['uid']]['post_count'] = ++$post_count[$vv['uid']];
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ //普通行为
|
|
|
|
+ public function getBehavior($statisticsData,$sData){
|
|
|
|
+ $yesterdayStart = Carbon::yesterday()->startOfDay()->toDateTimeString();
|
|
|
|
+ $yesterdayEnd = Carbon::yesterday()->endOfDay()->toDateTimeString();
|
|
|
|
+ //行为 read阅读 like点赞 unlike不喜欢 forward分享 collect收藏
|
|
|
|
+ $behavior = $this
|
|
|
|
+ ->behavior
|
|
|
|
+ ->whereIN('behavior_identification',['read','like','unlike','forward','collect'])
|
|
|
|
+ ->select('virus_behavior_id','behavior_identification')
|
|
|
|
+ ->get();
|
|
|
|
+ if($behavior){
|
|
|
|
+ foreach ($behavior as $key=>$value){
|
|
|
|
+ //普通行为
|
|
|
|
+ $generalLedgerRecord = $this->generalRecord
|
|
|
|
+ //->where([['created_at', '>=', $yesterdayStart], ['created_at', '<=', $yesterdayEnd]])
|
|
|
|
+ ->where('virus_behavior_id',$value['virus_behavior_id'])
|
|
|
|
+ ->get();
|
|
|
|
+ //阅读数
|
|
|
|
+ if($generalLedgerRecord){
|
|
|
|
+ if($value['behavior_identification'] == 'like'){
|
|
|
|
+ //喜欢数
|
|
|
|
+ $like_count = [];
|
|
|
|
+ foreach ($generalLedgerRecord as $kk=>$vv){
|
|
|
|
+ if(!isset($like_count[$vv['uid']])){
|
|
|
|
+ $like_count[$vv['uid']] = 0;
|
|
|
|
+ }
|
|
|
|
+ if(empty($statisticsData[$vv['uid']])){
|
|
|
|
+ $statisticsData[$vv['uid']] = $sData;
|
|
|
|
+ }
|
|
|
|
+ $statisticsData[$vv['uid']]['like_count'] = ++$like_count[$vv['uid']];
|
|
|
|
+ }
|
|
|
|
+ }elseif ($value['behavior_identification'] == 'read'){
|
|
|
|
+ //阅读数
|
|
|
|
+ $read_count = [];
|
|
|
|
+ foreach ($generalLedgerRecord as $kk=>$vv){
|
|
|
|
+ if(!isset($read_count[$vv['uid']])){
|
|
|
|
+ $read_count[$vv['uid']] = 0;
|
|
|
|
+ }
|
|
|
|
+ if(empty($statisticsData[$vv['uid']])){
|
|
|
|
+ $statisticsData[$vv['uid']] = $sData;
|
|
|
|
+ }
|
|
|
|
+ $statisticsData[$vv['uid']]['read_count'] = ++$read_count[$vv['uid']];
|
|
|
|
+ }
|
|
|
|
+ }elseif ($value['behavior_identification'] == 'unlike'){
|
|
|
|
+ //不喜欢
|
|
|
|
+ $unlike_count = [];
|
|
|
|
+ foreach ($generalLedgerRecord as $kk=>$vv){
|
|
|
|
+ if(!isset($unlike_count[$vv['uid']])){
|
|
|
|
+ $unlike_count[$vv['uid']] = 0;
|
|
|
|
+ }
|
|
|
|
+ if(empty($statisticsData[$vv['uid']])){
|
|
|
|
+ $statisticsData[$vv['uid']] = $sData;
|
|
|
|
+ }
|
|
|
|
+ $statisticsData[$vv['uid']]['unlike_count'] = ++$unlike_count[$vv['uid']];
|
|
|
|
+ }
|
|
|
|
+ }elseif ($value['behavior_identification'] == 'forward'){
|
|
|
|
+ //分享
|
|
|
|
+ $share_count = [];
|
|
|
|
+ foreach ($generalLedgerRecord as $kk=>$vv){
|
|
|
|
+ if(!isset($share_count[$vv['uid']])){
|
|
|
|
+ $share_count[$vv['uid']] = 0;
|
|
|
|
+ }
|
|
|
|
+ if(empty($statisticsData[$vv['uid']])){
|
|
|
|
+ $statisticsData[$vv['uid']] = $sData;
|
|
|
|
+ }
|
|
|
|
+ $statisticsData[$vv['uid']]['share_count'] = ++$share_count[$vv['uid']];
|
|
|
|
+ }
|
|
|
|
+ }elseif ($value['behavior_identification'] == 'collect'){
|
|
|
|
+ //收藏
|
|
|
|
+ $collect_count = [];
|
|
|
|
+ foreach ($generalLedgerRecord as $kk=>$vv){
|
|
|
|
+ if(!isset($collect_count[$vv['uid']])){
|
|
|
|
+ $collect_count[$vv['uid']] = 0;
|
|
|
|
+ }
|
|
|
|
+ if(empty($statisticsData[$vv['uid']])){
|
|
|
|
+ $statisticsData[$vv['uid']] = $sData;
|
|
|
|
+ }
|
|
|
|
+ $statisticsData[$vv['uid']]['collect_count'] = ++$collect_count[$vv['uid']];
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return $statisticsData;
|
|
|
|
+ }
|
|
|
|
+}
|