diff --git a/app/modules/performance/adapters/cafe24.py b/app/modules/performance/adapters/cafe24.py index 7db0708..257f9c4 100644 --- a/app/modules/performance/adapters/cafe24.py +++ b/app/modules/performance/adapters/cafe24.py @@ -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) + ")"} diff --git a/app/modules/performance/templates/performance/index.html b/app/modules/performance/templates/performance/index.html index c1f3341..bb762d9 100644 --- a/app/modules/performance/templates/performance/index.html +++ b/app/modules/performance/templates/performance/index.html @@ -235,4 +235,4 @@ } | tojson }} {% endblock %} -{% block scripts %}{% endblock %} +{% block scripts %}{% endblock %} diff --git a/app/modules/performance/templates/performance/settings.html b/app/modules/performance/templates/performance/settings.html index 572675e..26bac50 100644 --- a/app/modules/performance/templates/performance/settings.html +++ b/app/modules/performance/templates/performance/settings.html @@ -142,4 +142,4 @@ {% endblock %} -{% block scripts %}{% endblock %} +{% block scripts %}{% endblock %} diff --git a/app/modules/performance/tests/test_performance.py b/app/modules/performance/tests/test_performance.py index 1365cae..53c35da 100644 --- a/app/modules/performance/tests/test_performance.py +++ b/app/modules/performance/tests/test_performance.py @@ -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")]]) diff --git a/app/static/performance.js b/app/static/performance.js index 6922482..9035fc8 100644 --- a/app/static/performance.js +++ b/app/static/performance.js @@ -517,6 +517,16 @@ return "' + esc(x[0]) + '' + f(x[1]) + '' + f(x[2]) + ""; }).join("") + "" + + ((r.by_market || []).length + ? '

다른 마켓 연동 주문 — 마켓별

' + + '' + + "" + + r.by_market.map(function (b) { + return '"; + }).join("") + "
market_id주문경로주문수결제합계환불순매출
' + esc(b.market_id) + "" + esc((b.names || []).join(", ")) + + '' + fmt(b.orders) + '' + won(b.total) + + '' + won(-b.refund_amount) + '' + won(b.total - b.refund_amount) + "
" + : "") + '

' + esc(r.formula) + ". 미결제 주문 " + fmt(r.unpaid_orders) + "건 제외. 카페24 화면과 다른 줄이 있으면 알려 주세요 — 규칙을 맞추겠습니다.

"; } catch (err) {