更新.gitignore以排除部署配置文件,删除不再使用的一键部署脚本,优化小程序部署流程,增强文档说明。
This commit is contained in:
@@ -52,15 +52,15 @@ export async function POST(request: NextRequest) {
|
||||
|
||||
const user = users[0]
|
||||
|
||||
// 检查是否绑定支付方式(微信号或支付宝)
|
||||
// 如果没有绑定,提示用户先绑定
|
||||
// 微信零钱提现需要 open_id(小程序/公众号登录获得)
|
||||
const openId = user.open_id || ''
|
||||
const wechatId = user.wechat || user.wechat_id || ''
|
||||
const alipayId = user.alipay || ''
|
||||
|
||||
if (!wechatId && !alipayId) {
|
||||
if (!openId && !alipayId) {
|
||||
return NextResponse.json({
|
||||
success: false,
|
||||
message: '请先在设置中绑定微信号或支付宝',
|
||||
message: '提现到微信零钱需先使用微信登录;或绑定支付宝后提现到支付宝',
|
||||
needBind: true
|
||||
})
|
||||
}
|
||||
@@ -101,20 +101,24 @@ export async function POST(request: NextRequest) {
|
||||
})
|
||||
}
|
||||
|
||||
// 创建提现记录
|
||||
// 创建提现记录(微信零钱需保存 wechat_openid 供后台批准时调用商家转账到零钱)
|
||||
const withdrawId = `W${Date.now()}`
|
||||
const accountType = alipayId ? 'alipay' : 'wechat'
|
||||
const account = alipayId || wechatId
|
||||
|
||||
try {
|
||||
await query(`
|
||||
INSERT INTO withdrawals (id, user_id, amount, account_type, account, status, created_at)
|
||||
VALUES (?, ?, ?, ?, ?, 'pending', NOW())
|
||||
`, [withdrawId, userId, amount, accountType, account])
|
||||
INSERT INTO withdrawals (id, user_id, amount, status, wechat_openid, created_at)
|
||||
VALUES (?, ?, ?, 'pending', ?, NOW())
|
||||
`, [withdrawId, userId, amount, accountType === 'wechat' ? openId : null])
|
||||
|
||||
// TODO: 实际调用微信企业付款或支付宝转账API
|
||||
// 这里先模拟成功
|
||||
await query(`UPDATE withdrawals SET status = 'completed', completed_at = NOW() WHERE id = ?`, [withdrawId])
|
||||
// 微信零钱由后台批准时调用「商家转账到零钱」;支付宝/无 openid 时仅标记成功(需线下打款)
|
||||
if (accountType !== 'wechat' || !openId) {
|
||||
await query(`UPDATE withdrawals SET status = 'success', processed_at = NOW() WHERE id = ?`, [withdrawId])
|
||||
await query(`
|
||||
UPDATE users SET withdrawn_earnings = withdrawn_earnings + ?, pending_earnings = GREATEST(0, pending_earnings - ?) WHERE id = ?
|
||||
`, [amount, amount, userId])
|
||||
}
|
||||
} catch (e) {
|
||||
console.log('[Withdraw] 创建提现记录失败:', e)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user