From ef12a346005595355389d453db4f9829f89da250 Mon Sep 17 00:00:00 2001 From: king Date: Tue, 29 Sep 2026 17:04:51 +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=20=E2=80=94=20=EC=B1=84?= =?UTF-8?q?=EB=84=90=EB=B3=84=20PC/=EB=AA=A8=EB=B0=94=EC=9D=BC=20=EC=A3=BC?= =?UTF-8?q?=EB=AC=B8=20=EB=B6=84=EB=A6=AC=20+=20=EA=B2=B0=EC=A0=9C?= =?UTF-8?q?=EC=88=98=EB=8B=A8=EB=B3=84=20=ED=91=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 주문 채널별 표에 PC 주문 / 모바일 주문(주문의 order_from_mobile 기준 — PC 채널이어도 휴대폰 주문은 모바일) 건수·결제합계, 카페24 열(자체몰) 합계 줄 - 결제수단별 표(카페24 열 주문의 payment_method_name 조합별 주문수·결제합계·비중) - 대조 카드를 설정 화면 가로 전체 폭으로(넓은 표가 잘리지 않게), 자체몰 채널 이름 정리(PC) Co-Authored-By: Claude Opus 5.5 --- app/modules/performance/adapters/cafe24.py | 18 +++++++++-- .../templates/performance/index.html | 4 +-- .../templates/performance/settings.html | 6 ++-- .../performance/tests/test_performance.py | 16 ++++++++-- app/static/performance.css | 1 + app/static/performance.js | 32 +++++++++++++++++-- 6 files changed, 65 insertions(+), 12 deletions(-) diff --git a/app/modules/performance/adapters/cafe24.py b/app/modules/performance/adapters/cafe24.py index e6c2f71..82a5ded 100644 --- a/app/modules/performance/adapters/cafe24.py +++ b/app/modules/performance/adapters/cafe24.py @@ -54,7 +54,7 @@ EVENT_PREFIX = "c24:" # (실데이터 확인 2026-09-30: mobile=모바일웹, NCHECKOUT=네이버페이, KAKAOPAY=톡체크아웃). # 이 주문들은 카페24 자체몰 매출이다. 비교는 소문자로. SELF_CHANNELS: dict[str, str] = { - "": "자체몰", "self": "자체몰(PC)", "cafe24": "자체몰", "mobile": "모바일웹", "mobile_d": "모바일앱", + "": "기본", "self": "PC", "cafe24": "PC", "mobile": "모바일웹", "mobile_d": "모바일앱", "ncheckout": "네이버페이", "kakaopay": "톡체크아웃", } @@ -339,18 +339,31 @@ class Cafe24Adapter(MarketplaceAdapter): "market_id": key or "(없음)", "label": SELF_CHANNELS.get(_key(mid), ""), "names": set(), "kind": kind, "target": target_code(mid, place), "orders": 0, "total": 0, "refund_count": 0, "refund_amount": 0, + # 기기 — 주문의 order_from_mobile(T=모바일에서 주문). PC 채널(self)에도 모바일 주문이 섞여 있다. + "pc_orders": 0, "pc_total": 0, "mobile_orders": 0, "mobile_total": 0, }) groups = {"self": empty(), "market": empty()} by_channel: dict[str, dict[str, Any]] = {} + by_payment: dict[str, dict[str, Any]] = {} # 결제수단 조합별(카페24 열 주문만) unpaid = 0 for o in self.paid_orders(ctx, day, day): if o.get("paid") != "T": unpaid += 1 continue ch = channel(o.get("market_id"), o.get("order_place_id")) + total = order_total(o) ch["orders"] += 1 - ch["total"] += order_total(o) + ch["total"] += total + dev = "mobile" if str(o.get("order_from_mobile") or "").upper() == "T" else "pc" + ch[f"{dev}_orders"] += 1 + ch[f"{dev}_total"] += total + if ch["target"] == "cafe24": + names = [str(n) for n in (o.get("payment_method_name") or o.get("payment_method") or []) if n] + pkey = " + ".join(names) or "(없음)" + pm = by_payment.setdefault(pkey, {"method": pkey, "orders": 0, "total": 0}) + pm["orders"] += 1 + pm["total"] += total for n in (o.get("order_place_name"), o.get("order_place_id")): if n: ch["names"].add(str(n)) @@ -378,5 +391,6 @@ class Cafe24Adapter(MarketplaceAdapter): key=lambda v: v["total"], reverse=True) return {"date": day.isoformat(), "orders": groups, "refunds": refunds, "unpaid_orders": unpaid, "by_channel": channels_out, + "by_payment": sorted(by_payment.values(), key=lambda v: v["total"], reverse=True), "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 aa7df32..e57b2ef 100644 --- a/app/modules/performance/templates/performance/index.html +++ b/app/modules/performance/templates/performance/index.html @@ -1,6 +1,6 @@ {% extends "erp_base.html" %} -{% block head_extra %}{% endblock %} +{% block head_extra %}{% endblock %} {%- macro won(v) -%} {%- if v is none -%} @@ -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 bec4221..bb2e1e9 100644 --- a/app/modules/performance/templates/performance/settings.html +++ b/app/modules/performance/templates/performance/settings.html @@ -1,6 +1,6 @@ {% extends "erp_base.html" %} -{% block head_extra %}{% endblock %} +{% block head_extra %}{% endblock %} {%- macro when(v) -%}{{ (v or '')[:16] | replace('T', ' ') or '—' }}{%- endmacro -%} @@ -116,7 +116,7 @@ -
+

카페24 매출 대조

카페24 관리자 → 통계 → 일별 매출내역과 같은 날짜를 비교합니다. 그날 결제 주문과 환불을 카페24 API 에서 바로 합산하며(저장하지 않음), 자체몰과 다른 마켓 연동 주문을 나눠 보여 줍니다.

@@ -143,4 +143,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 4bc9d5d..ef70190 100644 --- a/app/modules/performance/tests/test_performance.py +++ b/app/modules/performance/tests/test_performance.py @@ -433,9 +433,11 @@ def test_cafe24_normalize_matches_daily_report(): ctx = AdapterContext(code="cafe24", credentials=None) fake = _FakeCafe24( - [[_c24_order("A"), _c24_order("B", market="shopn"), _c24_order("C", paid="F"), - _c24_order("D", market="auction"), _c24_order("E", market="NCHECKOUT"), - _c24_order("F", market="KAKAOPAY"), _c24_order("G", market="mobile")]], + [[_c24_order("A", order_from_mobile="T", payment_method_name=["신용카드"]), _c24_order("B", market="shopn"), + _c24_order("C", paid="F"), _c24_order("D", market="auction", payment_method_name=["신용카드"]), + _c24_order("E", market="NCHECKOUT", payment_method_name=["네이버페이"]), + _c24_order("F", market="KAKAOPAY", payment_method_name=["카카오페이", "적립금"]), + _c24_order("G", market="mobile", order_from_mobile="T", payment_method_name=["무통장입금"])]], [[_c24_refund("C20260929-01", "A", 12_610), _c24_refund("R20260929-02", "X", 20_000), _c24_refund("C20260929-03", "M", 9_000), _c24_refund("C20260929-04", "A", 5_000, status="F")]], lookup={"M": "shopn"}, @@ -478,6 +480,14 @@ def test_cafe24_normalize_matches_daily_report(): assert ch["auction"]["kind"] == "unknown" and ch["auction"]["target"] == "cafe24" assert ch["NCHECKOUT"]["kind"] == "self" and ch["NCHECKOUT"]["label"] == "네이버페이" assert ch["KAKAOPAY"]["label"] == "톡체크아웃" and ch["mobile"]["label"] == "모바일웹" + # 기기: PC 채널(self)이어도 휴대폰 주문(order_from_mobile=T)은 모바일 + assert ch["self"]["mobile_orders"] == 1 and ch["self"]["pc_orders"] == 0 and ch["self"]["mobile_total"] == 47_000 + assert ch["NCHECKOUT"]["pc_orders"] == 1 and ch["mobile"]["mobile_orders"] == 1 + # 결제수단별(카페24 열만 — 외부 마켓 B 제외) + pay = {p["method"]: p for p in rec["by_payment"]} + assert pay["신용카드"]["orders"] == 2 and pay["신용카드"]["total"] == 94_000 + assert pay["카카오페이 + 적립금"]["orders"] == 1 and "네이버페이" in pay and "무통장입금" in pay + assert sum(p["orders"] for p in rec["by_payment"]) == 5 # 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.css b/app/static/performance.css index 544e6e7..66e2ee4 100644 --- a/app/static/performance.css +++ b/app/static/performance.css @@ -92,6 +92,7 @@ a.perf-seg.is-active, a.perf-seg.is-active:link, a.perf-seg.is-active:visited { .perf-card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 8px; flex-wrap: wrap; } .perf-h { margin: 0; font-size: 14px; font-weight: 600; } .perf-grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; } +.perf-grid2 > .perf-card-wide { grid-column: 1 / -1; } /* 표가 넓은 카드(매출 대조)는 한 줄 전체 */ .perf-foot { margin: 8px 0 0; line-height: 1.5; } /* 표 */ diff --git a/app/static/performance.js b/app/static/performance.js index b1dc828..607052a 100644 --- a/app/static/performance.js +++ b/app/static/performance.js @@ -482,6 +482,7 @@ const r = await api("GET", "/performance/api/marketplaces/cafe24/reconcile?date=" + encodeURIComponent(day)); if (!r.ok) { out.innerHTML = '

' + esc((r.label ? r.label + " — " : "") + r.message) + "

"; return; } const s = r.orders.self, m = r.orders.market, rs = r.refunds.self, rm = r.refunds.market; + const dev = function (n, amt) { return n ? fmt(n) + '건 ' + won(amt) + "" : won(0); }; const MARKET_NAMES = {}; root.querySelectorAll("tr[data-code]").forEach(function (tr) { MARKET_NAMES[tr.dataset.code] = tr.dataset.name; }); const disc = ["membership_discount_amount", "set_product_discount_amount", "app_discount_amount", @@ -522,7 +523,8 @@ ((r.by_channel || []).length ? '

주문 채널별

' + '' + - '' + + '' + + "" + r.by_channel.map(function (b) { const col = MARKET_NAMES[b.target] || b.target; const kind = b.kind === "self" ? "자체몰 채널" + (b.label ? "(" + b.label + ")" : "") @@ -530,8 +532,34 @@ return '"; - }).join("") + "
market_id주문경로구분반영 열주문수결제합계환불순매출
구분반영 열주문수결제합계PC 주문모바일 주문환불순매출
' + esc(b.market_id) + "" + esc((b.names || []).join(", ")) + "" + (b.kind === "unknown" ? kind : esc(kind)) + "" + esc(col) + '' + fmt(b.orders) + '' + won(b.total) + + '' + dev(b.pc_orders, b.pc_total) + '' + dev(b.mobile_orders, b.mobile_total) + '' + won(-b.refund_amount) + '' + won(b.total - b.refund_amount) + "
" + }).join("") + "" + + // 카페24 열(자체몰) 기기 합계 + (function () { + const own = r.by_channel.filter(function (b) { return b.target === "cafe24"; }); + const t = own.reduce(function (a, b) { + a.o += b.orders; a.t += b.total; a.po += b.pc_orders; a.pt += b.pc_total; a.mo += b.mobile_orders; a.mt += b.mobile_total; + a.ra += b.refund_amount; return a; + }, { o: 0, t: 0, po: 0, pt: 0, mo: 0, mt: 0, ra: 0 }); + return '카페24 열(자체몰) 합계' + + fmt(t.o) + '' + won(t.t) + '' + dev(t.po, t.pt) + + '' + dev(t.mo, t.mt) + '' + won(-t.ra) + + '' + won(t.t - t.ra) + ""; + })() + "" + + '

PC/모바일은 주문의 모바일 주문 여부(order_from_mobile) 기준입니다 — 채널이 PC(self)여도 휴대폰에서 주문하면 모바일로 셉니다.

' + : "") + + ((r.by_payment || []).length + ? '

결제수단별 (카페24 열)

' + + '' + + (function () { + const tot = r.by_payment.reduce(function (a, p) { return a + p.total; }, 0); + return r.by_payment.map(function (p) { + return '"; + }).join(""); + })() + "
결제수단주문수결제합계비중
' + esc(p.method) + '' + fmt(p.orders) + + '' + won(p.total) + '' + + (tot > 0 ? (p.total / tot * 100).toFixed(1) + "%" : "–") + "
" : "") + '

' + esc(r.formula) + ". 미결제 주문 " + fmt(r.unpaid_orders) + "건 제외. \"알 수 없는 채널\"은 카페24 열에 넣습니다 — 외부 마켓이면 어느 쇼핑몰인지 알려 주세요.

";