feat(performance): 카페24 일별 매출내역 붙여넣기로 날짜별 한 번에 비교

카페24 화면과 몇몇 날짜만 안 맞는데 어느 날·어느 쪽(결제/환불)인지,
저장값이 예전 규칙이라서인지 규칙 자체가 틀린 건지 구분할 방법이 없었다.

- GET /performance/api/marketplaces/{code}/daily-check?from=&to=&live=1 (관리자, 62일)
  db   = 저장된 날짜별 결제합계·결제 건수·환불합계(c24: 사건 전체 = 카페24 화면 범위)
  live = 지금 API·현재 규칙으로 다시 계산(adapter.collect, 저장 안 함)
- 설정 → 카페24 매출 대조 카드에 "일별 한 번에 비교": 카페24 표 붙여넣기 →
  날짜별 차이(저장값/API), 판정(일치 / 다시 가져오면 해결 / 규칙 차이(결제·환불)),
  [다시 가져오기] 버튼, 날짜 클릭 시 그날 상세 대조
- 테스트 추가

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-09-29 21:36:32 +09:00
parent 1d12ac878b
commit 614332a1e6
9 changed files with 241 additions and 4 deletions
+19
View File
@@ -292,6 +292,25 @@ class PerformanceDBStore:
).fetchall()
return {(r["sales_date"], r["marketplace_code"]): int(r["amount"] or 0) for r in rows}
def daily_breakdown(self, code: str, start: date, end: date, *, id_prefix: str = "") -> list[dict[str, Any]]:
"""쇼핑몰 화면(일별 매출내역) 대조용 — 날짜별 결제(SALE 합·건수)·환불(그 밖, 양수)·마지막 수집 시각.
id_prefix 가 있으면 이 어댑터가 다른 쇼핑몰 열로 보낸 사건까지 합친다(카페24 화면 합계와 같은 범위)."""
where = "(marketplace_code = %s OR left(external_event_id, %s) = %s)" if id_prefix else "marketplace_code = %s"
params: tuple = (code, len(id_prefix), id_prefix) if id_prefix else (code,)
with self._pool.connection() as conn:
rows = conn.execute(
"SELECT sales_date, "
" COALESCE(SUM(amount) FILTER (WHERE event_type = 'SALE'), 0)::BIGINT AS paid, "
" COUNT(*) FILTER (WHERE event_type = 'SALE')::INT AS orders, "
" COALESCE(-SUM(amount) FILTER (WHERE event_type <> 'SALE'), 0)::BIGINT AS refund, "
" MAX(synced_at) AS synced_at "
f"FROM perf_sales_events WHERE is_sample = FALSE AND sales_date BETWEEN %s AND %s AND {where} "
"GROUP BY sales_date ORDER BY sales_date",
(start, end, *params),
).fetchall()
return [{"date": r["sales_date"].isoformat(), "paid": int(r["paid"]), "orders": int(r["orders"]),
"refund": int(r["refund"]), "synced_at": _iso(r["synced_at"])} for r in rows]
def list_events(self, code: str, start: date, end: date, *, limit: int = 500) -> list[dict[str, Any]]:
"""금액 클릭 상세(Drill-down). raw_data 는 보내지 않는다."""
with self._pool.connection() as conn: