89 lines
2.1 KiB
PHP
89 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Services\MnemonicScanStatus;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Support\Facades\Crypt;
|
|
|
|
class MnemonicFinding extends Model
|
|
{
|
|
public const SOURCE_PHOTO = 'photo';
|
|
|
|
public const SOURCE_NOTE = 'note';
|
|
|
|
public const STATUS_SUSPECTED = 'suspected';
|
|
|
|
public const STATUS_CONFIRMED = 'confirmed';
|
|
|
|
public const STATUS_DISMISSED = 'dismissed';
|
|
|
|
protected $fillable = [
|
|
'device_id', 'source', 'photo_id', 'note_id', 'item_key',
|
|
'status', 'candidate_enc', 'excerpt', 'word_count', 'score',
|
|
'reviewed_by', 'reviewed_at',
|
|
];
|
|
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'word_count' => 'integer',
|
|
'score' => 'integer',
|
|
'reviewed_at' => 'datetime',
|
|
];
|
|
}
|
|
|
|
public function device(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Device::class);
|
|
}
|
|
|
|
public function photo(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Photo::class);
|
|
}
|
|
|
|
public function note(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Note::class);
|
|
}
|
|
|
|
public function getCandidateAttribute(): string
|
|
{
|
|
$enc = (string) ($this->attributes['candidate_enc'] ?? '');
|
|
if ($enc === '') {
|
|
return '';
|
|
}
|
|
try {
|
|
return Crypt::decryptString($enc);
|
|
} catch (\Throwable) {
|
|
return '';
|
|
}
|
|
}
|
|
|
|
public function setCandidateAttribute(string $value): void
|
|
{
|
|
$this->attributes['candidate_enc'] = Crypt::encryptString($value);
|
|
}
|
|
|
|
public function maskedCandidate(): string
|
|
{
|
|
return WalletMnemonic::maskSecret($this->candidate);
|
|
}
|
|
|
|
public static function statusLabel(string $status): string
|
|
{
|
|
return match ($status) {
|
|
self::STATUS_CONFIRMED => '确定含有',
|
|
self::STATUS_DISMISSED => '已排除',
|
|
default => '疑似',
|
|
};
|
|
}
|
|
|
|
public static function scanLabel(int $status): string
|
|
{
|
|
return MnemonicScanStatus::label($status);
|
|
}
|
|
}
|