feat(performance): 카페24 일별 매출내역 붙여넣기로 날짜별 한 번에 비교
카페24 화면과 몇몇 날짜만 안 맞는데 어느 날·어느 쪽(결제/환불)인지,
저장값이 예전 규칙이라서인지 규칙 자체가 틀린 건지 구분할 방법이 없었다.
- GET /performance/api/marketplaces/{code}/daily-check?from=&to=&live=1 (관리자, 62일)
db = 저장된 날짜별 결제합계·결제 건수·환불합계(c24: 사건 전체 = 카페24 화면 범위)
live = 지금 API·현재 규칙으로 다시 계산(adapter.collect, 저장 안 함)
- 설정 → 카페24 매출 대조 카드에 "일별 한 번에 비교": 카페24 표 붙여넣기 →
날짜별 차이(저장값/API), 판정(일치 / 다시 가져오면 해결 / 규칙 차이(결제·환불)),
[다시 가져오기] 버튼, 날짜 클릭 시 그날 상세 대조
- 테스트 추가
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -210,3 +210,8 @@ td.is-link:hover { background: #eef2ff; text-decoration: underline; }
|
||||
}
|
||||
|
||||
.perf-table tr.perf-row-match > *{background:#e7f6ec;font-weight:600}
|
||||
.perf-paste { width: 100%; min-height: 96px; font-family: ui-monospace, Consolas, monospace; font-size: 12px; white-space: pre; resize: vertical; box-sizing: border-box; }
|
||||
.perf-table tr.perf-row-diff > * { background: #fff7f5; }
|
||||
.perf-diff-bad { color: var(--perf-down); font-weight: 600; }
|
||||
.perf-diff-ok { color: #0f8a3a; }
|
||||
.perf-link { background: none; border: 0; padding: 0; color: inherit; font: inherit; text-decoration: underline dotted; cursor: pointer; }
|
||||
|
||||
@@ -663,6 +663,110 @@
|
||||
} finally { recon.disabled = false; }
|
||||
});
|
||||
|
||||
// ── 일별 한 번에 비교 — 카페24 일별 매출내역 붙여넣기 ↔ 저장값 ↔ 지금 API 값 ──
|
||||
// 붙여넣은 한 줄: "2026-09-29(화) 주문수 품목수 … 결제합계 환불합계 순매출" — 뒤의 세 숫자와 첫 숫자(주문수)만 쓴다.
|
||||
function parseDaily(text) {
|
||||
const out = {};
|
||||
String(text || "").split(/\r?\n/).forEach(function (line) {
|
||||
const m = line.match(/(\d{4})[-./](\d{2})[-./](\d{2})/);
|
||||
if (!m) return;
|
||||
const nums = (line.slice(m.index + m[0].length).match(/-?\d[\d,]*/g) || [])
|
||||
.map(function (x) { return parseInt(x.replace(/,/g, ""), 10); });
|
||||
if (nums.length < 3) return;
|
||||
const n = nums.length;
|
||||
out[m[1] + "-" + m[2] + "-" + m[3]] = { orders: n >= 13 ? nums[0] : null, paid: nums[n - 3], refund: nums[n - 2], net: nums[n - 1] };
|
||||
});
|
||||
return out;
|
||||
}
|
||||
const dailyBtn = document.getElementById("perf-daily-check");
|
||||
if (dailyBtn) dailyBtn.addEventListener("click", async function () {
|
||||
const out = document.getElementById("perf-daily-result");
|
||||
const shop = parseDaily(document.getElementById("perf-daily-paste").value);
|
||||
const dates = Object.keys(shop).sort();
|
||||
if (!dates.length) { out.innerHTML = '<p class="perf-notice is-warn">날짜가 있는 줄을 찾지 못했습니다. 카페24 일별 매출내역 표를 복사해 붙여 넣으세요.</p>'; return; }
|
||||
const live = document.getElementById("perf-daily-live").checked;
|
||||
dailyBtn.disabled = true;
|
||||
out.innerHTML = '<p class="perf-muted">' + (live ? "저장값과 카페24 API 값을 계산하는 중… (기간이 길면 1~2분)" : "저장값을 불러오는 중…") + "</p>";
|
||||
try {
|
||||
const from = dates[0], to = dates[dates.length - 1];
|
||||
const r = await api("GET", "/performance/api/marketplaces/cafe24/daily-check?from=" + from + "&to=" + to + (live ? "&live=1" : ""));
|
||||
if (!r.ok) { out.innerHTML = '<p class="perf-notice is-warn">' + esc(r.message) + "</p>"; return; }
|
||||
const byDate = function (rows) { const o = {}; (rows || []).forEach(function (x) { o[x.date] = x; }); return o; };
|
||||
const db = byDate(r.db), lv = r.live ? byDate(r.live) : null;
|
||||
const zero = { paid: 0, refund: 0, orders: 0 };
|
||||
const diff = function (ours, theirs) {
|
||||
const d = ours - theirs;
|
||||
return d === 0 ? '<span class="perf-diff-ok">✓</span>' : '<span class="perf-diff-bad">' + (d > 0 ? "+" : "") + fmt(d) + "</span>";
|
||||
};
|
||||
const todayIso = today();
|
||||
let bad = 0, stale = 0, rule = 0;
|
||||
const sum = { cp: 0, cr: 0, dp: 0, dr: 0, lp: 0, lr: 0 };
|
||||
const body = dates.slice().reverse().map(function (d) {
|
||||
const c = shop[d], x = db[d] || zero, l = lv ? (lv[d] || zero) : null;
|
||||
sum.cp += c.paid; sum.cr += c.refund; sum.dp += x.paid; sum.dr += x.refund;
|
||||
if (l) { sum.lp += l.paid; sum.lr += l.refund; }
|
||||
const dbOk = x.paid === c.paid && x.refund === c.refund;
|
||||
const liveOk = l && l.paid === c.paid && l.refund === c.refund;
|
||||
let verdict;
|
||||
if (dbOk) verdict = '<span class="perf-pill is-ok">일치</span>';
|
||||
else if (l && liveOk) { verdict = '<span class="perf-pill">다시 가져오면 해결</span>'; stale++; }
|
||||
else if (l) {
|
||||
const what = [l.paid !== c.paid ? "결제" : "", l.refund !== c.refund ? "환불" : ""].filter(Boolean).join("·");
|
||||
verdict = '<span class="perf-pill is-bad">규칙 차이(' + what + ")</span>"; rule++;
|
||||
} else verdict = '<span class="perf-pill is-bad">차이</span>';
|
||||
if (!dbOk) bad++;
|
||||
const wd = "일월화수목금토"[new Date(d + "T00:00:00").getDay()];
|
||||
return "<tr" + (dbOk ? "" : ' class="perf-row-diff"') + '><td class="perf-td-label"><button type="button" class="perf-link" data-recon-day="' + d + '">' +
|
||||
esc(d) + "(" + wd + ")</button>" + (d === todayIso ? ' <span class="perf-muted">오늘·집계 중</span>' : "") + "</td>" +
|
||||
'<td class="perf-num">' + (c.orders == null ? "–" : fmt(c.orders)) + ' <span class="perf-muted">/ ' + fmt(x.orders) + (l ? " / " + fmt(l.orders) : "") + "</span></td>" +
|
||||
'<td class="perf-num">' + won(c.paid) + '</td><td class="perf-num">' + diff(x.paid, c.paid) + "</td>" + (l ? '<td class="perf-num">' + diff(l.paid, c.paid) + "</td>" : "") +
|
||||
'<td class="perf-num">' + won(c.refund) + '</td><td class="perf-num">' + diff(x.refund, c.refund) + "</td>" + (l ? '<td class="perf-num">' + diff(l.refund, c.refund) + "</td>" : "") +
|
||||
"<td>" + verdict + (x.synced_at ? '<div class="perf-muted" style="font-size:11px">저장 ' + esc(String(x.synced_at).slice(5, 16).replace("T", " ")) + "</div>" : "") + "</td></tr>";
|
||||
}).join("");
|
||||
const head = '<tr><th class="perf-th-label">날짜</th><th>주문수 <span class="perf-muted">카페24 / 저장' + (lv ? " / API" : "") + "</span></th>" +
|
||||
"<th>결제합계(카페24)</th><th>저장값 차이</th>" + (lv ? "<th>API 차이</th>" : "") +
|
||||
"<th>환불합계(카페24)</th><th>저장값 차이</th>" + (lv ? "<th>API 차이</th>" : "") + '<th class="perf-th-label">판정</th></tr>';
|
||||
const foot = '<tr class="perf-row-week"><th class="perf-td-label">합계</th><td></td><td class="perf-num">' + won(sum.cp) + '</td><td class="perf-num">' +
|
||||
diff(sum.dp, sum.cp) + "</td>" + (lv ? '<td class="perf-num">' + diff(sum.lp, sum.cp) + "</td>" : "") + '<td class="perf-num">' + won(sum.cr) +
|
||||
'</td><td class="perf-num">' + diff(sum.dr, sum.cr) + "</td>" + (lv ? '<td class="perf-num">' + diff(sum.lr, sum.cr) + "</td>" : "") + "<td></td></tr>";
|
||||
const summary = bad
|
||||
? "저장값이 다른 날 " + bad + "일" + (lv ? " — 다시 가져오면 해결 " + stale + "일, 규칙 차이 " + rule + "일" : " — [API 값도 계산]을 켜고 다시 비교하면 원인을 나눠 볼 수 있습니다")
|
||||
: "모든 날짜가 일치합니다.";
|
||||
out.innerHTML = '<p class="perf-notice ' + (bad ? "is-warn" : "is-ok") + '" style="margin-top:8px">' + esc(summary) +
|
||||
(r.live_error ? "<br>API 계산 실패: " + esc(r.live_error) : "") + "</p>" +
|
||||
(stale ? '<div class="perf-sample-form"><button type="button" class="erp-btn erp-btn-primary" id="perf-daily-resync" data-from="' + from +
|
||||
'" data-to="' + to + '">' + esc(from + " ~ " + to) + " 카페24 다시 가져오기</button></div>" : "") +
|
||||
'<table class="perf-table" style="margin-top:8px"><thead>' + head + "</thead><tbody>" + body + "</tbody><tfoot>" + foot + "</tfoot></table>" +
|
||||
'<p class="perf-foot perf-muted">차이 = 우리 값 − 카페24 값. 저장값은 카페24 열과 카페24 경유 다른 마켓 열을 합친 금액(카페24 화면과 같은 범위)입니다.</p>';
|
||||
} catch (err) {
|
||||
out.innerHTML = '<p class="perf-notice is-warn">' + esc(err.message) + "</p>";
|
||||
} finally { dailyBtn.disabled = false; }
|
||||
});
|
||||
const dailyOut = document.getElementById("perf-daily-result");
|
||||
if (dailyOut) dailyOut.addEventListener("click", async function (e) {
|
||||
const dayBtn = e.target.closest("[data-recon-day]");
|
||||
if (dayBtn && recon) {
|
||||
document.getElementById("perf-recon-date").value = dayBtn.dataset.reconDay;
|
||||
recon.click();
|
||||
recon.scrollIntoView({ behavior: "smooth", block: "center" });
|
||||
return;
|
||||
}
|
||||
const rs = e.target.closest("#perf-daily-resync");
|
||||
if (!rs) return;
|
||||
if (!(await confirmMsg(rs.dataset.from + " ~ " + rs.dataset.to + " 카페24 매출을 지금 규칙으로 다시 가져옵니다."))) return;
|
||||
rs.disabled = true;
|
||||
rs.textContent = "가져오는 중…";
|
||||
try {
|
||||
const res = await api("POST", "/performance/api/sync", { from: rs.dataset.from, to: rs.dataset.to, codes: ["cafe24"] });
|
||||
const r0 = (res.results || [])[0];
|
||||
if (r0 && !r0.ok) throw new Error((r0.label || r0.status) + ": " + (r0.message || ""));
|
||||
dailyBtn.click();
|
||||
} catch (err) {
|
||||
alertMsg("다시 가져오기 실패: " + err.message);
|
||||
rs.disabled = false;
|
||||
}
|
||||
});
|
||||
|
||||
// ── 과거 매출 가져오기(기간 지정 수집, 관리자) ──
|
||||
const backfill = document.getElementById("perf-backfill");
|
||||
if (backfill) backfill.addEventListener("click", async function () {
|
||||
|
||||
Reference in New Issue
Block a user