feat:바로빌 과금관리 테이블 마이그레이션

- barobill_subscriptions: 월정액 구독 관리
- barobill_billing_records: 과금 내역 기록
- barobill_monthly_summaries: 월별 집계 테이블

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
pro
2026-01-27 15:03:57 +09:00
parent 6d05ab815f
commit 597d24eb19
3 changed files with 151 additions and 0 deletions

View File

@@ -0,0 +1,46 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
/**
* 바로빌 월정액 구독 테이블
*
* 회원사별 월정액 서비스 구독 현황 관리
* - 계좌조회, 카드내역, 홈텍스 매입/매출
*/
return new class extends Migration
{
public function up(): void
{
Schema::create('barobill_subscriptions', function (Blueprint $table) {
$table->id();
$table->foreignId('member_id')->comment('바로빌 회원사 ID');
$table->enum('service_type', ['bank_account', 'card', 'hometax'])
->comment('서비스 유형: bank_account=계좌조회, card=카드내역, hometax=홈텍스');
$table->unsignedInteger('monthly_fee')->default(0)->comment('월정액 금액 (원)');
$table->date('started_at')->comment('구독 시작일');
$table->date('ended_at')->nullable()->comment('구독 종료일 (null=진행중)');
$table->boolean('is_active')->default(true)->comment('활성 상태');
$table->text('memo')->nullable()->comment('메모');
$table->timestamps();
$table->softDeletes();
// 인덱스
$table->index(['member_id', 'service_type']);
$table->index(['is_active', 'service_type']);
// 외래키
$table->foreign('member_id')
->references('id')
->on('barobill_members')
->onDelete('cascade');
});
}
public function down(): void
{
Schema::dropIfExists('barobill_subscriptions');
}
};

View File

@@ -0,0 +1,52 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
/**
* 바로빌 과금 기록 테이블
*
* 월별 과금 내역 (월정액 + 건별 사용량)
*/
return new class extends Migration
{
public function up(): void
{
Schema::create('barobill_billing_records', function (Blueprint $table) {
$table->id();
$table->foreignId('member_id')->comment('바로빌 회원사 ID');
$table->string('billing_month', 7)->comment('과금 월 (YYYY-MM)');
$table->enum('service_type', ['tax_invoice', 'bank_account', 'card', 'hometax'])
->comment('서비스 유형');
$table->enum('billing_type', ['subscription', 'usage'])
->comment('과금 유형: subscription=월정액, usage=건별');
$table->unsignedInteger('quantity')->default(1)->comment('수량 (월정액=1, 건별=사용건수)');
$table->unsignedInteger('unit_price')->default(0)->comment('단가 (원)');
$table->unsignedInteger('total_amount')->default(0)->comment('총액 (원)');
$table->date('billed_at')->comment('과금일');
$table->text('description')->nullable()->comment('설명');
$table->timestamps();
// 인덱스
$table->index(['member_id', 'billing_month']);
$table->index(['billing_month', 'service_type']);
$table->index(['billing_month', 'billing_type']);
$table->index('billed_at');
// 중복 방지 (같은 월, 같은 서비스, 같은 과금유형)
$table->unique(['member_id', 'billing_month', 'service_type', 'billing_type'], 'billing_unique');
// 외래키
$table->foreign('member_id')
->references('id')
->on('barobill_members')
->onDelete('cascade');
});
}
public function down(): void
{
Schema::dropIfExists('barobill_billing_records');
}
};

View File

@@ -0,0 +1,53 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
/**
* 바로빌 월별 집계 테이블
*
* 조회 성능 최적화를 위한 월별 집계 데이터
*/
return new class extends Migration
{
public function up(): void
{
Schema::create('barobill_monthly_summaries', function (Blueprint $table) {
$table->id();
$table->foreignId('member_id')->comment('바로빌 회원사 ID');
$table->string('billing_month', 7)->comment('과금 월 (YYYY-MM)');
// 월정액 항목별
$table->unsignedInteger('bank_account_fee')->default(0)->comment('계좌조회 월정액');
$table->unsignedInteger('card_fee')->default(0)->comment('카드내역 월정액');
$table->unsignedInteger('hometax_fee')->default(0)->comment('홈텍스 월정액');
$table->unsignedInteger('subscription_total')->default(0)->comment('월정액 합계');
// 건별 사용량
$table->unsignedInteger('tax_invoice_count')->default(0)->comment('세금계산서 발행 건수');
$table->unsignedInteger('tax_invoice_amount')->default(0)->comment('세금계산서 과금액');
$table->unsignedInteger('usage_total')->default(0)->comment('건별 사용 합계');
// 총합계
$table->unsignedInteger('grand_total')->default(0)->comment('총합계');
$table->timestamps();
// 인덱스
$table->unique(['member_id', 'billing_month']);
$table->index('billing_month');
// 외래키
$table->foreign('member_id')
->references('id')
->on('barobill_members')
->onDelete('cascade');
});
}
public function down(): void
{
Schema::dropIfExists('barobill_monthly_summaries');
}
};