97 lines
2.5 KiB
PHP
97 lines
2.5 KiB
PHP
<?php
|
|
header("Content-Type: application/json; charset=utf-8");
|
|
|
|
// -------------------------------------------
|
|
// DB 연결 (네가 스케줄 등 다른 페이지에서 쓰는 방식 그대로)
|
|
// -------------------------------------------
|
|
$pdo = new PDO(
|
|
"mysql:host=localhost;dbname=egbim;charset=utf8mb4",
|
|
"egbim",
|
|
"baron3840!!",
|
|
[
|
|
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
|
|
]
|
|
);
|
|
|
|
$action = $_REQUEST['action'] ?? '';
|
|
$issue_month = $_REQUEST['issue_month'] ?? '';
|
|
$issue_text = $_REQUEST['issue_text'] ?? '';
|
|
|
|
/*
|
|
테이블: sales_month_issues
|
|
id (PK)
|
|
issue_month (CHAR 7) 예: 2025-12
|
|
issue_text (TEXT)
|
|
created_at (DATETIME)
|
|
updated_at (DATETIME)
|
|
*/
|
|
|
|
// -------------------------------------------
|
|
// 📌 1) 주요 이슈 조회
|
|
// -------------------------------------------
|
|
if ($action === 'get') {
|
|
|
|
$stmt = $pdo->prepare("
|
|
SELECT issue_text
|
|
FROM sales_month_issues
|
|
WHERE issue_month = :m
|
|
LIMIT 1
|
|
");
|
|
$stmt->execute([":m" => $issue_month]);
|
|
$row = $stmt->fetch(PDO::FETCH_ASSOC);
|
|
|
|
echo json_encode([
|
|
"issue_text" => $row['issue_text'] ?? ""
|
|
]);
|
|
exit;
|
|
}
|
|
|
|
|
|
// -------------------------------------------
|
|
// 📌 2) 주요 이슈 저장 (UPDATE / INSERT)
|
|
// -------------------------------------------
|
|
if ($action === 'save') {
|
|
|
|
// 같은 month가 있는지 체크
|
|
$stmt = $pdo->prepare("
|
|
SELECT id FROM sales_month_issues WHERE issue_month = :m LIMIT 1
|
|
");
|
|
$stmt->execute([":m" => $issue_month]);
|
|
$row = $stmt->fetch(PDO::FETCH_ASSOC);
|
|
|
|
if ($row) {
|
|
// UPDATE
|
|
$stmt = $pdo->prepare("
|
|
UPDATE sales_month_issues
|
|
SET issue_text = :t,
|
|
updated_at = NOW()
|
|
WHERE id = :id
|
|
");
|
|
$stmt->execute([
|
|
":t" => $issue_text,
|
|
":id" => $row['id']
|
|
]);
|
|
|
|
} else {
|
|
// INSERT
|
|
$stmt = $pdo->prepare("
|
|
INSERT INTO sales_month_issues (issue_month, issue_text, created_at, updated_at)
|
|
VALUES (:m, :t, NOW(), NOW())
|
|
");
|
|
$stmt->execute([
|
|
":m" => $issue_month,
|
|
":t" => $issue_text
|
|
]);
|
|
}
|
|
|
|
echo json_encode(["success" => true]);
|
|
exit;
|
|
}
|
|
|
|
|
|
// -------------------------------------------
|
|
// invalid
|
|
// -------------------------------------------
|
|
echo json_encode(["error" => "invalid_action"]);
|
|
exit;
|