2026-02-09 12:32:26 +09:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace Database\Seeders;
|
|
|
|
|
|
|
|
|
|
use App\Models\Commons\Menu;
|
|
|
|
|
use Illuminate\Database\Seeder;
|
|
|
|
|
|
|
|
|
|
class FixServerMenuSeeder extends Seeder
|
|
|
|
|
{
|
|
|
|
|
public function run(): void
|
|
|
|
|
{
|
|
|
|
|
$tenantId = 1;
|
|
|
|
|
|
|
|
|
|
// 고객/거래처/채권관리 그룹 찾기
|
|
|
|
|
$targetGroup = Menu::withoutGlobalScopes()
|
|
|
|
|
->where('tenant_id', $tenantId)
|
|
|
|
|
->where('name', '고객/거래처/채권관리')
|
|
|
|
|
->whereNull('parent_id')
|
|
|
|
|
->first();
|
|
|
|
|
|
2026-02-25 11:45:01 +09:00
|
|
|
if (! $targetGroup) {
|
2026-02-09 12:32:26 +09:00
|
|
|
$this->command->error('고객/거래처/채권관리 그룹을 찾을 수 없습니다.');
|
2026-02-25 11:45:01 +09:00
|
|
|
|
2026-02-09 12:32:26 +09:00
|
|
|
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();
|
2026-02-25 11:45:01 +09:00
|
|
|
if ($menu) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
2026-02-09 12:32:26 +09:00
|
|
|
}
|
|
|
|
|
|
2026-02-25 11:45:01 +09:00
|
|
|
if (! $menu) {
|
2026-02-09 12:32:26 +09:00
|
|
|
// 이미 이동된 경우 확인
|
|
|
|
|
$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 {
|
2026-02-25 11:45:01 +09:00
|
|
|
$this->command->warn(' 메뉴 없음: '.implode(' / ', $searchNames));
|
2026-02-09 12:32:26 +09:00
|
|
|
}
|
2026-02-25 11:45:01 +09:00
|
|
|
|
2026-02-09 12:32:26 +09:00
|
|
|
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}");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|