Files
shaguabijia-app-server/app/admin/routers/ad_audit.py
T
zzhyyyyy b59145c784 feat(ad): 信息流广告切换为 Draw 信息流并区分比价/领券收益
后端支持 Draw 信息流广告:
- ad_feed_reward_record 新增 ad_type(feed/draw),ad_ecpm_record 新增 feed_scene(comparison/coupon/welfare)+ Alembic 迁移
- ecpm-report / feed-reward 接口接收并落 ad_type=draw 与 feed_scene
- 广告配置字段 compare/coupon_feed_code_id 改名为 compare/coupon_draw_code_id(默认 Draw 位 104098712)
- 收益报表与对账(ad_revenue / ad_audit)支持 draw 类型,按 feed_scene 区分比价/领券收益

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-26 22:58:23 +08:00

49 lines
1.8 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 / draw;不传=全部")
] = None,
limit: Annotated[int, Query(ge=1, le=500)] = 100,
only_mismatch: Annotated[
bool, Query(description="只看不一致(✗)行;统计数仍按全量,不受影响")
] = False,
) -> AdCoinAuditOut:
audit_date = date or cn_today().isoformat()
result = ad_audit.ad_coin_audit(
db, date=audit_date, user_id=user_id, scene=scene, limit=limit,
only_mismatch=only_mismatch,
)
return AdCoinAuditOut(
date=audit_date,
formula=AdCoinFormulaOut(**ad_audit.formula_snapshot()),
total=result["total"],
mismatch_count=result["mismatch_count"],
truncated=result["truncated"],
items=[AdCoinAuditRow(**r) for r in result["items"]],
)