feat: [barobill] 구독/과금/사용량 관리 API 이관

- BarobillBillingService 생성 (구독 CRUD, 월별 과금 배치, 사용량 과금, 집계)
- BarobillUsageService 생성 (회원별 사용량 조회, 통계, 정책 기반 과금 계산)
- BarobillBillingController 생성 (9개 엔드포인트)
  - 구독 관리, 월별 현황, 과금 배치, 연간 추이, 정책 관리
- BarobillUsageController 생성 (4개 엔드포인트)
  - 사용량 목록/통계, 회원별 상세, 과금 정책 정보
- finance.php 라우트 등록 (barobill/billing/*, barobill/usage/*)
This commit is contained in:
김보곤
2026-03-22 19:59:41 +09:00
parent a1f3de782f
commit ac94602cf1
5 changed files with 759 additions and 0 deletions

View File

@@ -0,0 +1,96 @@
<?php
namespace App\Http\Controllers\Api\V1;
use App\Helpers\ApiResponse;
use App\Http\Controllers\Controller;
use App\Models\Barobill\BarobillMember;
use App\Services\Barobill\BarobillUsageService;
use Carbon\Carbon;
use Illuminate\Http\Request;
class BarobillUsageController extends Controller
{
public function __construct(
private BarobillUsageService $usageService,
) {}
/**
* 사용량 목록
*/
public function index(Request $request)
{
$data = $request->validate([
'start_date' => 'nullable|date_format:Y-m-d',
'end_date' => 'nullable|date_format:Y-m-d',
'tenant_id' => 'nullable|integer',
]);
return ApiResponse::handle(function () use ($data) {
$startDate = $data['start_date'] ?? Carbon::now()->startOfMonth()->format('Y-m-d');
$endDate = $data['end_date'] ?? Carbon::now()->format('Y-m-d');
$tenantId = $data['tenant_id'] ?? null;
$usageList = $this->usageService->getUsageList($startDate, $endDate, $tenantId);
return [
'data' => $usageList,
'stats' => $this->usageService->aggregateStats($usageList),
'meta' => [
'start_date' => $startDate,
'end_date' => $endDate,
],
];
}, __('message.fetched'));
}
/**
* 사용량 통계
*/
public function stats(Request $request)
{
$data = $request->validate([
'start_date' => 'nullable|date_format:Y-m-d',
'end_date' => 'nullable|date_format:Y-m-d',
'tenant_id' => 'nullable|integer',
]);
return ApiResponse::handle(function () use ($data) {
$startDate = $data['start_date'] ?? Carbon::now()->startOfMonth()->format('Y-m-d');
$endDate = $data['end_date'] ?? Carbon::now()->format('Y-m-d');
$usageList = $this->usageService->getUsageList($startDate, $endDate, $data['tenant_id'] ?? null);
return $this->usageService->aggregateStats($usageList);
}, __('message.fetched'));
}
/**
* 회원별 사용량 상세
*/
public function show(Request $request, int $memberId)
{
$data = $request->validate([
'start_date' => 'nullable|date_format:Y-m-d',
'end_date' => 'nullable|date_format:Y-m-d',
]);
return ApiResponse::handle(function () use ($memberId, $data) {
$member = BarobillMember::withoutGlobalScopes()->findOrFail($memberId);
$startDate = $data['start_date'] ?? Carbon::now()->startOfMonth()->format('Y-m-d');
$endDate = $data['end_date'] ?? Carbon::now()->format('Y-m-d');
return $this->usageService->getMemberUsage($member, $startDate, $endDate);
}, __('message.fetched'));
}
/**
* 과금 정책 정보
*/
public function priceInfo()
{
return ApiResponse::handle(function () {
return ['prices' => BarobillUsageService::getPriceInfo()];
}, __('message.fetched'));
}
}