108 lines
2.5 KiB
PHP
108 lines
2.5 KiB
PHP
<?php
|
|
|
|
namespace App\Models\Barobill;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
|
|
/**
|
|
* 바로빌 API 설정 모델
|
|
*
|
|
* @property int $id
|
|
* @property string $name
|
|
* @property string $environment
|
|
* @property string $cert_key
|
|
* @property string|null $corp_num
|
|
* @property string $base_url
|
|
* @property string|null $description
|
|
* @property bool $is_active
|
|
* @property \Carbon\Carbon $created_at
|
|
* @property \Carbon\Carbon $updated_at
|
|
* @property \Carbon\Carbon|null $deleted_at
|
|
*/
|
|
class BarobillConfig extends Model
|
|
{
|
|
use HasFactory, SoftDeletes;
|
|
|
|
protected $fillable = [
|
|
'name',
|
|
'environment',
|
|
'cert_key',
|
|
'corp_num',
|
|
'base_url',
|
|
'description',
|
|
'is_active',
|
|
];
|
|
|
|
protected $casts = [
|
|
'is_active' => 'boolean',
|
|
];
|
|
|
|
/**
|
|
* 테스트 서버 설정 조회 (환경 기준, is_active 무관)
|
|
*/
|
|
public static function getActiveTest(): ?self
|
|
{
|
|
return self::where('environment', 'test')->first();
|
|
}
|
|
|
|
/**
|
|
* 운영 서버 설정 조회 (환경 기준, is_active 무관)
|
|
*/
|
|
public static function getActiveProduction(): ?self
|
|
{
|
|
return self::where('environment', 'production')->first();
|
|
}
|
|
|
|
/**
|
|
* 현재 환경에 맞는 설정 조회
|
|
*
|
|
* 테넌트별 서버 모드 지원을 위해 is_active 조건 제거
|
|
*/
|
|
public static function getActive(bool $isTestMode = false): ?self
|
|
{
|
|
return $isTestMode ? self::getActiveTest() : self::getActiveProduction();
|
|
}
|
|
|
|
/**
|
|
* 환경 라벨
|
|
*/
|
|
public function getEnvironmentLabelAttribute(): string
|
|
{
|
|
return match ($this->environment) {
|
|
'test' => '테스트서버',
|
|
'production' => '운영서버',
|
|
default => $this->environment,
|
|
};
|
|
}
|
|
|
|
/**
|
|
* 상태 라벨
|
|
*/
|
|
public function getStatusLabelAttribute(): string
|
|
{
|
|
return $this->is_active ? '활성' : '비활성';
|
|
}
|
|
|
|
/**
|
|
* 상태 색상 (Tailwind)
|
|
*/
|
|
public function getStatusColorAttribute(): string
|
|
{
|
|
return $this->is_active ? 'green' : 'gray';
|
|
}
|
|
|
|
/**
|
|
* 마스킹된 인증키 (앞 8자리만 표시)
|
|
*/
|
|
public function getMaskedCertKeyAttribute(): string
|
|
{
|
|
if (strlen($this->cert_key) <= 8) {
|
|
return $this->cert_key;
|
|
}
|
|
|
|
return substr($this->cert_key, 0, 8).str_repeat('*', 8).'...';
|
|
}
|
|
}
|