feat(计费): 根据使用时长调整积分扣除逻辑
在生成播客任务中新增usetime字段记录使用时长,并在积分扣除时根据时长调整扣分倍数。当使用时长为8-15分钟时,积分扣除翻倍。
This commit is contained in:
@@ -265,6 +265,7 @@ async def _generate_podcast_task(
|
|||||||
"task_results": task_results[auth_id][task_id],
|
"task_results": task_results[auth_id][task_id],
|
||||||
"timestamp": int(time.time()),
|
"timestamp": int(time.time()),
|
||||||
"status": task_results[auth_id][task_id]["status"],
|
"status": task_results[auth_id][task_id]["status"],
|
||||||
|
"usetime": usetime,
|
||||||
}
|
}
|
||||||
|
|
||||||
MAX_RETRIES = 3 # 定义最大重试次数
|
MAX_RETRIES = 3 # 定义最大重试次数
|
||||||
@@ -326,6 +327,7 @@ async def generate_podcast_submission(
|
|||||||
"timestamp": time.time(),
|
"timestamp": time.time(),
|
||||||
"callback_url": callback_url, # 存储回调地址
|
"callback_url": callback_url, # 存储回调地址
|
||||||
"auth_id": auth_id, # 存储 auth_id
|
"auth_id": auth_id, # 存储 auth_id
|
||||||
|
"usetime": usetime,
|
||||||
}
|
}
|
||||||
|
|
||||||
background_tasks.add_task(
|
background_tasks.add_task(
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ export async function GET(request: NextRequest) { // GET 函数接收 request
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function PUT(request: NextRequest) {
|
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 lang = getLanguageFromRequest(request); // 获取语言
|
||||||
const { t } = await getTranslation(lang, 'errors'); // 初始化翻译
|
const { t } = await getTranslation(lang, 'errors'); // 初始化翻译
|
||||||
try {
|
try {
|
||||||
@@ -63,7 +63,11 @@ export async function PUT(request: NextRequest) {
|
|||||||
const userId = auth_id; // 这里假设 auth_id 就是 userId
|
const userId = auth_id; // 这里假设 auth_id 就是 userId
|
||||||
|
|
||||||
// 5. 扣减积分
|
// 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 reasonCode = "podcast_generation";
|
||||||
const description = `${t("podcast_generation_task")}: ${task_id}`; // 多语言实现
|
const description = `${t("podcast_generation_task")}: ${task_id}`; // 多语言实现
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user