Files
sam-manage/app/Models/Barobill/BarobillBillingRecord.php
pro 39161d1203 feat:바로빌 과금관리 시스템 구현
- 모델: BarobillSubscription, BarobillBillingRecord, BarobillMonthlySummary
- 서비스: BarobillBillingService (구독/과금 처리 로직)
- API 컨트롤러: BarobillBillingController (구독/과금 CRUD)
- 뷰: 과금 현황 탭, 구독 관리 탭, 통계 카드, 상세 모달
- 라우트: 웹/API 라우트 추가

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-27 15:03:44 +09:00

117 lines
2.5 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';
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',
'created_at' => 'datetime',
'updated_at' => 'datetime',
];
/**
* 서비스 유형 라벨
*/
public const SERVICE_TYPES = [
'tax_invoice' => '전자세금계산서',
'bank_account' => '계좌조회',
'card' => '카드내역',
'hometax' => '홈텍스 매입/매출',
];
/**
* 과금 유형 라벨
*/
public const BILLING_TYPES = [
'subscription' => '월정액',
'usage' => '건별',
];
/**
* 건별 단가 (원)
*/
public const USAGE_UNIT_PRICES = [
'tax_invoice' => 100, // 전자세금계산서 건당 100원
];
/**
* 바로빌 회원사 관계
*/
public function member(): BelongsTo
{
return $this->belongsTo(BarobillMember::class, 'member_id');
}
/**
* 서비스 유형 라벨
*/
public function getServiceTypeLabelAttribute(): string
{
return self::SERVICE_TYPES[$this->service_type] ?? $this->service_type;
}
/**
* 과금 유형 라벨
*/
public function getBillingTypeLabelAttribute(): string
{
return self::BILLING_TYPES[$this->billing_type] ?? $this->billing_type;
}
/**
* 특정 월 조회
*/
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);
}
}