fix(performance): GS샵 매출 = supGiveAmt(협력사 지급액) — 협력사 포털 주문 통계 금액과 같은 항목

- 9월 실데이터: 6호세트 포털 176,715 ÷ 9 = 19,635 = API supGiveAmt(판매가 23,100·고객 결제 20,330),
  7호세트 45,900 × 85%, 주부체험 9,900 × 90% — 상품마다 GS 수수료율이 달라 판매가로는 못 맞춤
- 9/1~9/29 지급액 4,972,689 vs 포털 순주문 4,823,074(주문일↔매출인식일 차이)
- 이미 GS 수수료를 뺀 금액이라 GS샵 수수료율은 0% 로 둔다(문서·어댑터 설명)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-09-30 15:01:27 +09:00
parent b765fb8fb8
commit 8b3e6dffc5
3 changed files with 27 additions and 20 deletions
+14 -10
View File
@@ -20,10 +20,13 @@
**주문일 기준 조회 API 는 없다**(V3 문서에 주문 조회 없음) — 협력사 포털 주문 통계(총주문금액, 주문일)와는 기준이 달라
날짜별로 똑같이 맞출 수 없다.
매출 규칙(주문 통계의 금액도 할인 후 고객 결제 기준 — 7호세트 195,075 ÷ 5 = 39,015 = 45,900 × 85%):
매출 규칙 — 협력사 포털 주문 통계의 금액 = **supGiveAmt(협력사 지급액)**(2026-09-30, 9월 실데이터로 확인):
미라미라클 6호세트 포털 176,715 ÷ 9 = 19,635 = API 줄 supGiveAmt 19,635(판매가 23,100·고객 결제 20,330),
7호세트 39,015 = 45,900 × 85%, 주부체험 세트 8,910 = 9,900 × 90% — 상품마다 GS 수수료율이 달라 판매가 × 요율로는 못 맞춘다.
9/1~9/29: 지급액 4,972,689 / 포털 순주문 4,823,074(차이는 주문일 ↔ 매출인식일 기준 차이·취소분).
- 매출 내역 한 줄 = 사건 하나(`gs:{ordNo}-{ordItemNo}-{ordType}-{saleAwareDt}`), 날짜 = 매출인식일.
- 금액 = custChrAmt(할인 후 고객 결제금액), 배송비 제외(네이버와 같은 기준). ordType 이 SALE 이 아니면(취소·반품 등)
음수로(RETURN). 할인 = dcTotAmt. 기간을 통째로 다시 받는다(replace_range).
- 금액 = supGiveAmt, 배송비 제외. 이미 GS 수수료를 뺀 금액이라 **실적 설정의 GS샵 수수료율은 0%** 로 둔다.
ordType 이 SALE 이 아니면(취소·반품 등) 음수로(RETURN). 할인 = dcTotAmt. 기간을 통째로 다시 받는다(replace_range).
"""
from __future__ import annotations
@@ -235,12 +238,12 @@ class GsshopAdapter(MarketplaceAdapter):
yield {**r, "_day": day, "_id": base if n == 0 else f"{base}-{n + 1}"}
def normalize_order(self, r: dict[str, Any]) -> list[SaleEvent]:
"""매출 내역 한 줄 → SALE(ordType=SALE) 또는 RETURN(그 밖, 음수). 금액 = custChrAmt(할인 후 고객 결제금액)."""
"""매출 내역 한 줄 → SALE(ordType=SALE) 또는 RETURN(그 밖, 음수). 금액 = supGiveAmt(협력사 지급액 — 포털 주문 통계 금액)."""
oid, day = str(r.get("ordNo") or ""), r.get("_day")
if not oid or day is None:
return []
kind = str(r.get("ordType") or "SALE").upper()
amount = abs(_won(r.get("custChrAmt")))
amount = abs(_won(r.get("supGiveAmt")))
is_sale = kind == "SALE"
return [SaleEvent(
event_type="SALE" if is_sale else "RETURN", external_event_id=f"{EVENT_PREFIX}{r['_id']}",
@@ -248,7 +251,7 @@ class GsshopAdapter(MarketplaceAdapter):
payment_date=day if is_sale else None, amount=amount if is_sale else -amount,
product_name=str(r.get("prdNm") or "")[:200], quantity=abs(_won(r.get("chrQty"))),
discount_amount=abs(_won(r.get("dcTotAmt"))), order_status=kind[:50],
raw={"salePrice": _won(r.get("salePrice")), "supGiveAmt": _won(r.get("supGiveAmt")),
raw={"salePrice": _won(r.get("salePrice")), "custChrAmt": _won(r.get("custChrAmt")),
"orgOrdNo": str(r.get("orgOrdNo") or ""), "prdCd": str(r.get("prdCd") or "")},
)]
@@ -286,18 +289,19 @@ class GsshopAdapter(MarketplaceAdapter):
continue
got[key] = rows
probes.append({**row, "ok": True, "count": len(rows), "fields": field_summary([_strs(r) for r in rows])})
# 날짜별 현재 규칙 매출(custChrAmt, SALE 아닌 줄은 음수) — 협력사 포털 매출 화면과 나란히 비교
# 날짜별 현재 규칙 매출(supGiveAmt, SALE 아닌 줄은 음수) — 협력사 포털 매출 화면과 나란히 비교
days = []
d = day
while d <= to:
sales = [r for r in got.get("sales", []) if _yyyymmdd(r.get("saleAwareDt")) == d]
ret = [r for r in sales if str(r.get("ordType") or "SALE").upper() != "SALE"]
amt = sum(abs(_won(r.get("custChrAmt"))) for r in sales if r not in ret) - sum(abs(_won(r.get("custChrAmt"))) for r in ret)
amt = sum(abs(_won(r.get("supGiveAmt"))) for r in sales if r not in ret) - sum(abs(_won(r.get("supGiveAmt"))) for r in ret)
days.append({"date": d.isoformat(), "orders": len({str(r.get("ordNo")) for r in sales if r not in ret}),
"amount": amt, "claimed": sum(abs(_won(r.get("custChrAmt"))) for r in ret),
"amount": amt, "claimed": sum(abs(_won(r.get("supGiveAmt"))) for r in ret),
"ship": sum(_won(r.get("salePrice")) for r in got.get("shipping", [])
if _yyyymmdd(r.get("saleAwareDt")) == d)})
d += timedelta(days=1)
return {"date": day.isoformat(), "to": to.isoformat(), "probes": probes, "days": days,
"day_cols": {"claimed": "그중 취소·반품(음수로 반영)", "ship": "배송비(참고, 매출 제외)"},
"rule": "매출인식일 기준 매출 내역 custChrAmt(할인 후 고객 결제금액) 합, SALE 이 아닌 줄은 빼기, 배송비 제외"}
"rule": "매출인식일 기준 매출 내역 supGiveAmt(협력사 지급액 = 포털 주문 통계 금액) 합, SALE 이 아닌 줄은 빼기, "
"배송비 제외. 주문 통계는 주문일 기준이라 날마다 같지는 않고 기간이 길수록 가까워진다"}
@@ -1288,8 +1288,8 @@ def test_gsshop_token_connection_and_probe():
def test_gsshop_collect_sales():
"""GS샵 매출 = 매출 내역 custChrAmt(할인 후 고객 결제금액), 매출인식일 기준, 배송비 제외.
SALE 이 아닌 줄은 음수(RETURN). 실데이터 9/3: 16,400 − 820 = 15,580 모양."""
"""GS샵 매출 = 매출 내역 supGiveAmt(협력사 지급액 = 포털 주문 통계 금액), 매출인식일 기준, 배송비 제외.
SALE 이 아닌 줄은 음수(RETURN). 실데이터 9/3: 판매가 16,400 → 지급액 13,940(85%), 고객 결제 15,580."""
import httpx
from app.modules.performance.adapters import gsshop as gs
@@ -1299,7 +1299,7 @@ def test_gsshop_collect_sales():
def line(no, item, day, sale, dc, typ="SALE", qty=1):
return {"rnum": 1, "saleAwareDt": day, "prdCd": 1064149860, "prdNm": "미라클통 황토 3200ml", "supCd": 1047142,
"ordNo": no, "ordItemNo": item, "orgOrdNo": no, "ordType": typ, "chrQty": qty, "salePrice": sale,
"dcTotAmt": dc, "custChrAmt": sale - dc, "supGiveAmt": int((sale - dc) * 0.9)}
"dcTotAmt": dc, "custChrAmt": sale - dc, "supGiveAmt": round(sale * 0.85)}
rows = [line(3470403225, 1, 20260903, 16400, 820), line(3470403225, 2, 20260903, 32800, 1640, qty=2),
line(3470409999, 1, 20260904, 20000, 0, typ="RTN"), line(3470500000, 1, 20260912, 9900, 0)]
@@ -1324,11 +1324,11 @@ def test_gsshop_collect_sales():
assert r["ok"], r
ev_ = {k[2]: v for k, v in st.events.items() if k[0] == "gsshop"}
assert set(ev_) == {"gs:3470403225-1-SALE-20260903", "gs:3470403225-2-SALE-20260903", "gs:3470409999-1-RTN-20260904"}
assert ev_["gs:3470403225-1-SALE-20260903"]["amount"] == 15580 and ev_["gs:3470403225-1-SALE-20260903"]["discount_amount"] == 820
assert ev_["gs:3470403225-1-SALE-20260903"]["amount"] == 13940 and ev_["gs:3470403225-1-SALE-20260903"]["discount_amount"] == 820
assert ev_["gs:3470403225-2-SALE-20260903"]["quantity"] == 2
ret = ev_["gs:3470409999-1-RTN-20260904"]
assert ret["event_type"] == "RETURN" and ret["amount"] == -20000 and ret["sales_date"] == date(2026, 9, 4)
assert sum(v["amount"] for v in ev_.values()) == 15580 + 31160 - 20000 # 배송비 3,500 제외
assert ret["event_type"] == "RETURN" and ret["amount"] == -17000 and ret["sales_date"] == date(2026, 9, 4)
assert sum(v["amount"] for v in ev_.values()) == 13940 + 27880 - 17000 # 배송비 3,500 제외
httpx.get = get
try:
@@ -1336,8 +1336,8 @@ def test_gsshop_collect_sales():
code="gsshop", credentials=creds.accessor("gsshop")), date(2026, 9, 3), to=date(2026, 9, 4))
finally:
httpx.get = orig
assert rec["days"][0] == {"date": "2026-09-03", "orders": 1, "amount": 46740, "claimed": 0, "ship": 3500}
assert rec["days"][1]["amount"] == -20000 and rec["days"][1]["claimed"] == 20000
assert rec["days"][0] == {"date": "2026-09-03", "orders": 1, "amount": 41820, "claimed": 0, "ship": 3500}
assert rec["days"][1]["amount"] == -17000 and rec["days"][1]["claimed"] == 17000
if __name__ == "__main__":
+5 -2
View File
@@ -140,8 +140,11 @@
9/3: 211,100 − 19,528 = 191,572, 지급 179,435, 배송비 내역 7,000.
- **주문일 기준 조회 API 는 없다** — 협력사 포털 주문 통계(총주문금액·주문일, 할인 후 금액: 45,900 × 85% = 39,015)와는 날짜 기준이
달라 날마다 똑같이 맞지 않는다(매출인식일 = 정산 기준).
- **매출 규칙**: 매출 내역 한 줄 = 사건(`gs:{ordNo}-{ordItemNo}-{ordType}-{saleAwareDt}`), 날짜 = 매출인식일, 금액 = `custChrAmt`
(할인 후 고객 결제금액), 배송비 제외(네이버와 같은 기준). `ordType` 이 SALE 이 아니면 RETURN 음수. `replace_range`.
- **매출 규칙**: 매출 내역 한 줄 = 사건(`gs:{ordNo}-{ordItemNo}-{ordType}-{saleAwareDt}`), 날짜 = 매출인식일,
금액 = **`supGiveAmt`(협력사 지급액)** = 협력사 포털 주문 통계의 금액(2026-09-30 확인: 6호세트 포털 176,715 ÷ 9 = 19,635 = API
supGiveAmt 19,635 — 판매가 23,100·고객 결제 20,330. 7호세트 45,900 × 85%, 주부체험 9,900 × 90% — 상품마다 GS 수수료율이 다름).
9/1~9/29 지급액 4,972,689 vs 포털 순주문 4,823,074 — 남는 차이는 주문일 ↔ 매출인식일·취소분. 이미 GS 수수료를 뺀 금액이라
**GS샵 수수료율은 0%**. 배송비 제외, `ordType` 이 SALE 이 아니면 RETURN 음수. `replace_range`.
원본 데이터 확인에 날짜별 현재 규칙 매출·취소/반품·배송비(참고).
### 연동 단계 체크리스트(쇼핑몰마다)