From 2d1dc8f9ba89fe6c419352ecac99403b2187d0b1 Mon Sep 17 00:00:00 2001 From: kimbokon Date: Sun, 4 Jan 2026 21:44:45 +0900 Subject: [PATCH] =?UTF-8?q?=ED=8C=A8=ED=82=A4=EC=A7=80=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80=20=EB=B2=84=ED=8A=BC=20=EC=8B=9C=EC=9D=B8=EC=84=B1=20?= =?UTF-8?q?=EA=B0=9C=EC=84=A0=20=EB=B0=8F=20UI=20=EB=B3=B4=EC=A0=95~?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- salesmanagement/api/company_info.php | 48 +++++++++++++++------- salesmanagement/api/package_pricing.php | 8 ++-- salesmanagement/api/seed_packages.php | 54 +++++++++++++++++++++++++ salesmanagement/index.php | 24 ++++++++--- 4 files changed, 111 insertions(+), 23 deletions(-) create mode 100644 salesmanagement/api/seed_packages.php diff --git a/salesmanagement/api/company_info.php b/salesmanagement/api/company_info.php index ced20c6..340919d 100644 --- a/salesmanagement/api/company_info.php +++ b/salesmanagement/api/company_info.php @@ -663,20 +663,22 @@ $response = [ ] ]; -// DB에서 동적 모델 데이터 로드 시도 (package_pricing 테이블 사용) +// DB에서 동적 모델 및 패키지 데이터 로드 시도 (package_pricing 테이블 사용) require_once __DIR__ . '/../../lib/mydb.php'; try { $pdo = db_connect(); // 테이블 존재 확인 및 데이터 조회 $check = $pdo->query("SHOW TABLES LIKE 'package_pricing'"); if ($check->rowCount() > 0) { - $stmt = $pdo->prepare("SELECT * FROM package_pricing WHERE item_type = 'model' AND is_active = 1 ORDER BY id ASC"); + $stmt = $pdo->prepare("SELECT * FROM package_pricing WHERE is_active = 1 ORDER BY id ASC"); $stmt->execute(); - $dbModels = $stmt->fetchAll(PDO::FETCH_ASSOC); + $dbItems = $stmt->fetchAll(PDO::FETCH_ASSOC); - if (!empty($dbModels)) { + if (!empty($dbItems)) { $dynamicModels = []; - foreach ($dbModels as $row) { + $dynamicPackages = []; + + foreach ($dbItems as $row) { // commission_rates JSON 파싱 $rates = json_decode($row['commission_rates'] ?? '{}', true); if (empty($rates)) { @@ -687,26 +689,42 @@ try { ]; } - $dynamicModels[] = [ - "id" => $row['item_id'], // unique_id 역할 - "db_id" => $row['id'], + $item = [ + "id" => $row['item_id'], "name" => $row['item_name'], "sub_name" => $row['sub_name'], - "total_amount" => (int)$row['total_amount'], "join_fee" => (int)$row['join_fee'], "subscription_fee" => (int)$row['subscription_fee'], + "total_amount" => (int)$row['total_amount'], "discretion_allowed" => (bool)$row['allow_flexible_pricing'], "commission_rates" => $rates ]; - } - // package_types의 'select_models' 항목 찾아서 업데이트 - foreach ($response['sales_config']['package_types'] as &$pkg) { - if ($pkg['id'] === 'select_models') { - $pkg['models'] = $dynamicModels; - break; + if ($row['item_type'] === 'model') { + $dynamicModels[] = $item; + } else if ($row['item_type'] === 'package') { + $item['type'] = 'package'; + $dynamicPackages[] = $item; } } + + // 새로운 package_types 구성 + $newPackageTypes = []; + + // 1. 선택 모델 추가 + $newPackageTypes[] = [ + "id" => "select_models", + "name" => "선택모델", + "type" => "checkbox", + "models" => $dynamicModels + ]; + + // 2. 패키지 항목들 추가 + foreach ($dynamicPackages as $pkg) { + $newPackageTypes[] = $pkg; + } + + $response['sales_config']['package_types'] = $newPackageTypes; } } } catch (Exception $e) { diff --git a/salesmanagement/api/package_pricing.php b/salesmanagement/api/package_pricing.php index 95a1c67..b880a4c 100644 --- a/salesmanagement/api/package_pricing.php +++ b/salesmanagement/api/package_pricing.php @@ -69,13 +69,15 @@ try { $sub_name = $data['sub_name'] ?? null; $join_fee = floatval($data['join_fee'] ?? 0); $subscription_fee = floatval($data['subscription_fee'] ?? 0); + $total_amount = isset($data['total_amount']) ? floatval($data['total_amount']) : null; + $allow_flexible_pricing = intval($data['allow_flexible_pricing'] ?? 1); $commission_rates = isset($data['commission_rates']) ? json_encode($data['commission_rates'], JSON_UNESCAPED_UNICODE) : null; $stmt = $pdo->prepare(" - INSERT INTO package_pricing (item_type, item_id, item_name, sub_name, join_fee, subscription_fee, commission_rates) - VALUES (?, ?, ?, ?, ?, ?, ?) + INSERT INTO package_pricing (item_type, item_id, item_name, sub_name, join_fee, subscription_fee, total_amount, allow_flexible_pricing, commission_rates) + VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?) "); - $stmt->execute([$item_type, $item_id, $item_name, $sub_name, $join_fee, $subscription_fee, $commission_rates]); + $stmt->execute([$item_type, $item_id, $item_name, $sub_name, $join_fee, $subscription_fee, $total_amount, $allow_flexible_pricing, $commission_rates]); echo json_encode(['success' => true, 'message' => '항목이 생성되었습니다.', 'id' => $pdo->lastInsertId()], JSON_UNESCAPED_UNICODE); break; diff --git a/salesmanagement/api/seed_packages.php b/salesmanagement/api/seed_packages.php new file mode 100644 index 0000000..17f07ed --- /dev/null +++ b/salesmanagement/api/seed_packages.php @@ -0,0 +1,54 @@ +query("SELECT COUNT(*) FROM package_pricing WHERE item_type = 'package' AND is_active = 1"); + if ($stmt->fetchColumn() == 0) { + $initialPackages = [ + [ + "item_type" => "package", + "item_id" => "construction_management", + "item_name" => "공사관리", + "sub_name" => "패키지", + "total_amount" => 0, + "join_fee" => 40000000, + "subscription_fee" => 200000, + "allow_flexible_pricing" => 0 + ], + [ + "item_type" => "package", + "item_id" => "process_government", + "item_name" => "공정/정부지원사업", + "sub_name" => "패키지", + "total_amount" => 0, + "join_fee" => 80000000, + "subscription_fee" => 400000, + "allow_flexible_pricing" => 0 + ] + ]; + + $stmt = $pdo->prepare("INSERT INTO package_pricing (item_type, item_id, item_name, sub_name, total_amount, join_fee, subscription_fee, allow_flexible_pricing) VALUES (?, ?, ?, ?, ?, ?, ?, ?)"); + + foreach ($initialPackages as $item) { + $stmt->execute([ + $item['item_type'], + $item['item_id'], + $item['item_name'], + $item['sub_name'], + $item['total_amount'], + $item['join_fee'], + $item['subscription_fee'], + $item['allow_flexible_pricing'] + ]); + } + echo "Packages seeded successfully.\n"; + } else { + echo "Packages already exist.\n"; + } +} catch (Exception $e) { + echo "Error: " . $e->getMessage(); +} +?> diff --git a/salesmanagement/index.php b/salesmanagement/index.php index 0965da1..224cc74 100644 --- a/salesmanagement/index.php +++ b/salesmanagement/index.php @@ -1340,9 +1340,19 @@ {/* 패키지 카드 그리드 */} - {packages.length > 0 && ( -
-

패키지

+
+
+

패키지 관리

+ +
+ + {packages.length > 0 ? (
{packages.map(item => (
@@ -1392,8 +1402,12 @@
))}
-
- )} + ) : ( +
+ 등록된 패키지가 없습니다. +
+ )} +
{/* 편집 모달 */} {editModalOpen && editingItem && (