Files
sam-api/app/Models/Barobill/BarobillBillingRecord.php
김보곤 18a6f3e7aa refactor: [barobill] 바로빌 연동 코드 전면 개선
- config/services.php에 barobill 설정 등록 (운영/테스트 모드 분기 정상화)
- BarobillSetting 모델에 BelongsToTenant 적용 및 use_* 필드 casts 추가
- BarobillService API URL을 baroservice.com(SOAP)으로 수정
- BarobillService callApi 메서드 경로 하드코딩 제거 (서비스별 분기)
- BarobillService 예외 이중 래핑 문제 수정
- BarobillController URL 메서드 중복 코드 제거
- 누락 모델 16개 생성 (MNG 패턴 준수, BelongsToTenant 적용)
- 바로빌 전 테이블 options JSON 컬럼 추가 마이그레이션
2026-03-11 18:16:59 +09:00

83 lines
2.3 KiB
PHP

<?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,
};
}
}