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
@@ -51,6 +51,8 @@ export class WechatPayService {
/** 发起 API v3 请求 */
private async request(method: string, apiPath: string, body?: any) {
const url = `${WX_API_BASE}${apiPath}`
const bodyStr = body ? JSON.stringify(body) : ''
this.logger.log(`[wxpay-request] ${method} ${apiPath} 请求体: ${bodyStr}`)
try {
const res = await axios({
method,
@@ -63,9 +65,12 @@ export class WechatPayService {
},
data: body,
})
this.logger.log(`[wxpay-request] ${method} ${apiPath} 成功: ${JSON.stringify(res.data)}`)
return res.data
} catch (e: any) {
this.logger.error(`微信支付请求失败: ${method} ${apiPath}`, e.response?.data || e.message)
const errDetail = e.response?.data ? JSON.stringify(e.response.data) : e.message
const errStatus = e.response?.status || '无状态码'
this.logger.error(`[wxpay-request] ${method} ${apiPath} 失败 status=${errStatus}: ${errDetail}`)
throw e
}
}
@@ -99,8 +104,15 @@ export class WechatPayService {
amount: { total: amount, currency: 'CNY' },
payer: { openid },
}
this.logger.log(`[jsapiPay] 下单参数: description=${description}, outTradeNo=${outTradeNo}, amount=${amount}, openid=${openid}`)
this.logger.log(`[jsapiPay] 完整请求体: ${JSON.stringify(body)}`)
const result = await this.request('POST', '/v3/pay/transactions/jsapi', body)
this.logger.log(`[jsapiPay] 微信返回: ${JSON.stringify(result)}`)
const prepayId = result.prepay_id
if (!prepayId) {
this.logger.error(`[jsapiPay] 微信返回缺少prepay_id: ${JSON.stringify(result)}`)
throw new Error('微信下单失败: 缺少prepay_id')
}
// 生成小程序/JSAPI 调起支付参数
const nonce = crypto.randomBytes(16).toString('hex')
const timestamp = Math.floor(Date.now() / 1000).toString()