diff --git a/database/seeders/FixServerMenuSeeder.php b/database/seeders/FixServerMenuSeeder.php new file mode 100644 index 00000000..4560a0d5 --- /dev/null +++ b/database/seeders/FixServerMenuSeeder.php @@ -0,0 +1,107 @@ +where('tenant_id', $tenantId) + ->where('name', '고객/거래처/채권관리') + ->whereNull('parent_id') + ->first(); + + if (!$targetGroup) { + $this->command->error('고객/거래처/채권관리 그룹을 찾을 수 없습니다.'); + return; + } + + $this->command->info("대상 그룹: 고객/거래처/채권관리 (id: {$targetGroup->id})"); + + // 서버에서 실제 메뉴 이름으로 이동 (로컬과 서버 모두 대응) + $menuMoves = [ + // [검색 이름들, 새 이름, sort_order] + [['채권관리', '미수금 관리', '미수금관리'], '미수금관리', 3], + [['채무관리', '미지급금 관리', '미지급금관리'], '미지급금관리', 4], + [['환불관리', '환불/해지 관리', '환불/해지관리'], '환불/해지관리', 5], + ]; + + foreach ($menuMoves as [$searchNames, $newName, $sortOrder]) { + $menu = null; + foreach ($searchNames as $name) { + $menu = Menu::withoutGlobalScopes() + ->where('tenant_id', $tenantId) + ->where('name', $name) + ->where('is_active', true) + ->first(); + if ($menu) break; + } + + if (!$menu) { + // 이미 이동된 경우 확인 + $existing = Menu::withoutGlobalScopes() + ->where('tenant_id', $tenantId) + ->where('parent_id', $targetGroup->id) + ->where('name', $newName) + ->first(); + + if ($existing) { + $this->command->info(" 이미 이동됨: {$newName} (id: {$existing->id})"); + } else { + $this->command->warn(" 메뉴 없음: " . implode(' / ', $searchNames)); + } + continue; + } + + $menu->update([ + 'parent_id' => $targetGroup->id, + 'sort_order' => $sortOrder, + 'name' => $newName, + ]); + $this->command->info(" 이동: {$menu->getOriginal('name')} → 고객/거래처/채권관리/{$newName} (sort: {$sortOrder})"); + } + + // 재무관리 부모 비활성화 (자식 없으면) + $financeParent = Menu::withoutGlobalScopes() + ->where('tenant_id', $tenantId) + ->where('name', '재무관리') + ->whereNull('parent_id') + ->first(); + + if ($financeParent) { + $remaining = Menu::withoutGlobalScopes() + ->where('tenant_id', $tenantId) + ->where('parent_id', $financeParent->id) + ->where('is_active', true) + ->count(); + + if ($remaining === 0) { + $financeParent->update(['is_active' => false]); + $this->command->info(" 비활성화: 재무관리 (id: {$financeParent->id})"); + } else { + $this->command->warn(" 재무관리 자식 {$remaining}개 남음 - 비활성화 안 함"); + } + } + + // 결과 확인 + $this->command->info(''); + $this->command->info('=== 고객/거래처/채권관리 최종 구성 ==='); + $children = Menu::withoutGlobalScopes() + ->where('tenant_id', $tenantId) + ->where('parent_id', $targetGroup->id) + ->where('is_active', true) + ->orderBy('sort_order') + ->get(['name', 'url', 'sort_order']); + + foreach ($children as $child) { + $this->command->info(" {$child->sort_order}. {$child->name} → {$child->url}"); + } + } +}