feat: 견적 V2 동적 카테고리 시스템 구현
- CategoryService: tree 메서드에 code_group 필터 지원 추가 - FormulaEvaluatorService: 하드코딩된 process_type을 동적 카테고리로 변경 - groupItemsByProcess(): item_category 필드 기반 그룹화 - getItemCategoryTree(): DB에서 카테고리 트리 조회 - buildCategoryMapping(): BENDING 하위 카테고리 처리 - addProcessGroupToItems(): category_code 필드 추가 (레거시 호환 유지) - QuoteItemCategorySeeder: 품목 카테고리 초기 데이터 시더 추가 - BODY, BENDING(하위 3개), MOTOR_CTRL, ACCESSORY Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -197,15 +197,22 @@ public function tree(array $params)
|
||||
{
|
||||
$tenantId = $this->tenantId();
|
||||
$onlyActive = (bool) ($params['only_active'] ?? false);
|
||||
$codeGroup = $params['code_group'] ?? null;
|
||||
|
||||
$q = Category::where('tenant_id', $tenantId)
|
||||
->when($onlyActive, fn ($qq) => $qq->where('is_active', 1))
|
||||
->when($codeGroup, fn ($qq) => $qq->where('code_group', $codeGroup))
|
||||
->orderBy('parent_id')->orderBy('sort_order')->orderBy('id')
|
||||
->get(['id', 'parent_id', 'code', 'name', 'is_active', 'sort_order']);
|
||||
->get(['id', 'parent_id', 'code', 'code_group', 'name', 'is_active', 'sort_order']);
|
||||
|
||||
// 최상위 카테고리 ID 수집 (해당 code_group의 parent_id가 null이거나, 다른 code_group의 카테고리를 가리키는 경우)
|
||||
$categoryIds = $q->pluck('id')->toArray();
|
||||
$rootIds = $q->filter(fn ($c) => $c->parent_id === null || ! in_array($c->parent_id, $categoryIds))->pluck('id')->toArray();
|
||||
|
||||
$byParent = [];
|
||||
foreach ($q as $c) {
|
||||
$byParent[$c->parent_id ?? 0][] = $c;
|
||||
$parentKey = in_array($c->id, $rootIds) ? 0 : ($c->parent_id ?? 0);
|
||||
$byParent[$parentKey][] = $c;
|
||||
}
|
||||
|
||||
$build = function ($pid) use (&$build, &$byParent) {
|
||||
|
||||
Reference in New Issue
Block a user