Files
sam-api/app/Models/Barobill/BarobillBillingRecord.php

83 lines
2.3 KiB
PHP
Raw Normal View History

<?php
namespace App\Models\Barobill;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class BarobillBillingRecord extends Model
{
protected $table = 'barobill_billing_records';
public const SERVICE_TYPES = ['tax_invoice', 'bank_account', 'card', 'hometax'];
public const BILLING_TYPES = ['subscription', 'usage'];
protected $fillable = [
'member_id',
'billing_month',
'service_type',
'billing_type',
'quantity',
'unit_price',
'total_amount',
'billed_at',
'description',
];
protected $casts = [
'quantity' => 'integer',
'unit_price' => 'integer',
'total_amount' => 'integer',
'billed_at' => 'date',
];
// =========================================================================
// 관계 정의
// =========================================================================
public function member(): BelongsTo
{
return $this->belongsTo(BarobillMember::class, 'member_id');
}
// =========================================================================
// 스코프
// =========================================================================
public function scopeOfMonth($query, string $billingMonth)
{
return $query->where('billing_month', $billingMonth);
}
public function scopeSubscription($query)
{
return $query->where('billing_type', 'subscription');
}
public function scopeUsage($query)
{
return $query->where('billing_type', 'usage');
}
public function scopeOfService($query, string $serviceType)
{
return $query->where('service_type', $serviceType);
}
// =========================================================================
// 접근자
// =========================================================================
public function getServiceTypeLabelAttribute(): string
{
return match ($this->service_type) {
'tax_invoice' => '전자세금계산서',
'bank_account' => '계좌조회',
'card' => '카드조회',
'hometax' => '홈택스',
default => $this->service_type,
};
}
}