From 4cb37688ed262d83a4d05951260732ff48f4e6bc Mon Sep 17 00:00:00 2001 From: king Date: Tue, 29 Sep 2026 16:46:28 +0900 Subject: [PATCH] =?UTF-8?q?feat(performance):=20=EC=B9=B4=ED=8E=9824=20?= =?UTF-8?q?=EB=A7=A4=EC=B6=9C=20=EB=8C=80=EC=A1=B0=EC=97=90=20=EB=8B=A4?= =?UTF-8?q?=EB=A5=B8=20=EB=A7=88=EC=BC=93=20=EC=97=B0=EB=8F=99=20=EC=A3=BC?= =?UTF-8?q?=EB=AC=B8=EC=9D=84=20=EB=A7=88=EC=BC=93=EB=B3=84(market=5Fid?= =?UTF-8?q?=C2=B7=EC=A3=BC=EB=AC=B8=EA=B2=BD=EB=A1=9C)=EB=A1=9C=20?= =?UTF-8?q?=ED=91=9C=EC=8B=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 9/28 대조 결과 자체몰 + 다른 마켓 연동 합계가 카페24 일별 매출내역과 모든 줄에서 일치(공식 확인). 어느 마켓 주문인지 확인할 수 있게 market_id 별 주문수·결제합계·환불·순매출 표를 추가. Co-Authored-By: Claude Opus 5.5 --- app/modules/performance/adapters/cafe24.py | 21 ++++++++++++++++++- .../templates/performance/index.html | 2 +- .../templates/performance/settings.html | 2 +- .../performance/tests/test_performance.py | 2 ++ app/static/performance.js | 10 +++++++++ 5 files changed, 34 insertions(+), 3 deletions(-) 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) {