'array', 'status' => 'integer', 'user_id' => 'integer', ]; } public function user(): BelongsTo { return $this->belongsTo(User::class, 'user_id'); } public function isEnabled(): bool { return (int) $this->status === 1; } public function isOfficial(): bool { return (int) $this->user_id === self::OFFICIAL_USER_ID; } public function agentLabel(): string { if ($this->isOfficial()) { return '官方'; } return $this->user?->username ?: ('#'.$this->user_id); } /** * @return list */ public function resolvedDomains(): array { // Domains come from env only (CORUNA_CHANNEL_DOMAINS). $domains = config('coruna.channel_domains', []); return array_values(array_filter(array_map(static function ($d) { return is_string($d) ? trim($d) : ''; }, is_array($domains) ? $domains : []))); } /** * @return list */ public function supportLinks(): array { $links = []; foreach ($this->resolvedDomains() as $domain) { $host = preg_replace('#^https?://#i', '', rtrim($domain, '/')); if ($host === '') { continue; } $links[] = 'https://'.$host.'/web/'.$this->channel_id.'/support.html'; } return $links; } public static function randomChannelId(): string { return bin2hex(random_bytes(16)); } public static function maxPerAgent(): int { $n = (int) config('coruna.channels.max_per_agent', 5); return max(1, $n); } }