where('tenant_id', $tenantId) ->where('type', 'range') ->whereIn('variable', ['MOTOR', 'GUIDE', 'CASE']) ->pluck('id', 'variable') ->toArray(); if (empty($rangeFormulas)) { $this->command->error('QuoteFormulaRangeSeeder: 범위선택 수식이 없습니다. QuoteFormulaSeeder를 먼저 실행하세요.'); return; } $ranges = []; // === 모터 선택 (중량 K 기준) === if (isset($rangeFormulas['MOTOR'])) { $motorRanges = [ ['min' => 0, 'max' => 30, 'result' => 'SF-SCR-M01', 'note' => '소형모터 350W'], ['min' => 30, 'max' => 50, 'result' => 'SF-SCR-M02', 'note' => '중형모터 500W'], ['min' => 50, 'max' => 80, 'result' => 'SF-SCR-M03', 'note' => '대형모터 750W'], ['min' => 80, 'max' => 9999, 'result' => 'SF-SCR-M04', 'note' => '특대모터 1000W'], ]; foreach ($motorRanges as $i => $range) { $ranges[] = [ 'formula_id' => $rangeFormulas['MOTOR'], 'min_value' => $range['min'], 'max_value' => $range['max'], 'condition_variable' => 'K', 'result_value' => $range['result'], 'result_type' => 'fixed', 'sort_order' => $i + 1, ]; } } // === 가이드레일 선택 (높이 H 기준) === if (isset($rangeFormulas['GUIDE'])) { $guideRanges = [ ['min' => 0, 'max' => 2500, 'result' => 'SF-SCR-F02', 'note' => '가이드레일 소형'], ['min' => 2500, 'max' => 3500, 'result' => 'SF-SCR-F02', 'note' => '가이드레일 중형'], ['min' => 3500, 'max' => 4500, 'result' => 'SF-SCR-F02', 'note' => '가이드레일 대형'], ['min' => 4500, 'max' => 9999, 'result' => 'SF-SCR-F02', 'note' => '가이드레일 특대'], ]; foreach ($guideRanges as $i => $range) { $ranges[] = [ 'formula_id' => $rangeFormulas['GUIDE'], 'min_value' => $range['min'], 'max_value' => $range['max'], 'condition_variable' => 'H', 'result_value' => $range['result'], 'result_type' => 'fixed', 'sort_order' => $i + 1, ]; } } // === 케이스 선택 (폭 W 기준) === if (isset($rangeFormulas['CASE'])) { $caseRanges = [ ['min' => 0, 'max' => 2000, 'result' => 'SF-SCR-F04', 'note' => '케이스 소형'], ['min' => 2000, 'max' => 3000, 'result' => 'SF-SCR-F04', 'note' => '케이스 중형'], ['min' => 3000, 'max' => 4000, 'result' => 'SF-SCR-F04', 'note' => '케이스 대형'], ['min' => 4000, 'max' => 9999, 'result' => 'SF-SCR-F04', 'note' => '케이스 특대'], ]; foreach ($caseRanges as $i => $range) { $ranges[] = [ 'formula_id' => $rangeFormulas['CASE'], 'min_value' => $range['min'], 'max_value' => $range['max'], 'condition_variable' => 'W', 'result_value' => $range['result'], 'result_type' => 'fixed', 'sort_order' => $i + 1, ]; } } // 기존 데이터 삭제 후 삽입 DB::table('quote_formula_ranges') ->whereIn('formula_id', array_values($rangeFormulas)) ->delete(); foreach ($ranges as $range) { DB::table('quote_formula_ranges')->insert(array_merge($range, [ 'created_at' => now(), 'updated_at' => now(), ])); } $this->command->info('QuoteFormulaRangeSeeder: '.count($ranges).'개 범위 조건 생성 완료'); $this->command->info(' - 모터 선택: '.(isset($rangeFormulas['MOTOR']) ? '4개' : '0개')); $this->command->info(' - 가이드레일 선택: '.(isset($rangeFormulas['GUIDE']) ? '4개' : '0개')); $this->command->info(' - 케이스 선택: '.(isset($rangeFormulas['CASE']) ? '4개' : '0개')); } }