|
@@ -6,15 +6,14 @@ use App\Module\AppGame\Handler\BaseHandler;
|
|
|
use App\Module\UrsPromotion\Services\UrsUserMappingService;
|
|
use App\Module\UrsPromotion\Services\UrsUserMappingService;
|
|
|
use App\Module\UrsPromotion\Services\UrsReferralService;
|
|
use App\Module\UrsPromotion\Services\UrsReferralService;
|
|
|
use App\Module\UrsPromotion\Services\UrsTalentService;
|
|
use App\Module\UrsPromotion\Services\UrsTalentService;
|
|
|
|
|
+use App\Module\UrsPromotion\Models\UrsUserRelationCache;
|
|
|
use App\Module\User\Services\UserActivityService;
|
|
use App\Module\User\Services\UserActivityService;
|
|
|
|
|
+use App\Module\User\Models\UserInfo;
|
|
|
use App\Module\Fund\Enums\FUND_TYPE;
|
|
use App\Module\Fund\Enums\FUND_TYPE;
|
|
|
use App\Module\Game\Enums\REWARD_SOURCE_TYPE;
|
|
use App\Module\Game\Enums\REWARD_SOURCE_TYPE;
|
|
|
-use App\Module\Game\Models\GameRewardLog;
|
|
|
|
|
use App\Module\Fund\Models\FundLogModel;
|
|
use App\Module\Fund\Models\FundLogModel;
|
|
|
-use App\Module\GameItems\Models\ItemTransactionLog;
|
|
|
|
|
use Google\Protobuf\Internal\Message;
|
|
use Google\Protobuf\Internal\Message;
|
|
|
use Illuminate\Support\Facades\Log;
|
|
use Illuminate\Support\Facades\Log;
|
|
|
-use Illuminate\Support\Facades\DB;
|
|
|
|
|
use Uraus\Kku\Request\RequestPromotionInfo;
|
|
use Uraus\Kku\Request\RequestPromotionInfo;
|
|
|
use Uraus\Kku\Response\ResponsePromotionInfo;
|
|
use Uraus\Kku\Response\ResponsePromotionInfo;
|
|
|
use Uraus\Kku\Common\Reward;
|
|
use Uraus\Kku\Common\Reward;
|
|
@@ -185,46 +184,31 @@ class InfoHandler extends BaseHandler
|
|
|
private function getTodayStats(int $ursUserId): array
|
|
private function getTodayStats(int $ursUserId): array
|
|
|
{
|
|
{
|
|
|
try {
|
|
try {
|
|
|
- $teamMembers = UrsReferralService::getTeamMembers($ursUserId);
|
|
|
|
|
-
|
|
|
|
|
- $directNewCount = 0;
|
|
|
|
|
- $teamNewCount = 0;
|
|
|
|
|
-
|
|
|
|
|
- // 统计今日新增的直推用户
|
|
|
|
|
- if (!empty($teamMembers[1])) {
|
|
|
|
|
- foreach ($teamMembers[1] as $directMember) {
|
|
|
|
|
- $farmUserId = UrsUserMappingService::getFarmUserId($directMember);
|
|
|
|
|
- if ($farmUserId) {
|
|
|
|
|
- // 检查用户映射创建时间是否为今日
|
|
|
|
|
- $mapping = UrsUserMappingService::getMappingDetail($directMember);
|
|
|
|
|
- if ($mapping && $mapping->mappingTime &&
|
|
|
|
|
- Carbon::parse($mapping->mappingTime)->isToday()) {
|
|
|
|
|
- $directNewCount++;
|
|
|
|
|
- $teamNewCount++;
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ // 获取当前用户的农场用户ID
|
|
|
|
|
+ $farmUserId = UrsUserMappingService::getFarmUserId($ursUserId);
|
|
|
|
|
+ if (!$farmUserId) {
|
|
|
|
|
+ return [
|
|
|
|
|
+ 'direct_new_count' => 0,
|
|
|
|
|
+ 'team_new_count' => 0
|
|
|
|
|
+ ];
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // 统计今日新增的间推和三推用户
|
|
|
|
|
- foreach ([ 2, 3 ] as $level) {
|
|
|
|
|
- if (!empty($teamMembers[$level])) {
|
|
|
|
|
- foreach ($teamMembers[$level] as $member) {
|
|
|
|
|
- $farmUserId = UrsUserMappingService::getFarmUserId($member);
|
|
|
|
|
- if ($farmUserId) {
|
|
|
|
|
- $mapping = UrsUserMappingService::getMappingDetail($member);
|
|
|
|
|
- if ($mapping && $mapping->mappingTime &&
|
|
|
|
|
- Carbon::parse($mapping->mappingTime)->isToday()) {
|
|
|
|
|
- $teamNewCount++;
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ // 使用 UrsUserRelationCache 查询今日新增的关系记录
|
|
|
|
|
+ // 查询今日创建的关系缓存记录,按层级统计
|
|
|
|
|
+ $todayRelations = UrsUserRelationCache::where('related_user_id', $farmUserId)
|
|
|
|
|
+ ->whereDate('created_at', today())
|
|
|
|
|
+ ->selectRaw('
|
|
|
|
|
+ COUNT(CASE WHEN depth = 1 THEN 1 END) as direct_new_count,
|
|
|
|
|
+ COUNT(CASE WHEN depth <= 3 THEN 1 END) as team_new_count
|
|
|
|
|
+ ')
|
|
|
|
|
+ ->first();
|
|
|
|
|
+
|
|
|
|
|
+ $directNewCount = $todayRelations->direct_new_count ?? 0;
|
|
|
|
|
+ $teamNewCount = $todayRelations->team_new_count ?? 0;
|
|
|
|
|
|
|
|
return [
|
|
return [
|
|
|
- 'direct_new_count' => $directNewCount,
|
|
|
|
|
- 'team_new_count' => $teamNewCount
|
|
|
|
|
|
|
+ 'direct_new_count' => (int)$directNewCount,
|
|
|
|
|
+ 'team_new_count' => (int)$teamNewCount
|
|
|
];
|
|
];
|
|
|
|
|
|
|
|
} catch (\Exception $e) {
|
|
} catch (\Exception $e) {
|
|
@@ -249,44 +233,35 @@ class InfoHandler extends BaseHandler
|
|
|
private function getActiveStats(int $ursUserId): array
|
|
private function getActiveStats(int $ursUserId): array
|
|
|
{
|
|
{
|
|
|
try {
|
|
try {
|
|
|
- $teamMembers = UrsReferralService::getTeamMembers($ursUserId);
|
|
|
|
|
- $activeThreshold = Carbon::now()->subHours(24); // 24小时内活跃
|
|
|
|
|
-
|
|
|
|
|
- $directActiveCount = 0;
|
|
|
|
|
- $teamActiveCount = 0;
|
|
|
|
|
-
|
|
|
|
|
- // 统计直推活跃用户
|
|
|
|
|
- if (!empty($teamMembers[1])) {
|
|
|
|
|
- foreach ($teamMembers[1] as $directMember) {
|
|
|
|
|
- $farmUserId = UrsUserMappingService::getFarmUserId($directMember);
|
|
|
|
|
- if ($farmUserId) {
|
|
|
|
|
- $lastActivity = UserActivityService::getLastActivityTime($farmUserId);
|
|
|
|
|
- if ($lastActivity && $lastActivity->gt($activeThreshold)) {
|
|
|
|
|
- $directActiveCount++;
|
|
|
|
|
- $teamActiveCount++;
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ // 获取当前用户的农场用户ID
|
|
|
|
|
+ $farmUserId = UrsUserMappingService::getFarmUserId($ursUserId);
|
|
|
|
|
+ if (!$farmUserId) {
|
|
|
|
|
+ return [
|
|
|
|
|
+ 'direct_active_count' => 0,
|
|
|
|
|
+ 'team_active_count' => 0
|
|
|
|
|
+ ];
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // 统计间推和三推活跃用户
|
|
|
|
|
- foreach ([ 2, 3 ] as $level) {
|
|
|
|
|
- if (!empty($teamMembers[$level])) {
|
|
|
|
|
- foreach ($teamMembers[$level] as $member) {
|
|
|
|
|
- $farmUserId = UrsUserMappingService::getFarmUserId($member);
|
|
|
|
|
- if ($farmUserId) {
|
|
|
|
|
- $lastActivity = UserActivityService::getLastActivityTime($farmUserId);
|
|
|
|
|
- if ($lastActivity && $lastActivity->gt($activeThreshold)) {
|
|
|
|
|
- $teamActiveCount++;
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ $activeThreshold = Carbon::now()->subHours(24); // 24小时内活跃
|
|
|
|
|
+
|
|
|
|
|
+ // 使用 UrsUserRelationCache 和 UserInfo 进行 JOIN 查询
|
|
|
|
|
+ // 一次性获取所有团队成员的活跃状态
|
|
|
|
|
+ $activeStats = UrsUserRelationCache::where('related_user_id', $farmUserId)
|
|
|
|
|
+ ->where('depth', '<=', 3) // 只统计前3级
|
|
|
|
|
+ ->join('kku_user_infos', 'kku_urs_promotion_user_relation_cache.user_id', '=', 'kku_user_infos.user_id')
|
|
|
|
|
+ ->where('kku_user_infos.last_activity_time', '>=', $activeThreshold)
|
|
|
|
|
+ ->selectRaw('
|
|
|
|
|
+ COUNT(CASE WHEN depth = 1 THEN 1 END) as direct_active_count,
|
|
|
|
|
+ COUNT(*) as team_active_count
|
|
|
|
|
+ ')
|
|
|
|
|
+ ->first();
|
|
|
|
|
+
|
|
|
|
|
+ $directActiveCount = $activeStats->direct_active_count ?? 0;
|
|
|
|
|
+ $teamActiveCount = $activeStats->team_active_count ?? 0;
|
|
|
|
|
|
|
|
return [
|
|
return [
|
|
|
- 'direct_active_count' => $directActiveCount,
|
|
|
|
|
- 'team_active_count' => $teamActiveCount
|
|
|
|
|
|
|
+ 'direct_active_count' => (int)$directActiveCount,
|
|
|
|
|
+ 'team_active_count' => (int)$teamActiveCount
|
|
|
];
|
|
];
|
|
|
|
|
|
|
|
} catch (\Exception $e) {
|
|
} catch (\Exception $e) {
|