From de10441275bfc18c712f70996067a7c6111be777 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B6=8C=ED=98=81=EC=84=B1?= Date: Wed, 11 Feb 2026 15:58:42 +0900 Subject: [PATCH] =?UTF-8?q?fix(API):=20=EA=B2=BD=EB=8F=99=20=EA=B2=AC?= =?UTF-8?q?=EC=A0=81=20=EC=88=98=EC=8B=9D=20=ED=95=B8=EB=93=A4=EB=9F=AC=20?= =?UTF-8?q?=EA=B0=9C=EC=84=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 4.6 --- .../Handlers/KyungdongFormulaHandler.php | 69 +++++++++++++------ 1 file changed, 48 insertions(+), 21 deletions(-) diff --git a/app/Services/Quote/Handlers/KyungdongFormulaHandler.php b/app/Services/Quote/Handlers/KyungdongFormulaHandler.php index 48a98de..2b1b3c0 100644 --- a/app/Services/Quote/Handlers/KyungdongFormulaHandler.php +++ b/app/Services/Quote/Handlers/KyungdongFormulaHandler.php @@ -63,6 +63,38 @@ public function __construct(?EstimatePriceService $priceService = null) 'EST-ANGLE-BRACKET-철제800K' => 14910, ]; + /** + * items master에서 코드로 아이템 조회 (캐싱 적용, id + name) + * + * @param string $code 아이템 코드 + * @return array{id: int|null, name: string|null} + */ + private function lookupItem(string $code): array + { + static $cache = []; + if (isset($cache[$code])) { + return $cache[$code]; + } + + // 1. 고정 매핑에 ID만 있는 경우 → DB에서 name 조회 + if (isset(self::FIXED_ITEM_MAPPINGS[$code])) { + $fixedId = self::FIXED_ITEM_MAPPINGS[$code]; + $name = \App\Models\Items\Item::where('id', $fixedId)->value('name'); + $cache[$code] = ['id' => $fixedId, 'name' => $name]; + + return $cache[$code]; + } + + // 2. DB에서 동적 조회 (BD-*, EST-* 패턴) + $item = \App\Models\Items\Item::where('tenant_id', self::TENANT_ID) + ->where('code', $code) + ->first(['id', 'name']); + + $cache[$code] = ['id' => $item?->id, 'name' => $item?->name]; + + return $cache[$code]; + } + /** * items master에서 코드로 아이템 ID 조회 (캐싱 적용) * @@ -71,28 +103,14 @@ public function __construct(?EstimatePriceService $priceService = null) */ private function lookupItemId(string $code): ?int { - // 1. 고정 매핑 먼저 확인 - if (isset(self::FIXED_ITEM_MAPPINGS[$code])) { - return self::FIXED_ITEM_MAPPINGS[$code]; - } - - // 2. DB에서 동적 조회 (BD-*, EST-* 패턴) - static $cache = []; - if (isset($cache[$code])) { - return $cache[$code]; - } - - $item = \App\Models\Items\Item::where('tenant_id', self::TENANT_ID) - ->where('code', $code) - ->first(['id']); - - $cache[$code] = $item?->id; - - return $cache[$code]; + return $this->lookupItem($code)['id']; } /** - * 아이템 배열에 item_code/item_id 매핑 추가 + * 아이템 배열에 item_code/item_id 매핑 추가 + 마스터 품목명 적용 + * + * items 마스터에 등록된 품목이면 마스터의 name을 item_name으로 사용하고, + * 미등록 품목이면 하드코딩된 item_name을 그대로 유지 * * @param array $item 아이템 배열 * @param string $code 아이템 코드 @@ -100,10 +118,19 @@ private function lookupItemId(string $code): ?int */ private function withItemMapping(array $item, string $code): array { - return array_merge($item, [ + $looked = $this->lookupItem($code); + + $merged = array_merge($item, [ 'item_code' => $code, - 'item_id' => $this->lookupItemId($code), + 'item_id' => $looked['id'], ]); + + // 마스터에 등록된 품목이면 마스터 name 사용 + if ($looked['name']) { + $merged['item_name'] = $looked['name']; + } + + return $merged; } /**