From 595d57ce31e74b4bc2d0952fc6e157c3159b43af Mon Sep 17 00:00:00 2001 From: kent Date: Mon, 29 Dec 2025 21:43:28 +0900 Subject: [PATCH] =?UTF-8?q?feat(seeder):=20=EC=8B=9C=EB=AE=AC=EB=A0=88?= =?UTF-8?q?=EC=9D=B4=ED=84=B0=EC=9A=A9=20=EB=8B=A8=EA=B0=80=20=EC=8B=9C?= =?UTF-8?q?=EB=8D=94=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - DesignPriceSeeder 생성 - items.attributes.salesPrice → prices 테이블 마이그레이션 - 85개 품목 단가 데이터 추가 완료 - 대상: SF-SCR-%, SF-STL-%, SF-BND-%, SM-%, RM-% 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- database/seeders/DesignPriceSeeder.php | 111 +++++++++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100644 database/seeders/DesignPriceSeeder.php diff --git a/database/seeders/DesignPriceSeeder.php b/database/seeders/DesignPriceSeeder.php new file mode 100644 index 00000000..ab54a32d --- /dev/null +++ b/database/seeders/DesignPriceSeeder.php @@ -0,0 +1,111 @@ +command->info('시뮬레이터 단가 시딩 시작...'); + + DB::transaction(function () { + $this->seedPricesFromItems(); + }); + + $count = Price::where('tenant_id', $this->tenantId) + ->where('status', Price::STATUS_ACTIVE) + ->count(); + $this->command->info("단가 시딩 완료! (총 {$count}개 active)"); + } + + protected function seedPricesFromItems(): void + { + // 시뮬레이터용 품목 코드 패턴 + $patterns = [ + 'SF-SCR-%', // 스크린 반제품 + 'SF-STL-%', // 철재 반제품 + 'SF-BND-%', // 절곡 반제품 + 'SM-%', // 부자재 + 'RM-%', // 원자재 + ]; + + $query = DB::table('items') + ->where('tenant_id', $this->tenantId) + ->whereNull('deleted_at') + ->where(function ($q) use ($patterns) { + foreach ($patterns as $pattern) { + $q->orWhere('code', 'like', $pattern); + } + }); + + $items = $query->get(); + $created = 0; + $skipped = 0; + + foreach ($items as $item) { + $attributes = json_decode($item->attributes, true) ?? []; + $salesPrice = $attributes['salesPrice'] ?? 0; + + if ($salesPrice <= 0) { + $skipped++; + continue; + } + + // 기존 active 단가 확인 + $existingPrice = Price::where('tenant_id', $this->tenantId) + ->where('item_id', $item->id) + ->where('item_type_code', $item->item_type) + ->where('status', Price::STATUS_ACTIVE) + ->first(); + + if ($existingPrice) { + // 기존 단가 업데이트 + $existingPrice->update([ + 'sales_price' => $salesPrice, + 'updated_by' => 1, + ]); + $this->command->line(" 업데이트: {$item->code} => " . number_format($salesPrice)); + } else { + // 새 단가 생성 + Price::create([ + 'tenant_id' => $this->tenantId, + 'item_type_code' => $item->item_type, + 'item_id' => $item->id, + 'client_group_id' => null, + 'purchase_price' => $salesPrice * 0.7, // 매입가 추정 (70%) + 'processing_cost' => 0, + 'loss_rate' => 0, + 'margin_rate' => 30, // 마진율 30% + 'sales_price' => $salesPrice, + 'rounding_rule' => Price::ROUNDING_ROUND, + 'rounding_unit' => 100, + 'effective_from' => now()->toDateString(), + 'effective_to' => null, + 'note' => 'Design 시뮬레이터 연동 데이터', + 'status' => Price::STATUS_ACTIVE, + 'is_final' => false, + 'created_by' => 1, + ]); + $created++; + $this->command->line(" 생성: {$item->code} => " . number_format($salesPrice)); + } + } + + $this->command->info(" 생성: {$created}개, 스킵(단가없음): {$skipped}개"); + } +} \ No newline at end of file