diff --git a/laf-cloud/functions/passCheckSettlement.ts b/laf-cloud/functions/passCheckSettlement.ts index 06097ba..47154d3 100644 --- a/laf-cloud/functions/passCheckSettlement.ts +++ b/laf-cloud/functions/passCheckSettlement.ts @@ -46,8 +46,10 @@ export function expiredSnapshots(user: any, now = Date.now()): any { for (const key of Object.keys(stages)) { const stage = stages[key], end = Number(stage?.time || key); if (!end || end > now || result[String(end)]) continue; - result[String(end)] = { end, stage: copy({ ...stage, time: String(end) }), frozenAt: now, - claimed: false, emptySeen: false, offer: 'unused' }; + result[String(end)] = { + end, stage: copy({ ...stage, time: String(end) }), frozenAt: now, + claimed: false, emptySeen: false, offer: 'unused' + }; } return result; } @@ -87,8 +89,10 @@ async function flushPending(user: any, table: string): Promise { * can commit until that receipt has been durably copied to the independent archive. */ export async function commitUserSettlement(user: any, row: any, patch: any, expected: any, table = 'users', unset: any = {}): Promise { const revision = (Number(user.passSettlementRevision) || 0) + 1; - const written = await collection(table).updateOne({ ...expected, _id: user._id, - passSettlementRevision: user.passSettlementRevision ?? null, passSettlementPending: null }, { + const written = await collection(table).updateOne({ + ...expected, _id: user._id, + passSettlementRevision: user.passSettlementRevision ?? null, passSettlementPending: null + }, { $set: { ...patch, passSettlementRevision: revision, passSettlementPending: { revision, row } }, ...(Object.keys(unset).length ? { $unset: unset } : {}) }); @@ -184,7 +188,7 @@ export async function mutateSettlement(user: any, body: any, table = 'users'): P rewards = normalizeRewards(body.rewards); if (body.claimFlags) for (const lane of purchase ? ['passCheck'] : ['free', 'passCheck']) { const flags = body.claimFlags[lane]; - if (!Array.isArray(flags) || flags.length > 10000 || flags.some(v => v !== 0 && v !== 1 && v !== null)) fail('领取记录无效', 400); + if (!Array.isArray(flags) || flags.length > 10000 || flags.some(v => v !== 0 && v !== -1 && v !== 1 && v !== null)) fail('领取记录无效', 400); next.stage[lane] = [...(next.stage[lane] || [])]; flags.forEach((v, i) => { if (v === 0) next.stage[lane][i] = 0; }); }