From a7975f72708087f9f20a7be1855c406542770e7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B6=8C=ED=98=81=EC=84=B1?= Date: Wed, 4 Feb 2026 20:30:07 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20ItemService=20update=20=EC=8B=9C=20attri?= =?UTF-8?q?butes=20=EB=A8=B8=EC=A7=80=20=EB=A1=9C=EC=A7=81=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 기존: attributes 전체 덮어쓰기 → 수정: 기존 값 보존 후 새 값만 머지 - 품목 수정 시 레거시 속성(sales_price, legacy 정보 등) 유실 방지 Co-Authored-By: Claude Opus 4.5 --- app/Services/ItemService.php | 21 ++++++++++++- ...000_add_gcs_uri_to_sales_consultations.php | 31 ------------------- 2 files changed, 20 insertions(+), 32 deletions(-) delete mode 100644 database/migrations/2026_02_02_103000_add_gcs_uri_to_sales_consultations.php diff --git a/app/Services/ItemService.php b/app/Services/ItemService.php index 1f56075..9ab0168 100644 --- a/app/Services/ItemService.php +++ b/app/Services/ItemService.php @@ -7,6 +7,8 @@ use App\Models\ItemMaster\ItemPage; use App\Models\Items\Item; use App\Models\Items\ItemDetail; +use App\Models\Products\CommonCode; +use App\Models\Scopes\TenantScope; use Illuminate\Contracts\Pagination\LengthAwarePaginator; use Illuminate\Database\Eloquent\Model; use Symfony\Component\HttpKernel\Exception\BadRequestHttpException; @@ -425,7 +427,18 @@ public function index(array $params): LengthAwarePaginator } } - $paginator = $query->orderBy('id', 'desc')->paginate($size); + // common_codes에서 item_type 한글명 조회 (서브쿼리로 컬럼 충돌 방지) + $tableName = $query->getModel()->getTable(); + $query->addSelect([ + 'item_type_name' => CommonCode::withoutGlobalScope(TenantScope::class) + ->select('name') + ->whereColumn('code', "{$tableName}.item_type") + ->where('code_group', 'item_type') + ->where('is_active', true) + ->limit(1), + ]); + + $paginator = $query->orderBy("{$tableName}.id", 'desc')->paginate($size); // 날짜 형식 변환, files 그룹화, options 펼침, code → item_code $paginator->setCollection( @@ -702,6 +715,12 @@ public function update(int $id, array $data): Model $this->validateBom($data['bom'], $id); } + // attributes 병합 (기존 값 보존, 새 값으로 덮어쓰기) + if (isset($data['attributes']) && is_array($data['attributes'])) { + $existingAttributes = is_array($item->attributes) ? $item->attributes : []; + $data['attributes'] = array_merge($existingAttributes, $data['attributes']); + } + // 테이블 업데이트 $itemData = array_intersect_key($data, array_flip([ 'item_type', 'code', 'name', 'unit', 'category_id', diff --git a/database/migrations/2026_02_02_103000_add_gcs_uri_to_sales_consultations.php b/database/migrations/2026_02_02_103000_add_gcs_uri_to_sales_consultations.php deleted file mode 100644 index cf5248d..0000000 --- a/database/migrations/2026_02_02_103000_add_gcs_uri_to_sales_consultations.php +++ /dev/null @@ -1,31 +0,0 @@ -string('gcs_uri', 500)->nullable()->after('duration')->comment('GCS 저장 URI'); - }); - } - } - - /** - * Reverse the migrations. - */ - public function down(): void - { - Schema::table('sales_consultations', function (Blueprint $table) { - $table->dropColumn('gcs_uri'); - }); - } -};