修正失败的任务总积分同步

This commit is contained in:
2026-06-03 17:45:34 +08:00
parent 846eaa0eb0
commit 71dbf01fc8
3 changed files with 54 additions and 9 deletions
@@ -109,7 +109,7 @@ async def refund_unrefunded_media_charges(
db,
user_id=user_id,
amount=amount,
description=f"{description_prefix}失败积分回退 attempt:{attempt_no}",
description=f"{description_prefix}失败积分回退",
related_id=owner_id,
biz_key=refund_biz_key,
refund_for_biz_key=charge.biz_key,
@@ -149,13 +149,17 @@ async def mark_generation_record_failed_and_refund_once(
if error_message:
record.error_message = error_message
await refund_unrefunded_media_charges(
refunded_amount = await refund_unrefunded_media_charges(
db,
user_id=record.user_id,
owner_type=OWNER_GENERATION_RECORD,
owner_id=record.id,
description_prefix="生成记录",
)
if refunded_amount > 0:
# GenerationRecord.credits_cost 只代表视频/图片生成媒体积分。
# 提示词优化积分在 text_credits_cost 中记录,优化成功后不参与生成失败退款。
record.credits_cost = max(0.0, round(float(record.credits_cost or 0) - refunded_amount, 2))
await db.flush()
return record
@@ -194,12 +198,15 @@ async def mark_chat_generation_task_failed_and_refund_once(
if error_message:
task.error_message = error_message
await refund_unrefunded_media_charges(
refunded_amount = await refund_unrefunded_media_charges(
db,
user_id=task.user_id,
owner_type=OWNER_CHAT_GENERATION_TASK,
owner_id=task.id,
description_prefix="Chat生成任务",
)
if refunded_amount > 0:
task.credits_cost = max(0.0, round(float(task.credits_cost or 0) - refunded_amount, 2))
await db.flush()
return task