feat: [상품관리] 카테고리별 최저 개발비/최저 구독료 설정 기능 추가

- 카테고리 관리에서 최저 개발비, 최저 구독료 설정 가능
- 상품 추가/수정 시 최저가 이하 입력 차단 (서버 검증)
- 상품 목록에 최저가 안내 배너 표시 (경고 아이콘)
- 상품 모달에서 실시간 최저가 미달 경고 표시 (빨간 테두리)
This commit is contained in:
김보곤
2026-03-14 11:52:52 +09:00
parent fa2f023ee3
commit bd81eebf07
3 changed files with 237 additions and 10 deletions

View File

@@ -68,6 +68,13 @@ public function store(Request $request): JsonResponse
'is_required' => 'boolean',
]);
// 최저가 검증
$category = SalesProductCategory::findOrFail($validated['category_id']);
$minFeeErrors = $this->validateMinFees($category, $validated);
if ($minFeeErrors) {
return response()->json(['success' => false, 'message' => $minFeeErrors], 422);
}
// 코드 중복 체크
$exists = SalesProduct::where('category_id', $validated['category_id'])
->where('code', $validated['code'])
@@ -115,6 +122,14 @@ public function update(Request $request, int $id): JsonResponse
'is_active' => 'boolean',
]);
// 최저가 검증
$category = $product->category;
$checkData = array_merge($product->toArray(), $validated);
$minFeeErrors = $this->validateMinFees($category, $checkData);
if ($minFeeErrors) {
return response()->json(['success' => false, 'message' => $minFeeErrors], 422);
}
$product->update($validated);
return response()->json([
@@ -224,6 +239,8 @@ public function updateCategory(Request $request, int $id): JsonResponse
'name' => 'sometimes|string|max:100',
'description' => 'nullable|string',
'base_storage' => 'nullable|string|max:20',
'min_development_fee' => 'nullable|numeric|min:0',
'min_subscription_fee' => 'nullable|numeric|min:0',
'is_active' => 'boolean',
]);
@@ -259,6 +276,30 @@ public function deleteCategory(int $id): JsonResponse
]);
}
// ==================== 내부 헬퍼 ====================
/**
* 최저가 검증
*/
private function validateMinFees(SalesProductCategory $category, array $data): ?string
{
$errors = [];
if ($category->min_development_fee > 0 && isset($data['registration_fee'])) {
if ($data['registration_fee'] < $category->min_development_fee) {
$errors[] = '개발비(할인가)는 최저 개발비 ₩'.number_format($category->min_development_fee).' 이상이어야 합니다.';
}
}
if ($category->min_subscription_fee > 0 && isset($data['subscription_fee'])) {
if ($data['subscription_fee'] < $category->min_subscription_fee) {
$errors[] = '월 구독료는 최저 구독료 ₩'.number_format($category->min_subscription_fee).' 이상이어야 합니다.';
}
}
return $errors ? implode(' ', $errors) : null;
}
// ==================== API (영업 시나리오용) ====================
/**