feat(admin): 首页门面数字保底/护栏 + 轮播种子真实化与批量 + 比价记录索引
- ops_stat: 真实值 offset→保底(max);初始基数过只增不减护栏 - ops_marquee: 脱敏名手机尾号+中文昵称混合;金额长尾;时间随机抖动;真实+种子不足兜底补满;真实记录查询 ~30s 缓存 - comparison_record: 复合索引 (status, created_at) + 迁移(PG CONCURRENTLY);修复 alembic 多 head(merge 改挂 onboarding_completion) - 轮播种子批量删除/启用接口 + ids 上限;docs 同步 - 附带并行会话 WIP:admin users / wallet Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -12,6 +12,8 @@ from fastapi import APIRouter, Depends, HTTPException, Query, Request
|
||||
from app.admin.audit import write_audit
|
||||
from app.admin.deps import AdminDb, get_client_ip, get_current_admin, require_role
|
||||
from app.admin.schemas.ops_marquee_seed import (
|
||||
OpsMarqueeSeedBatchDelete,
|
||||
OpsMarqueeSeedBatchEnable,
|
||||
OpsMarqueeSeedBulkCreate,
|
||||
OpsMarqueeSeedCreate,
|
||||
OpsMarqueeSeedOut,
|
||||
@@ -111,6 +113,40 @@ def bulk_generate(
|
||||
return [_out(s) for s in seeds]
|
||||
|
||||
|
||||
@router.post("/batch-delete", summary="批量删除种子(带审计)")
|
||||
def batch_delete_seeds(
|
||||
body: OpsMarqueeSeedBatchDelete,
|
||||
request: Request,
|
||||
admin: Annotated[AdminUser, Depends(require_role("operator"))],
|
||||
db: AdminDb,
|
||||
) -> dict:
|
||||
n = ops_marquee.batch_delete(db, body.ids, commit=False)
|
||||
write_audit(
|
||||
db, admin, action="ops_marquee_seed.batch_delete", target_type="ops_marquee_seed",
|
||||
target_id=None, detail={"ids": body.ids, "deleted": n},
|
||||
ip=get_client_ip(request), commit=False,
|
||||
)
|
||||
db.commit()
|
||||
return {"deleted": n}
|
||||
|
||||
|
||||
@router.post("/batch-enable", summary="批量启用 / 停用种子(带审计)")
|
||||
def batch_enable_seeds(
|
||||
body: OpsMarqueeSeedBatchEnable,
|
||||
request: Request,
|
||||
admin: Annotated[AdminUser, Depends(require_role("operator"))],
|
||||
db: AdminDb,
|
||||
) -> dict:
|
||||
n = ops_marquee.batch_set_enabled(db, body.ids, body.enabled, commit=False)
|
||||
write_audit(
|
||||
db, admin, action="ops_marquee_seed.batch_enable", target_type="ops_marquee_seed",
|
||||
target_id=None, detail={"ids": body.ids, "enabled": body.enabled, "updated": n},
|
||||
ip=get_client_ip(request), commit=False,
|
||||
)
|
||||
db.commit()
|
||||
return {"updated": n}
|
||||
|
||||
|
||||
@router.patch("/{seed_id}", response_model=OpsMarqueeSeedOut, summary="改轮播种子(带审计)")
|
||||
def update_seed(
|
||||
seed_id: int,
|
||||
|
||||
@@ -12,6 +12,7 @@ from app.admin.schemas.common import CursorPage, OkResponse
|
||||
from app.admin.schemas.user import (
|
||||
AdminUserListItem,
|
||||
AdminUserOverview,
|
||||
GrantCashRequest,
|
||||
GrantCoinsRequest,
|
||||
SetDebugTraceRequest,
|
||||
SetUserStatusRequest,
|
||||
@@ -132,3 +133,42 @@ def grant_user_coins(
|
||||
)
|
||||
db.commit()
|
||||
return OkResponse()
|
||||
|
||||
|
||||
@router.post("/{user_id}/cash", response_model=OkResponse, summary="手动增减现金(带审计)")
|
||||
def grant_user_cash(
|
||||
user_id: int,
|
||||
body: GrantCashRequest,
|
||||
request: Request,
|
||||
admin: Annotated[AdminUser, Depends(require_role("finance"))],
|
||||
db: AdminDb,
|
||||
) -> OkResponse:
|
||||
"""给指定用户增/减现金(分)。正=发放、负=扣减;主要用于让无现金用户直接测试提现。"""
|
||||
if body.amount_cents == 0:
|
||||
raise HTTPException(status_code=400, detail="amount_cents 不能为 0")
|
||||
user = user_repo.get_user_by_id(db, user_id)
|
||||
if user is None:
|
||||
raise HTTPException(status_code=404, detail="用户不存在")
|
||||
# 负数扣减时不允许扣成负余额(运营误操作保护)
|
||||
if body.amount_cents < 0:
|
||||
acc_now = wallet_repo.get_or_create_account(db, user_id, commit=False)
|
||||
if acc_now.cash_balance_cents + body.amount_cents < 0:
|
||||
raise HTTPException(
|
||||
status_code=400, detail=f"扣减后现金为负(当前余额 {acc_now.cash_balance_cents} 分)"
|
||||
)
|
||||
biz_type = "admin_grant" if body.amount_cents > 0 else "admin_deduct"
|
||||
# grant_cash 只 flush 不 commit;审计同 commit=False;最后一起 commit → 原子(改钱+留痕)
|
||||
acc, _ = wallet_repo.grant_cash(
|
||||
db, user_id, body.amount_cents, biz_type=biz_type, remark=f"admin:{body.reason}"[:128],
|
||||
)
|
||||
write_audit(
|
||||
db, admin, action="user.cash.grant", target_type="user", target_id=user_id,
|
||||
detail={
|
||||
"amount_cents": body.amount_cents,
|
||||
"balance_after_cents": acc.cash_balance_cents,
|
||||
"reason": body.reason,
|
||||
},
|
||||
ip=get_client_ip(request), commit=False,
|
||||
)
|
||||
db.commit()
|
||||
return OkResponse()
|
||||
|
||||
Reference in New Issue
Block a user