增加充值审计日志
This commit is contained in:
@@ -14,6 +14,7 @@ from ..permissions import user_has_permission
|
||||
from ..schemas import YybLoginRequest, YybSelectionRequest, YybTaskCreateRequest
|
||||
from ..services.yyb_service import _utcnow, public_task, sync_task
|
||||
from ..services.yyb_worker_client import YybWorkerClient, YybWorkerError
|
||||
from ..services.audit_service import record_audit
|
||||
|
||||
|
||||
router = APIRouter(prefix="/api/yyb", tags=["应用宝充值"])
|
||||
@@ -58,6 +59,10 @@ def create_task(payload: YybTaskCreateRequest, db: Session = Depends(get_db), cu
|
||||
worker_job_id=str(data["job_id"]), status=str(data.get("status", "created")),
|
||||
phase="login", message="请选择登录方式")
|
||||
db.add(task)
|
||||
record_audit(
|
||||
db, current, action="recharge:yyb:create", target=f"yyb_task:{task.task_id}",
|
||||
detail={"task_id": task.task_id, "status": task.status},
|
||||
)
|
||||
db.commit()
|
||||
db.refresh(task)
|
||||
return public_task(task, include_qr=False, creator_username=current.username)
|
||||
@@ -73,6 +78,10 @@ def login(task_id: int, payload: YybLoginRequest, db: Session = Depends(get_db),
|
||||
task.message = "请扫码登录并在手机确认"
|
||||
if data.get("qr_data"):
|
||||
task.login_qr_data = data["qr_data"]
|
||||
record_audit(
|
||||
db, current, action="recharge:yyb:login", target=f"yyb_task:{task.task_id}",
|
||||
detail={"task_id": task.task_id, "provider": payload.provider, "status": task.status},
|
||||
)
|
||||
db.commit()
|
||||
return public_task(task, creator_username=_creator_username(db, task))
|
||||
|
||||
@@ -129,6 +138,14 @@ def selection(task_id: int, payload: YybSelectionRequest, db: Session = Depends(
|
||||
setattr(task, field, selected[field])
|
||||
task.price_fen = int(selected.get("price_fen") or 0)
|
||||
task.phase, task.status, task.message = "payment", "ready", "选择已保存,可以生成付款码"
|
||||
record_audit(
|
||||
db, current, action="recharge:yyb:selection", target=f"yyb_task:{task.task_id}",
|
||||
detail={
|
||||
"task_id": task.task_id, "product_id": task.product_id, "points": task.points,
|
||||
"zone_id": task.zone_id, "zone_name": task.zone_name, "role_id": task.role_id,
|
||||
"role_name": task.role_name, "price_fen": task.price_fen,
|
||||
},
|
||||
)
|
||||
db.commit()
|
||||
return public_task(task, creator_username=_creator_username(db, task))
|
||||
|
||||
@@ -156,11 +173,20 @@ def payment(task_id: int, db: Session = Depends(get_db), current: User = Depends
|
||||
task.phase = "payment"
|
||||
task.message = "生成付款码失败,请稍后重试"
|
||||
task.payment_started_at = None
|
||||
record_audit(
|
||||
db, current, action="recharge:yyb:payment", target=f"yyb_task:{task.task_id}",
|
||||
detail="生成付款码失败", success=False,
|
||||
)
|
||||
db.commit()
|
||||
raise
|
||||
task.status = str(data.get("status", "ordering"))
|
||||
task.phase = str(data.get("phase", "payment"))
|
||||
task.message = str(data.get("message", task.message))
|
||||
record_audit(
|
||||
db, current, action="recharge:yyb:payment", target=f"yyb_task:{task.task_id}",
|
||||
detail={"task_id": task.task_id, "product_id": task.product_id, "points": task.points,
|
||||
"price_fen": task.price_fen, "status": task.status},
|
||||
)
|
||||
db.commit()
|
||||
return public_task(task, include_qr=False, creator_username=_creator_username(db, task))
|
||||
|
||||
@@ -177,6 +203,11 @@ def payment_check(task_id: int, db: Session = Depends(get_db), current: User = D
|
||||
task.payment_last_checked_at = _utcnow()
|
||||
if task.status == "success":
|
||||
task.phase = "completed"
|
||||
record_audit(
|
||||
db, current, action="recharge:yyb:payment_check", target=f"yyb_task:{task.task_id}",
|
||||
detail={"task_id": task.task_id, "status": task.status, "message": task.message},
|
||||
success=task.status != "failed",
|
||||
)
|
||||
db.commit()
|
||||
return public_task(task, include_qr=False, creator_username=_creator_username(db, task))
|
||||
|
||||
@@ -189,5 +220,9 @@ def stop(task_id: int, db: Session = Depends(get_db), current: User = Depends(re
|
||||
task.phase = str(data.get("phase", "stopped"))
|
||||
task.message = str(data.get("message", "任务已停止"))
|
||||
task.finished_at = _utcnow()
|
||||
record_audit(
|
||||
db, current, action="recharge:yyb:stop", target=f"yyb_task:{task.task_id}",
|
||||
detail={"task_id": task.task_id, "status": task.status},
|
||||
)
|
||||
db.commit()
|
||||
return public_task(task, creator_username=_creator_username(db, task))
|
||||
|
||||
Reference in New Issue
Block a user