|
|
@@ -102,27 +102,76 @@ const PaymentPage = () => {
|
|
|
rateLimiter.recordAttempt(orderId)
|
|
|
|
|
|
// 调用微信支付
|
|
|
+ // console.debug('开始调用微信支付...')
|
|
|
const paymentResult = await requestWechatPayment(paymentData)
|
|
|
+ // console.debug('微信支付调用完成,结果:', paymentResult)
|
|
|
|
|
|
if (paymentResult.success) {
|
|
|
// 支付成功
|
|
|
- setPaymentStatus(PaymentStatus.SUCCESS)
|
|
|
+ // console.debug('微信支付成功,开始更新状态')
|
|
|
+ // console.debug('更新前支付状态:', paymentStatus)
|
|
|
+
|
|
|
+ // 使用函数式更新确保状态正确设置
|
|
|
+ setPaymentStatus(prevStatus => {
|
|
|
+ console.debug('setPaymentStatus 被调用,前一个状态:', prevStatus, '新状态:', PaymentStatus.SUCCESS)
|
|
|
+ return PaymentStatus.SUCCESS
|
|
|
+ })
|
|
|
+
|
|
|
paymentStateManager.setPaymentState(orderId, PaymentStatus.SUCCESS)
|
|
|
|
|
|
// 清除频率限制记录
|
|
|
rateLimiter.clearAttempts(orderId)
|
|
|
|
|
|
- // 跳转到支付成功页面
|
|
|
+
|
|
|
+ // 调用后端API更新订单支付状态为已支付 (2)
|
|
|
+ try {
|
|
|
+ // console.debug('开始调用后端API更新订单支付状态')
|
|
|
+ await paymentClient.payment.updateOrderStatus.$post({
|
|
|
+ json: {
|
|
|
+ orderId: orderId,
|
|
|
+ payState: 2 // 2表示支付成功
|
|
|
+ }
|
|
|
+ })
|
|
|
+ // console.debug('数据库订单支付状态更新成功')
|
|
|
+ } catch (error) {
|
|
|
+ console.error('数据库更新订单支付状态失败:', error)
|
|
|
+ // 这里不抛出错误,因为支付已经成功,只是状态同步失败
|
|
|
+ // 可以记录日志或发送通知给管理员
|
|
|
+ }
|
|
|
+
|
|
|
+ // console.debug('支付状态已更新为SUCCESS,准备跳转')
|
|
|
+
|
|
|
+ // 强制触发UI重新渲染
|
|
|
setTimeout(() => {
|
|
|
+ // console.debug('强制触发UI更新')
|
|
|
+ setPaymentStatus(currentStatus => currentStatus)
|
|
|
+ }, 100)
|
|
|
+
|
|
|
+ // 确保状态更新显示在UI上
|
|
|
+ setTimeout(() => {
|
|
|
+ // console.debug('开始跳转到支付成功页面')
|
|
|
Taro.redirectTo({
|
|
|
url: `/pages/payment-success/index?orderId=${orderId}&amount=${amount}`
|
|
|
})
|
|
|
- }, 1500)
|
|
|
+ }, 2000) // 增加延迟时间,确保用户看到成功状态
|
|
|
} else {
|
|
|
// 支付失败
|
|
|
- setPaymentStatus(PaymentStatus.FAILED)
|
|
|
+ console.debug('支付失败,开始更新状态')
|
|
|
+ console.debug('更新前支付状态:', paymentStatus)
|
|
|
+
|
|
|
+ setPaymentStatus(prevStatus => {
|
|
|
+ console.debug('setPaymentStatus 被调用,前一个状态:', prevStatus, '新状态:', PaymentStatus.FAILED)
|
|
|
+ return PaymentStatus.FAILED
|
|
|
+ })
|
|
|
paymentStateManager.setPaymentState(orderId, PaymentStatus.FAILED)
|
|
|
|
|
|
+ await paymentClient.payment.updateOrderStatus.$post({
|
|
|
+ json: {
|
|
|
+ orderId: orderId,
|
|
|
+ payState: 3 // 3表示支付失败
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
if (paymentResult.type === 'cancel') {
|
|
|
setErrorMessage('用户取消支付')
|
|
|
} else {
|
|
|
@@ -154,15 +203,34 @@ const PaymentPage = () => {
|
|
|
)
|
|
|
|
|
|
if (retryResult.success) {
|
|
|
+ console.debug('重试支付成功,开始更新状态')
|
|
|
setPaymentStatus(PaymentStatus.SUCCESS)
|
|
|
paymentStateManager.setPaymentState(orderId, PaymentStatus.SUCCESS)
|
|
|
|
|
|
+ // 调用后端API更新订单支付状态为已支付 (2)
|
|
|
+ try {
|
|
|
+ console.debug('开始调用后端API更新订单支付状态(重试)')
|
|
|
+ await paymentClient.payment.updateOrderStatus.$post({
|
|
|
+ json: {
|
|
|
+ orderId: orderId,
|
|
|
+ payState: 2 // 2表示支付成功
|
|
|
+ }
|
|
|
+ })
|
|
|
+ console.debug('订单支付状态更新成功(重试)')
|
|
|
+ } catch (error) {
|
|
|
+ console.error('更新订单支付状态失败(重试):', error)
|
|
|
+ // 这里不抛出错误,因为支付已经成功,只是状态同步失败
|
|
|
+ }
|
|
|
+
|
|
|
+ console.debug('重试支付状态已更新为SUCCESS,准备跳转')
|
|
|
+
|
|
|
// 跳转到支付成功页面
|
|
|
setTimeout(() => {
|
|
|
+ console.debug('开始跳转到支付成功页面(重试)')
|
|
|
Taro.redirectTo({
|
|
|
url: `/pages/payment-success/index?orderId=${orderId}&amount=${amount}`
|
|
|
})
|
|
|
- }, 1500)
|
|
|
+ }, 2000) // 增加延迟时间,确保用户看到成功状态
|
|
|
} else {
|
|
|
setPaymentStatus(PaymentStatus.FAILED)
|
|
|
setErrorMessage(retryResult.message || '支付重试失败')
|
|
|
@@ -298,8 +366,8 @@ const PaymentPage = () => {
|
|
|
)}
|
|
|
|
|
|
{paymentStatus === PaymentStatus.SUCCESS && (
|
|
|
- <Button disabled className="w-full h-22 bg-gray-100 text-gray-500 rounded-full text-sm">
|
|
|
- 支付成功
|
|
|
+ <Button disabled className="w-full h-22 bg-green-500 text-white rounded-full text-lg font-bold">
|
|
|
+ ✓ 支付成功
|
|
|
</Button>
|
|
|
)}
|
|
|
</View>
|