diff --git a/app/Http/Controllers/Api/Admin/Barobill/BarobillMemberController.php b/app/Http/Controllers/Api/Admin/Barobill/BarobillMemberController.php index 39d103b7..c6d62343 100644 --- a/app/Http/Controllers/Api/Admin/Barobill/BarobillMemberController.php +++ b/app/Http/Controllers/Api/Admin/Barobill/BarobillMemberController.php @@ -4,6 +4,7 @@ use App\Http\Controllers\Controller; use App\Models\Barobill\BarobillMember; +use App\Models\Tenants\Tenant; use App\Services\Barobill\BarobillService; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; @@ -68,6 +69,25 @@ public function index(Request $request): JsonResponse|Response // 테넌트 1(본사)이면 자동으로 전체 테넌트 모드 $isHeadquarters = $tenantId == self::HEADQUARTERS_TENANT_ID; + // 본사이면 barobill_members 미등록 테넌트에 기본 레코드 자동 생성 + if ($isHeadquarters || $allTenants) { + $existingTenantIds = BarobillMember::pluck('tenant_id')->toArray(); + $missingTenants = Tenant::whereNotIn('id', $existingTenantIds)->get(); + + foreach ($missingTenants as $tenant) { + BarobillMember::create([ + 'tenant_id' => $tenant->id, + 'biz_no' => $tenant->business_num ?? '', + 'corp_name' => $tenant->company_name, + 'ceo_name' => $tenant->ceo_name ?? '', + 'barobill_id' => '', + 'barobill_pwd' => '', + 'status' => 'pending', + 'server_mode' => 'test', + ]); + } + } + $query = BarobillMember::query() // 본사(테넌트 1)이거나 전체 테넌트 모드일 때는 필터 없음 ->when(!$isHeadquarters && !$allTenants && $tenantId, fn($q) => $q->where('tenant_id', $tenantId))