77 lines
2.0 KiB
PHP
77 lines
2.0 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace App\Models\Barobill;
|
||
|
|
|
||
|
|
use Illuminate\Database\Eloquent\Model;
|
||
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
||
|
|
|
||
|
|
class BarobillSubscription extends Model
|
||
|
|
{
|
||
|
|
use SoftDeletes;
|
||
|
|
|
||
|
|
protected $table = 'barobill_subscriptions';
|
||
|
|
|
||
|
|
public const SERVICE_TYPES = ['bank_account', 'card', 'hometax'];
|
||
|
|
|
||
|
|
public const DEFAULT_MONTHLY_FEES = [
|
||
|
|
'bank_account' => 10000,
|
||
|
|
'card' => 10000,
|
||
|
|
'hometax' => 0,
|
||
|
|
];
|
||
|
|
|
||
|
|
protected $fillable = [
|
||
|
|
'member_id',
|
||
|
|
'service_type',
|
||
|
|
'monthly_fee',
|
||
|
|
'started_at',
|
||
|
|
'ended_at',
|
||
|
|
'is_active',
|
||
|
|
'memo',
|
||
|
|
];
|
||
|
|
|
||
|
|
protected $casts = [
|
||
|
|
'monthly_fee' => 'integer',
|
||
|
|
'started_at' => 'date',
|
||
|
|
'ended_at' => 'date',
|
||
|
|
'is_active' => 'boolean',
|
||
|
|
];
|
||
|
|
|
||
|
|
// =========================================================================
|
||
|
|
// 관계 정의
|
||
|
|
// =========================================================================
|
||
|
|
|
||
|
|
public function member(): BelongsTo
|
||
|
|
{
|
||
|
|
return $this->belongsTo(BarobillMember::class, 'member_id');
|
||
|
|
}
|
||
|
|
|
||
|
|
// =========================================================================
|
||
|
|
// 스코프
|
||
|
|
// =========================================================================
|
||
|
|
|
||
|
|
public function scopeActive($query)
|
||
|
|
{
|
||
|
|
return $query->where('is_active', true);
|
||
|
|
}
|
||
|
|
|
||
|
|
public function scopeOfService($query, string $serviceType)
|
||
|
|
{
|
||
|
|
return $query->where('service_type', $serviceType);
|
||
|
|
}
|
||
|
|
|
||
|
|
// =========================================================================
|
||
|
|
// 접근자
|
||
|
|
// =========================================================================
|
||
|
|
|
||
|
|
public function getServiceTypeLabelAttribute(): string
|
||
|
|
{
|
||
|
|
return match ($this->service_type) {
|
||
|
|
'bank_account' => '계좌조회',
|
||
|
|
'card' => '카드조회',
|
||
|
|
'hometax' => '홈택스',
|
||
|
|
default => $this->service_type,
|
||
|
|
};
|
||
|
|
}
|
||
|
|
}
|