fix(performance): 카페24 매출을 카페24 "일별 매출내역" 기준으로(결제합계·환불합계) + 매출 대조 도구
원인: 품목 결제금액(배송비 제외)을 매출로, 취소·반품 완료일의 품목 금액을 환불로 잡아 카페24 화면(결제합계 = 상품구매금액 + 배송비 − 할인 − 쿠폰, 환불합계 = 환불완료일 실제 환불액)과 달랐다. - SALE: 결제일 기준 주문 단위 결제합계(initial_order_amount — 결제 당시 금액) - CANCEL/RETURN: GET /admin/refunds 환불완료일, 실제 환불액(환불코드 R=반품) - 환불도 원 주문 market_id 로 자체몰만(다른 마켓 연동 주문 제외) - 기간 교체(replace_range): 동기화한 기간의 카페24 실데이터를 지우고 새로 넣음(한 트랜잭션, 테스트 데이터 제외) — 예전 품목 단위 행이 남아 이중 집계되지 않게 - 설정 화면 "카페24 매출 대조": 날짜별로 카페24 화면 열 순서대로 원천 금액 합산(자체몰/마켓 구분, 저장 안 함) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -470,6 +470,60 @@
|
||||
} finally { btn.disabled = false; btn.textContent = label; }
|
||||
}
|
||||
|
||||
// ── 카페24 매출 대조 — 카페24 "일별 매출내역" 열 순서대로 ──
|
||||
const recon = document.getElementById("perf-recon");
|
||||
if (recon) recon.addEventListener("click", async function () {
|
||||
const day = document.getElementById("perf-recon-date").value;
|
||||
const out = document.getElementById("perf-recon-result");
|
||||
if (!day) return;
|
||||
recon.disabled = true;
|
||||
out.innerHTML = '<p class="perf-muted">카페24에서 불러오는 중…</p>';
|
||||
try {
|
||||
const r = await api("GET", "/performance/api/marketplaces/cafe24/reconcile?date=" + encodeURIComponent(day));
|
||||
if (!r.ok) { out.innerHTML = '<p class="perf-notice is-warn">' + esc((r.label ? r.label + " — " : "") + r.message) + "</p>"; return; }
|
||||
const s = r.orders.self, m = r.orders.market, rs = r.refunds.self, rm = r.refunds.market;
|
||||
const disc = ["membership_discount_amount", "set_product_discount_amount", "app_discount_amount",
|
||||
"market_other_discount_amount", "shipping_fee_discount_amount"];
|
||||
const coup = ["coupon_discount_price", "coupon_shipping_fee_amount"];
|
||||
const LABEL = {
|
||||
membership_discount_amount: "회원할인", set_product_discount_amount: "세트상품할인", app_discount_amount: "앱할인",
|
||||
market_other_discount_amount: "마켓 기타할인", shipping_fee_discount_amount: "배송비할인",
|
||||
coupon_discount_price: "상품쿠폰", coupon_shipping_fee_amount: "배송비쿠폰",
|
||||
};
|
||||
const sum = function (g, keys) { return keys.reduce(function (a, k) { return a + (g[k] || 0); }, 0); };
|
||||
const rows = [
|
||||
["주문수", s.orders, m.orders, "cnt"], ["품목수(수량 합계)", s.items, m.items, "cnt"], ["품목수(품목 줄 수)", s.lines, m.lines, "cnt"],
|
||||
["상품구매금액", s.order_price_amount, m.order_price_amount], ["배송비", s.shipping_fee, m.shipping_fee],
|
||||
["할인 합계", sum(s, disc), sum(m, disc)],
|
||||
].concat(disc.map(function (k) { return [" · " + LABEL[k], s[k], m[k], "sub"]; }))
|
||||
.concat([["쿠폰 합계", sum(s, coup), sum(m, coup)]])
|
||||
.concat(coup.map(function (k) { return [" · " + LABEL[k], s[k], m[k], "sub"]; }))
|
||||
.concat([
|
||||
["결제합계(계산)", s.total, m.total, "key"],
|
||||
[" 참고: 실결제금액", s.payment_amount, m.payment_amount, "sub"],
|
||||
[" 참고: 적립금 사용", s.points_spent_amount, m.points_spent_amount, "sub"],
|
||||
[" 참고: 예치금 사용", s.credits_spent_amount, m.credits_spent_amount, "sub"],
|
||||
["환불 건수", rs.count, rm.count, "cnt"],
|
||||
["환불합계(실제 환불액)", rs.actual_refund_amount, rm.actual_refund_amount, "key"],
|
||||
[" 참고: 환불 적립금", rs.used_points, rm.used_points, "sub"],
|
||||
[" 참고: 환불 예치금", rs.used_credits, rm.used_credits, "sub"],
|
||||
["순매출(결제합계 − 환불합계)", s.total - rs.actual_refund_amount, m.total - rm.actual_refund_amount, "key"],
|
||||
]);
|
||||
out.innerHTML = '<table class="perf-table" style="margin-top:8px"><thead><tr><th class="perf-th-label">' + esc(r.date) +
|
||||
"</th><th>자체몰(실적 반영)</th><th>다른 마켓 연동(제외)</th></tr></thead><tbody>" +
|
||||
rows.map(function (x) {
|
||||
const cls = x[3] === "key" ? ' class="perf-row-week"' : "";
|
||||
const f = function (v) { return x[3] === "cnt" ? fmt(v) : won(v); };
|
||||
return "<tr" + cls + '><th class="perf-td-label' + (x[3] === "sub" ? " perf-muted" : "") + '">' + esc(x[0]) +
|
||||
'</th><td class="perf-num">' + f(x[1]) + '</td><td class="perf-num">' + f(x[2]) + "</td></tr>";
|
||||
}).join("") + "</tbody></table>" +
|
||||
'<p class="perf-foot perf-muted">' + esc(r.formula) + ". 미결제 주문 " + fmt(r.unpaid_orders) +
|
||||
"건 제외. 카페24 화면과 다른 줄이 있으면 알려 주세요 — 규칙을 맞추겠습니다.</p>";
|
||||
} catch (err) {
|
||||
out.innerHTML = '<p class="perf-notice is-warn">' + esc(err.message) + "</p>";
|
||||
} finally { recon.disabled = false; }
|
||||
});
|
||||
|
||||
// ── 과거 매출 가져오기(기간 지정 수집, 관리자) ──
|
||||
const backfill = document.getElementById("perf-backfill");
|
||||
if (backfill) backfill.addEventListener("click", async function () {
|
||||
|
||||
Reference in New Issue
Block a user