|
@@ -15,6 +15,9 @@ use App\Models\CommunityMemberStatistics;
|
|
|
use App\Models\GeneralRecord;
|
|
|
use App\Models\ReleaseRecord;
|
|
|
use Illuminate\Support\Carbon;
|
|
|
+use Illuminate\Support\Facades\DB;
|
|
|
+use Illuminate\Database\QueryException;
|
|
|
+use Illuminate\Support\Facades\Log;
|
|
|
|
|
|
class CommunityMemberStatisticsRepository {
|
|
|
public function __construct(CommunityMemberStatistics $communityMemberStatistics,
|
|
@@ -42,11 +45,11 @@ class CommunityMemberStatisticsRepository {
|
|
|
'collect_count' => 0,
|
|
|
'comment_count' => 0,
|
|
|
];
|
|
|
+ Log::debug('统计用户行为开始');
|
|
|
$statisticsData = [];
|
|
|
//评论行为
|
|
|
$commentAccountRecord = $this->commentRecord
|
|
|
- //->where([['created_at', '>=', $yesterdayStart], ['created_at', '<=', $yesterdayEnd]])
|
|
|
- //->where('uid',617)
|
|
|
+ ->where([['created_at', '>=', $yesterdayStart], ['created_at', '<=', $yesterdayEnd]])
|
|
|
->get();
|
|
|
//统计评论行为
|
|
|
if($commentAccountRecord){
|
|
@@ -64,8 +67,7 @@ class CommunityMemberStatisticsRepository {
|
|
|
$statisticsData = $this->getBehavior($statisticsData,$sData);
|
|
|
//发布行为
|
|
|
$releaseRecordData = $this->releaseRecord
|
|
|
- //->where([['created_at', '>=', $yesterdayStart], ['created_at', '<=', $yesterdayEnd]])
|
|
|
- //->where('uid',90)
|
|
|
+ ->where([['created_at', '>=', $yesterdayStart], ['created_at', '<=', $yesterdayEnd]])
|
|
|
->get();
|
|
|
if($releaseRecordData){
|
|
|
$post_count = [];
|
|
@@ -79,6 +81,38 @@ class CommunityMemberStatisticsRepository {
|
|
|
$statisticsData[$vv['uid']]['post_count'] = ++$post_count[$vv['uid']];
|
|
|
}
|
|
|
}
|
|
|
+ //得到数据查询是否有,有修改,没有添加
|
|
|
+ if(!empty($statisticsData)){
|
|
|
+ DB::beginTransaction();
|
|
|
+ Log::info('统计用户行为内容'.json_encode($statisticsData));
|
|
|
+ try{
|
|
|
+ foreach ($statisticsData as $key => $value){
|
|
|
+ $statisticsInfo = $this->communityMemberStatistics->where('uid',$key)->first();
|
|
|
+ if($statisticsInfo){
|
|
|
+ $upData = [
|
|
|
+ 'post_count' => ($statisticsInfo->post_count+$value['post_count']),
|
|
|
+ 'read_count' => ($statisticsInfo->read_count+$value['read_count']),
|
|
|
+ 'share_count' => ($statisticsInfo->share_count+$value['share_count']),
|
|
|
+ 'like_count' => ($statisticsInfo->like_count+$value['like_count']),
|
|
|
+ 'unlike_count' => ($statisticsInfo->unlike_count+$value['unlike_count']),
|
|
|
+ 'collect_count' => ($statisticsInfo->collect_count+$value['collect_count']),
|
|
|
+ 'comment_count' => ($statisticsInfo->comment_count+$value['comment_count']),
|
|
|
+ ];
|
|
|
+ $this->communityMemberStatistics
|
|
|
+ ->where('id',$statisticsInfo->id)
|
|
|
+ ->update($upData);
|
|
|
+ }else{
|
|
|
+ $value['uid'] = $key;
|
|
|
+ $this->communityMemberStatistics->create($value);
|
|
|
+ }
|
|
|
+ DB::commit();
|
|
|
+ }
|
|
|
+ }catch (QueryException $exception){
|
|
|
+ DB::rollBack();
|
|
|
+ Log::debug('统计用户行为出错:'.$exception->getMessage());
|
|
|
+ }
|
|
|
+ Log::debug('统计用户行为结束');
|
|
|
+ }
|
|
|
}
|
|
|
//普通行为
|
|
|
public function getBehavior($statisticsData,$sData){
|
|
@@ -94,7 +128,7 @@ class CommunityMemberStatisticsRepository {
|
|
|
foreach ($behavior as $key=>$value){
|
|
|
//普通行为
|
|
|
$generalLedgerRecord = $this->generalRecord
|
|
|
- //->where([['created_at', '>=', $yesterdayStart], ['created_at', '<=', $yesterdayEnd]])
|
|
|
+ ->where([['created_at', '>=', $yesterdayStart], ['created_at', '<=', $yesterdayEnd]])
|
|
|
->where('virus_behavior_id',$value['virus_behavior_id'])
|
|
|
->get();
|
|
|
//阅读数
|
|
@@ -166,4 +200,8 @@ class CommunityMemberStatisticsRepository {
|
|
|
}
|
|
|
return $statisticsData;
|
|
|
}
|
|
|
+ //用户详情
|
|
|
+ public function view($uid){
|
|
|
+ return $this->communityMemberStatistics->where('uid',$uid)->first();
|
|
|
+ }
|
|
|
}
|