feat(计费): 根据使用时长调整积分扣除逻辑

在生成播客任务中新增usetime字段记录使用时长,并在积分扣除时根据时长调整扣分倍数。当使用时长为8-15分钟时,积分扣除翻倍。
This commit is contained in:
hex2077
2025-08-27 00:41:10 +08:00
parent 03ac351930
commit ecef7718b9
2 changed files with 8 additions and 2 deletions

View File

@@ -30,7 +30,7 @@ export async function GET(request: NextRequest) { // GET 函数接收 request
}
export async function PUT(request: NextRequest) {
const { task_id, auth_id, timestamp, status } = await request.json();
const { task_id, auth_id, timestamp, status, usetime } = await request.json();
const lang = getLanguageFromRequest(request); // 获取语言
const { t } = await getTranslation(lang, 'errors'); // 初始化翻译
try {
@@ -63,7 +63,11 @@ export async function PUT(request: NextRequest) {
const userId = auth_id; // 这里假设 auth_id 就是 userId
// 5. 扣减积分
const pointsToDeduct = parseInt(process.env.POINTS_PER_PODCAST || '10', 10); // 从环境变量获取默认10
let pointsToDeduct = parseInt(process.env.POINTS_PER_PODCAST || '10', 10); // 从环境变量获取默认10
if(usetime === '8-15 minutes') {
pointsToDeduct = pointsToDeduct * 2;
}
const reasonCode = "podcast_generation";
const description = `${t("podcast_generation_task")}: ${task_id}`; // 多语言实现