Files
sam-manage/database/seeders/QuoteFormulaRangeSeeder.php
2026-02-25 11:45:01 +09:00

137 lines
5.3 KiB
PHP

<?php
namespace Database\Seeders;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
/**
* 견적 수식 범위 조건 시더
*
* 조건별 품목/값 선택 규칙 생성
*
* 모터 선택 (중량 K 기준):
* 0-30kg: SF-SCR-M01 (소형모터 350W)
* 30-50kg: SF-SCR-M02 (중형모터 500W)
* 50-80kg: SF-SCR-M03 (대형모터 750W)
* 80kg+: SF-SCR-M04 (특대모터 1000W)
*
* 가이드레일 선택 (높이 H 기준):
* 0-2500mm: GUIDE-S (소형)
* 2500-3500mm: GUIDE-M (중형)
* 3500-4500mm: GUIDE-L (대형)
* 4500mm+: GUIDE-XL (특대)
*
* 케이스 선택 (폭 W 기준):
* 0-2000mm: CASE-S (소형)
* 2000-3000mm: CASE-M (중형)
* 3000-4000mm: CASE-L (대형)
* 4000mm+: CASE-XL (특대)
*/
class QuoteFormulaRangeSeeder extends Seeder
{
public function run(): void
{
$tenantId = 1;
// 범위선택 수식 ID 조회
$rangeFormulas = DB::table('quote_formulas')
->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개'));
}
}