feat: [barobill] 회원사관리 페이지에서 미등록 테넌트 자동 생성

- 본사(tenant_id=1) 접근 시 barobill_members 레코드가 없는 테넌트에 기본 레코드 자동 생성
- 신규 생성 레코드는 status=pending, server_mode=test 기본값
- 테넌트의 사업자번호, 회사명, 대표자명을 자동 매핑
This commit is contained in:
김보곤
2026-02-21 11:21:24 +09:00
parent feb8cbe995
commit 13eab75da3

View File

@@ -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))