feat(performance): 카페24 매출 대조에 다른 마켓 연동 주문을 마켓별(market_id·주문경로)로 표시
9/28 대조 결과 자체몰 + 다른 마켓 연동 합계가 카페24 일별 매출내역과 모든 줄에서 일치(공식 확인). 어느 마켓 주문인지 확인할 수 있게 market_id 별 주문수·결제합계·환불·순매출 표를 추가. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -278,11 +278,21 @@ class Cafe24Adapter(MarketplaceAdapter):
|
||||
return {"orders": 0, "items": 0, "lines": 0, **{k: 0 for k in AMOUNT_FIELDS}, "total": 0}
|
||||
|
||||
groups = {"self": empty(), "market": empty()}
|
||||
by_market: dict[str, dict[str, Any]] = {} # 다른 마켓 연동 주문 — market_id 별
|
||||
unpaid = 0
|
||||
for o in self.paid_orders(ctx, day, day):
|
||||
if o.get("paid") != "T":
|
||||
unpaid += 1
|
||||
continue
|
||||
if not is_self_market(o.get("market_id")):
|
||||
key = str(o.get("market_id"))
|
||||
bm = by_market.setdefault(key, {"market_id": key, "names": set(), "orders": 0, "total": 0,
|
||||
"refund_count": 0, "refund_amount": 0})
|
||||
bm["orders"] += 1
|
||||
bm["total"] += order_total(o)
|
||||
for n in (o.get("order_place_name"), o.get("order_place_id")):
|
||||
if n:
|
||||
bm["names"].add(str(n))
|
||||
g = groups["self" if is_self_market(o.get("market_id")) else "market"]
|
||||
g["orders"] += 1
|
||||
g["items"] += sum(int(i.get("quantity") or 0) for i in o.get("items") or [])
|
||||
@@ -295,10 +305,19 @@ class Cafe24Adapter(MarketplaceAdapter):
|
||||
refunds = {"self": {"count": 0, "actual_refund_amount": 0, "used_points": 0, "used_credits": 0},
|
||||
"market": {"count": 0, "actual_refund_amount": 0, "used_points": 0, "used_credits": 0}}
|
||||
for r in rows:
|
||||
g = refunds["self" if is_self_market(markets.get(str(r.get("order_id")), "self")) else "market"]
|
||||
mid = markets.get(str(r.get("order_id")), "self")
|
||||
g = refunds["self" if is_self_market(mid) else "market"]
|
||||
g["count"] += 1
|
||||
for k in ("actual_refund_amount", "used_points", "used_credits"):
|
||||
g[k] += _won(r.get(k))
|
||||
if not is_self_market(mid):
|
||||
bm = by_market.setdefault(str(mid), {"market_id": str(mid), "names": set(), "orders": 0, "total": 0,
|
||||
"refund_count": 0, "refund_amount": 0})
|
||||
bm["refund_count"] += 1
|
||||
bm["refund_amount"] += _won(r.get("actual_refund_amount"))
|
||||
markets_out = sorted(({**v, "names": sorted(v["names"])} for v in by_market.values()),
|
||||
key=lambda v: v["total"], reverse=True)
|
||||
return {"date": day.isoformat(), "orders": groups, "refunds": refunds, "unpaid_orders": unpaid,
|
||||
"by_market": markets_out,
|
||||
"formula": "결제합계 = 상품구매금액 + 배송비 − 할인(" + ", ".join(DISCOUNT_FIELDS) +
|
||||
") − 쿠폰(" + ", ".join(COUPON_FIELDS) + ")"}
|
||||
|
||||
@@ -235,4 +235,4 @@
|
||||
} | tojson }}</script>
|
||||
{% endblock %}
|
||||
|
||||
{% block scripts %}<script src="/static/performance.js?v=20260930a" defer></script>{% endblock %}
|
||||
{% block scripts %}<script src="/static/performance.js?v=20260930b" defer></script>{% endblock %}
|
||||
|
||||
@@ -142,4 +142,4 @@
|
||||
</section>
|
||||
{% endblock %}
|
||||
|
||||
{% block scripts %}<script src="/static/performance.js?v=20260930a" defer></script>{% endblock %}
|
||||
{% block scripts %}<script src="/static/performance.js?v=20260930b" defer></script>{% endblock %}
|
||||
|
||||
@@ -456,6 +456,8 @@ def test_cafe24_normalize_matches_daily_report():
|
||||
assert rec["orders"]["self"]["orders"] == 1 and rec["orders"]["self"]["total"] == 47_000
|
||||
assert rec["orders"]["market"]["orders"] == 1 and rec["unpaid_orders"] == 1
|
||||
assert rec["refunds"]["self"]["actual_refund_amount"] == 32_610 and rec["refunds"]["market"]["count"] == 1
|
||||
assert rec["by_market"] == [{"market_id": "shopn", "names": [], "orders": 1, "total": 47_000,
|
||||
"refund_count": 1, "refund_amount": 9_000}]
|
||||
# 60일 단위 분할 + 페이지 넘김(1000건이면 다음 페이지)
|
||||
page1 = [_c24_order(f"x-{i}") for i in range(1000)]
|
||||
fake2 = _FakeCafe24([page1, [_c24_order("y")]])
|
||||
|
||||
@@ -517,6 +517,16 @@
|
||||
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>" +
|
||||
((r.by_market || []).length
|
||||
? '<h4 class="perf-h" style="margin:14px 0 6px">다른 마켓 연동 주문 — 마켓별</h4>' +
|
||||
'<table class="perf-table"><thead><tr><th class="perf-th-label">market_id</th><th class="perf-th-label">주문경로</th>' +
|
||||
"<th>주문수</th><th>결제합계</th><th>환불</th><th>순매출</th></tr></thead><tbody>" +
|
||||
r.by_market.map(function (b) {
|
||||
return '<tr><td class="perf-td-label">' + esc(b.market_id) + "</td><td>" + esc((b.names || []).join(", ")) +
|
||||
'</td><td class="perf-num">' + fmt(b.orders) + '</td><td class="perf-num">' + won(b.total) +
|
||||
'</td><td class="perf-num">' + won(-b.refund_amount) + '</td><td class="perf-num">' + won(b.total - b.refund_amount) + "</td></tr>";
|
||||
}).join("") + "</tbody></table>"
|
||||
: "") +
|
||||
'<p class="perf-foot perf-muted">' + esc(r.formula) + ". 미결제 주문 " + fmt(r.unpaid_orders) +
|
||||
"건 제외. 카페24 화면과 다른 줄이 있으면 알려 주세요 — 규칙을 맞추겠습니다.</p>";
|
||||
} catch (err) {
|
||||
|
||||
Reference in New Issue
Block a user