Files
sam-manage/database/seeders/CategoryGroupSeeder.php
hskwon 9dadf05e3a feat: Design 시뮬레이터 샘플 데이터 Seeder 추가
- CategoryGroupSeeder: 면적/중량/수량 기반 단가 계산 그룹 3개
- DesignItemSeeder: Design 샘플 품목 99개 (RM:20, SM:25, SF:40, FG:14)
- 완제품 BOM 데이터 포함 (수량 수식 quantityFormula 지원)
2025-12-24 14:44:21 +09:00

84 lines
3.1 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace Database\Seeders;
use App\Models\CategoryGroup;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
/**
* 카테고리 그룹 시더
*
* 면적/중량/수량 기반 단가 계산 그룹을 생성합니다.
* Design 시뮬레이터와 동일한 계산 방식을 위한 기초 데이터입니다.
*
* 사용법:
* php artisan db:seed --class=CategoryGroupSeeder
*/
class CategoryGroupSeeder extends Seeder
{
protected int $tenantId = 1;
public function run(): void
{
$this->command->info('카테고리 그룹 시딩 시작...');
DB::transaction(function () {
// 기존 데이터 삭제
CategoryGroup::withoutGlobalScopes()
->where('tenant_id', $this->tenantId)
->delete();
$this->seedCategoryGroups();
});
$count = CategoryGroup::withoutGlobalScopes()
->where('tenant_id', $this->tenantId)
->count();
$this->command->info("카테고리 그룹 시딩 완료! (총 {$count}개)");
}
protected function seedCategoryGroups(): void
{
$groups = [
[
'code' => CategoryGroup::CODE_AREA_BASED,
'name' => '면적기반',
'multiplier_variable' => CategoryGroup::MULTIPLIER_AREA,
'categories' => ['원단', '패널', '도장', '표면처리', '스크린원단'],
'description' => '면적(㎡)을 기준으로 단가를 계산합니다. 최종단가 = 기본단가 × M(면적)',
'sort_order' => 1,
],
[
'code' => CategoryGroup::CODE_WEIGHT_BASED,
'name' => '중량기반',
'multiplier_variable' => CategoryGroup::MULTIPLIER_WEIGHT,
'categories' => ['강판', '알루미늄', '스테인리스', '철재'],
'description' => '중량(kg)을 기준으로 단가를 계산합니다. 최종단가 = 기본단가 × K(중량)',
'sort_order' => 2,
],
[
'code' => CategoryGroup::CODE_QUANTITY_BASED,
'name' => '수량기반',
'multiplier_variable' => null,
'categories' => ['볼트', '너트', '와셔', '앵커', '모터', '제어반', '리모컨', '스위치', '전선', '가이드레일', '케이스', '커버', '브라켓', '실링재', '패킹'],
'description' => '수량을 기준으로 단가를 계산합니다. 최종단가 = 기본단가 (곱셈 없음)',
'sort_order' => 3,
],
];
foreach ($groups as $group) {
CategoryGroup::create([
'tenant_id' => $this->tenantId,
'code' => $group['code'],
'name' => $group['name'],
'multiplier_variable' => $group['multiplier_variable'],
'categories' => $group['categories'],
'description' => $group['description'],
'sort_order' => $group['sort_order'],
'is_active' => true,
]);
}
}
}