fix: statisc

This commit is contained in:
hashbro
2026-08-10 03:53:10 +08:00
parent ad30453922
commit aad44bf52e
33 changed files with 1207 additions and 28 deletions
+35
View File
@@ -60,4 +60,39 @@ final class AgentScope
return $devicesQuery->whereIn('devices.channel_id', $ids);
}
/**
* Restrict a query that has a bare channel_id column (e.g. page_visits).
*/
public static function applyChannelIdScope(Builder $query, ?User $agent, string $column = 'channel_id'): Builder
{
if ($agent === null) {
return $query;
}
$ids = self::channelIdsFor($agent);
if ($ids === []) {
return $query->whereRaw('1 = 0');
}
return $query->whereIn($column, $ids);
}
public static function applyChannelIdAgentUserFilter(Builder $query, ?int $agentUserId, string $column = 'channel_id'): Builder
{
if ($agentUserId === null || $agentUserId <= 0) {
return $query;
}
$ids = Channel::query()
->where('user_id', $agentUserId)
->pluck('channel_id')
->all();
if ($ids === []) {
return $query->whereRaw('1 = 0');
}
return $query->whereIn($column, $ids);
}
}