0bddce516f
- eCPM 口径修正:getEcpm 原值是分/千次,新增 parse_ecpm_fen;parse_ecpm_yuan 改为 ÷100 转元,因子1 阈值按元判档(100/200/400),收益换算用元 - test-grant 用客户端按 ad_session_id 上报的真实 eCPM 发奖(取不到/≤0 兜底 200) - 新增 GET /admin/api/ad-coin-audit 只读复算对账(router/repo/schema),复用发奖公式 - 同步更新 docs/api、docs/database 的分/元口径 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> --------- Co-authored-by: OuYingJun1024 <1034284404@qq.com> Reviewed-on: #32 Co-authored-by: ouzhou <ouzhou@wonderable.ai> Co-committed-by: ouzhou <ouzhou@wonderable.ai>
45 lines
1.6 KiB
Python
45 lines
1.6 KiB
Python
"""admin 看广告金币审计:只读对账,核对发奖金币是否按公式计算。
|
|
|
|
任意已登录 admin 可看(只读,不涉及资金操作)。复算逻辑在 app/admin/repositories/ad_audit.py。
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
from typing import Annotated
|
|
|
|
from fastapi import APIRouter, Depends, Query
|
|
|
|
from app.admin.deps import AdminDb, get_current_admin
|
|
from app.admin.repositories import ad_audit
|
|
from app.admin.schemas.ad_audit import AdCoinAuditOut, AdCoinAuditRow, AdCoinFormulaOut
|
|
from app.core.rewards import cn_today
|
|
|
|
router = APIRouter(
|
|
prefix="/admin/api/ad-coin-audit",
|
|
tags=["admin-ad-coin-audit"],
|
|
dependencies=[Depends(get_current_admin)],
|
|
)
|
|
|
|
|
|
@router.get("", response_model=AdCoinAuditOut, summary="看广告金币公式审计(复算对比)")
|
|
def get_ad_coin_audit(
|
|
db: AdminDb,
|
|
date: Annotated[str | None, Query(description="北京时间 YYYY-MM-DD,默认今天")] = None,
|
|
user_id: Annotated[int | None, Query(description="只看某用户;不传=全部用户")] = None,
|
|
scene: Annotated[
|
|
str | None, Query(description="reward_video / feed;不传=两类都要")
|
|
] = None,
|
|
limit: Annotated[int, Query(ge=1, le=500)] = 100,
|
|
) -> AdCoinAuditOut:
|
|
audit_date = date or cn_today().isoformat()
|
|
rows = ad_audit.ad_coin_audit(
|
|
db, date=audit_date, user_id=user_id, scene=scene, limit=limit,
|
|
)
|
|
items = [AdCoinAuditRow(**r) for r in rows]
|
|
return AdCoinAuditOut(
|
|
date=audit_date,
|
|
formula=AdCoinFormulaOut(**ad_audit.formula_snapshot()),
|
|
total=len(items),
|
|
mismatch_count=sum(1 for it in items if not it.matched),
|
|
items=items,
|
|
)
|