增加充值审计日志
This commit is contained in:
@@ -73,6 +73,7 @@ from ..services.huya_service import (
|
||||
upsert_huya_cookie,
|
||||
)
|
||||
from ..services.huya_runner import HuyaBatchRunner, huya_batch_registry
|
||||
from ..services.audit_service import record_audit
|
||||
from ..services.huya_register_runner import (
|
||||
export_success_logs_text,
|
||||
huya_register_registry,
|
||||
@@ -1292,12 +1293,19 @@ def update_config(
|
||||
):
|
||||
"""更新虎牙配置。"""
|
||||
config = ensure_huya_config(db)
|
||||
changed_fields = []
|
||||
for field in HUYA_CONFIG_FIELDS:
|
||||
value = getattr(req, field)
|
||||
if value is not None:
|
||||
setattr(config, field, value.strip())
|
||||
changed_fields.append(field)
|
||||
apply_huya_config_defaults(config)
|
||||
config.updated_at = datetime.now(timezone.utc)
|
||||
if changed_fields:
|
||||
record_audit(
|
||||
db, current, action="recharge:huya:config", target="huya_config",
|
||||
detail={"changed_fields": changed_fields},
|
||||
)
|
||||
db.commit()
|
||||
db.refresh(config)
|
||||
return _config_out(config)
|
||||
@@ -1356,6 +1364,16 @@ async def create_task_batch(
|
||||
if count == 0:
|
||||
raise HTTPException(status_code=400, detail="没有有效的虎牙账号")
|
||||
|
||||
if req.task_type == "create_recharge_order":
|
||||
record_audit(
|
||||
db, current, action="recharge:huya:create", target=f"huya_batch:{batch_id}",
|
||||
detail={
|
||||
"batch_id": batch_id, "task_type": req.task_type, "count": count,
|
||||
"account_count": len(req.account_ids),
|
||||
},
|
||||
)
|
||||
db.commit()
|
||||
|
||||
log_queue = asyncio.Queue()
|
||||
loop = asyncio.get_running_loop()
|
||||
thread_db = SessionLocal()
|
||||
@@ -1436,6 +1454,12 @@ def stop_batch(
|
||||
):
|
||||
"""停止正在运行的虎牙批次。"""
|
||||
_require_huya_batch_owner(db, current, batch_id)
|
||||
is_recharge_batch = (
|
||||
db.query(HuyaTask.id)
|
||||
.filter(HuyaTask.batch_id == batch_id, HuyaTask.task_type == "create_recharge_order")
|
||||
.first()
|
||||
is not None
|
||||
)
|
||||
batch = huya_batch_registry.get(batch_id)
|
||||
if batch:
|
||||
if batch.get("finished"):
|
||||
@@ -1449,6 +1473,12 @@ def stop_batch(
|
||||
return {"message": f"批次已结束,已清理 {cleaned} 个残留任务", "success": True}
|
||||
raise HTTPException(status_code=404, detail="批次已结束")
|
||||
batch["runner"].stop()
|
||||
if is_recharge_batch:
|
||||
record_audit(
|
||||
db, current, action="recharge:huya:stop", target=f"huya_batch:{batch_id}",
|
||||
detail={"batch_id": batch_id, "mode": "running"},
|
||||
)
|
||||
db.commit()
|
||||
return {"message": "已发送停止信号", "success": True}
|
||||
|
||||
cleaned = cleanup_orphan_huya_tasks(
|
||||
@@ -1457,6 +1487,12 @@ def stop_batch(
|
||||
message="任务已停止(批次不存在)",
|
||||
)
|
||||
if cleaned:
|
||||
if is_recharge_batch:
|
||||
record_audit(
|
||||
db, current, action="recharge:huya:stop", target=f"huya_batch:{batch_id}",
|
||||
detail={"batch_id": batch_id, "mode": "orphan_cleanup", "cleaned": cleaned},
|
||||
)
|
||||
db.commit()
|
||||
return {"message": f"已清理 {cleaned} 个残留任务", "success": True}
|
||||
raise HTTPException(status_code=404, detail="批次不存在或已结束")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user