feat: unified gravity system - VIP members consume gravity instead of unlimited; add monthly gravity top-up cron

This commit is contained in:
yuzhiran
2026-06-19 22:43:52 +08:00
parent c2ba810a02
commit 2fbab1072f
22 changed files with 956 additions and 216 deletions
+10 -10
View File
@@ -113,7 +113,7 @@ export class AdminController {
expireAt.setDate(expireAt.getDate() + (pricing.plans?.growth?.durationDays || VIP_DURATION_DAYS))
user.plan = 'growth'
user.vipExpireAt = expireAt
await this.quotaService.setPlanQuota(targetUserId, 'growth', credits)
await this.quotaService.setPlanQuota(targetUserId, pricing.plans?.growth?.gravityPerMonth || 250)
return { success: true, plan: 'growth', expireAt }
}
@@ -122,7 +122,7 @@ export class AdminController {
if (!userId || !type || amount === undefined) {
throw new HttpException('参数不完整', HttpStatus.BAD_REQUEST)
}
const validTypes = ['interviewCredits', 'resumeOptimizeCredits', 'resumeDownloadCredits', 'shareCredits']
const validTypes = ['interviewCredits', 'resumeOptimizeCredits', 'resumeDownloadCredits', 'shareCredits', 'gravity']
if (!validTypes.includes(type)) {
throw new HttpException('无效的额度类型', HttpStatus.BAD_REQUEST)
}
@@ -291,18 +291,18 @@ export class AdminController {
} else {
user.vipExpireAt = expireAt
}
await this.quotaService.setPlanQuota(order.userId, planId, credits)
await this.quotaService.setPlanQuota(order.userId, planCfg.gravityPerMonth)
}
} else {
const pricing = await this.pricingService.getConfig()
const creditMap: Record<string, number> = {
interview: pricing.interview?.creditsPerPurchase || 1,
optimize: pricing.resumeOptimize?.creditsPerPurchase || 1,
download: pricing.resumeDownload?.creditsPerPurchase || 1,
const gravityMap: Record<string, number> = {
interview: pricing.gravityRates?.interviewPerUse || 5,
optimize: pricing.gravityRates?.optimizePerUse || 3,
download: pricing.gravityRates?.downloadPerUse || 2,
}
const credits = creditMap[order.type]
if (credits) {
await this.quotaService.grantCredits(order.userId, order.type as any, credits)
const g = gravityMap[order.type]
if (g) {
await this.quotaService.grantGravity(order.userId, g)
}
}
}