fix: share-gain防刷改用shareRecords统计(schema strict丢弃了临时字段)
This commit is contained in:
@@ -227,16 +227,12 @@ router.post('/share-gain', userAuthMiddleware, async (req, res) => {
|
||||
quota = new AIChatQuota({ openid })
|
||||
}
|
||||
|
||||
// [防刷] 每日分享奖励最多3次
|
||||
const today = new Date().toISOString().slice(0, 10)
|
||||
const shareDate = (quota.shareDate || '').toString().slice(0, 10)
|
||||
const shareCount = shareDate === today ? (quota.shareCount || 0) : 0
|
||||
if (shareCount >= 3) {
|
||||
// [防刷] 每日分享奖励最多3次(基于 shareRecords 统计)
|
||||
const dayStart = new Date(); dayStart.setHours(0, 0, 0, 0)
|
||||
const todayShares = (quota.shareRecords || []).filter(r => new Date(r.sharedAt) >= dayStart).length
|
||||
if (todayShares >= 3) {
|
||||
return ApiResponse.error(res, '今日分享奖励已领完,明天再来吧', 429)
|
||||
}
|
||||
quota.shareDate = new Date()
|
||||
quota.shareCount = shareCount + 1
|
||||
await quota.save()
|
||||
|
||||
const remainingQuota = await quota.addQuotaByShare(5)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user