feat(performance): 카페24 주문 매출 수집 연동 + 과거 매출 가져오기

카페24 (Admin API GET /admin/orders, 문서 2026-09-01 기준)
- 결제(SALE): date_type=pay_date, embed=items — 결제된 주문의 품목 결제금액(할인 반영·배송비 제외), 결제일
- 취소(CANCEL): cancel_complete_date, 품목 C40~C43 만 음수(입금전취소 C47~C49 제외)
- 반품(RETURN): return_complete_date, 품목 R40~R43 음수, 부분 반품은 claim_quantity 비율
- 자체몰 주문만(market_id=self) — 카페24로 연동된 다른 마켓 주문은 이중 집계 방지로 제외
- 60일 단위 분할(한 호출 3개월 미만), limit 1000 페이지 넘김, 개인정보 미저장(raw 는 금액·상태만)
- 기존 app/integrations/cafe24 토큰·클라이언트 재사용, 연결 테스트는 주문 권한까지 확인
- DEFAULT_SCOPES 에 mall.read_order 추가(읽기만) — 카페24 상품관리 → 시스템에서 재연결 필요

과거 매출 가져오기(설정, 관리자): 기간 지정 수집(최대 366일), 일반 사용자는 403

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-09-29 16:25:25 +09:00
parent 6e175d0bac
commit 04a1fddd95
9 changed files with 414 additions and 32 deletions
+40
View File
@@ -470,6 +470,46 @@
} finally { btn.disabled = false; btn.textContent = label; }
}
// ── 과거 매출 가져오기(기간 지정 수집, 관리자) ──
const backfill = document.getElementById("perf-backfill");
if (backfill) backfill.addEventListener("click", async function () {
const from = document.getElementById("perf-backfill-from").value;
const to = document.getElementById("perf-backfill-to").value;
const box = document.getElementById("perf-backfill-result");
if (!from || !to) return;
if (!(await confirmMsg(from + " ~ " + to + " 매출을 연동된 쇼핑몰에서 가져옵니다. 기간이 길면 몇 분 걸릴 수 있습니다."))) return;
const names = {};
root.querySelectorAll("tr[data-code]").forEach(function (tr) { names[tr.dataset.code] = tr.dataset.name; });
backfill.disabled = true;
backfill.textContent = "가져오는 중…";
box.hidden = true;
try {
const res = await api("POST", "/performance/api/sync", { from: from, to: to });
const ok = [], bad = [], rest = [];
(res.results || []).forEach(function (r) {
const name = names[r.code] || r.code;
if (r.ok) ok.push(name + " " + fmt(r.upserted) + "건");
else if (r.skipped) rest.push(name + "(이미 진행 중)");
else if (r.status === "not_implemented" || r.status === "not_configured") rest.push(name);
else bad.push(name + "(" + (r.label || r.status) + ": " + (r.message || "") + ")");
});
box.innerHTML = [
ok.length ? "<b>반영</b> " + esc(ok.join(", ")) : "",
bad.length ? "<b>실패</b> " + esc(bad.join(", ")) : "",
rest.length ? '<span class="perf-muted">건너뜀(미연동·미설정): ' + esc(rest.join(", ")) + "</span>" : "",
].filter(Boolean).join(" · ") || "가져올 쇼핑몰이 없습니다.";
box.className = "perf-notice" + (bad.length ? " is-warn" : " is-ok");
box.hidden = false;
} catch (err) {
box.textContent = "가져오기 실패: " + err.message;
box.className = "perf-notice is-warn";
box.hidden = false;
} finally {
backfill.disabled = false;
backfill.textContent = "가져오기";
}
});
// ── 테스트 데이터 / 재암호화 ──
const gen = document.getElementById("perf-sample-gen");
if (gen) gen.addEventListener("click", async function () {