패키지 추가 버튼 시인성 개선 및 UI 보정~
This commit is contained in:
@@ -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
|
||||
];
|
||||
|
||||
if ($row['item_type'] === 'model') {
|
||||
$dynamicModels[] = $item;
|
||||
} else if ($row['item_type'] === 'package') {
|
||||
$item['type'] = 'package';
|
||||
$dynamicPackages[] = $item;
|
||||
}
|
||||
}
|
||||
|
||||
// package_types의 'select_models' 항목 찾아서 업데이트
|
||||
foreach ($response['sales_config']['package_types'] as &$pkg) {
|
||||
if ($pkg['id'] === 'select_models') {
|
||||
$pkg['models'] = $dynamicModels;
|
||||
break;
|
||||
}
|
||||
// 새로운 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) {
|
||||
|
||||
@@ -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;
|
||||
|
||||
54
salesmanagement/api/seed_packages.php
Normal file
54
salesmanagement/api/seed_packages.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/../../lib/mydb.php';
|
||||
|
||||
try {
|
||||
$pdo = db_connect();
|
||||
|
||||
// Check if package_pricing has any packages
|
||||
$stmt = $pdo->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();
|
||||
}
|
||||
?>
|
||||
@@ -1340,9 +1340,19 @@
|
||||
</div>
|
||||
|
||||
{/* 패키지 카드 그리드 */}
|
||||
{packages.length > 0 && (
|
||||
<div>
|
||||
<h4 className="text-lg font-semibold text-slate-700 mb-4">패키지</h4>
|
||||
<div className="mt-8">
|
||||
<div className="flex items-center justify-between mb-4 p-3 bg-slate-50 rounded-xl">
|
||||
<h4 className="text-lg font-bold text-slate-800">패키지 관리</h4>
|
||||
<button
|
||||
onClick={() => handleAddItem('package')}
|
||||
className="px-4 py-2 bg-blue-600 text-white rounded-lg text-sm font-bold hover:bg-blue-700 transition-colors shadow-sm flex items-center gap-2"
|
||||
>
|
||||
<LucideIcon name="plus" className="w-4 h-4" />
|
||||
[ + 패키지 추가 ]
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{packages.length > 0 ? (
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||
{packages.map(item => (
|
||||
<div key={`${item.item_type}_${item.item_id}`} className="bg-white rounded-lg p-5 shadow-sm border border-slate-200 hover:shadow-md transition-shadow">
|
||||
@@ -1392,8 +1402,12 @@
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
) : (
|
||||
<div className="text-center py-8 text-slate-400 bg-slate-50 rounded-xl border border-dashed border-slate-300">
|
||||
등록된 패키지가 없습니다.
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* 편집 모달 */}
|
||||
{editModalOpen && editingItem && (
|
||||
|
||||
Reference in New Issue
Block a user