【功能优化】支付:查询支付订单时,增加 sync 主动轮询,解决支付宝、微信存在延迟的问题

pull/105/MERGE
YunaiV 2024-09-24 09:04:57 +08:00
parent 27260f4a75
commit a1995c88e8
3 changed files with 40 additions and 24 deletions

View File

@ -81,7 +81,7 @@
import { fen2yuan, useDurationTime } from '@/sheep/hooks/useGoods'; import { fen2yuan, useDurationTime } from '@/sheep/hooks/useGoods';
import PayOrderApi from '@/sheep/api/pay/order'; import PayOrderApi from '@/sheep/api/pay/order';
import PayChannelApi from '@/sheep/api/pay/channel'; import PayChannelApi from '@/sheep/api/pay/channel';
import { getPayMethods } from '@/sheep/platform/pay'; import { getPayMethods, goPayResult } from '@/sheep/platform/pay';
const userWallet = computed(() => sheep.$store('user').userWallet); const userWallet = computed(() => sheep.$store('user').userWallet);
@ -135,12 +135,22 @@
// payOrder.status => payStatus // payOrder.status => payStatus
function checkPayStatus() { function checkPayStatus() {
if (state.orderInfo.status === 10 if (state.orderInfo.status === 10 || state.orderInfo.status === 20) {
|| state.orderInfo.status === 20 ) { // //
state.payStatus = 2; state.payStatus = 2;
//
uni.showModal({
title: '提示',
content: '订单已支付',
showCancel: false,
success: function () {
goPayResult(state.orderInfo.id, state.orderType);
},
});
return; return;
} }
if (state.orderInfo.status === 30) { // if (state.orderInfo.status === 30) {
//
state.payStatus = -1; state.payStatus = -1;
return; return;
} }
@ -155,26 +165,26 @@
// //
async function setOrder(id) { async function setOrder(id) {
// //
const { data, code } = await PayOrderApi.getOrder(id); const { data, code } = await PayOrderApi.getOrder(id, true);
if (code !== 0 || !data) { if (code !== 0 || !data) {
state.payStatus = -2; state.payStatus = -2;
return; return;
} }
state.orderInfo = data; state.orderInfo = data;
//
await setPayMethods();
// //
checkPayStatus(); checkPayStatus();
//
await setPayMethods();
} }
// //
async function setPayMethods() { async function setPayMethods() {
const { data, code } = await PayChannelApi.getEnableChannelCodeList(state.orderInfo.appId) const { data, code } = await PayChannelApi.getEnableChannelCodeList(state.orderInfo.appId);
if (code !== 0) { if (code !== 0) {
return return;
} }
state.payMethods = getPayMethods(data) state.payMethods = getPayMethods(data);
state.payMethods.find(item => { state.payMethods.find((item) => {
if (item.value && !item.disabled) { if (item.value && !item.disabled) {
state.payment = item.value; state.payment = item.value;
return true; return true;
@ -183,9 +193,11 @@
} }
onLoad((options) => { onLoad((options) => {
if (sheep.$platform.name === 'WechatOfficialAccount' if (
&& sheep.$platform.os === 'ios' sheep.$platform.name === 'WechatOfficialAccount' &&
&& !sheep.$platform.landingPage.includes('pages/pay/index')) { sheep.$platform.os === 'ios' &&
!sheep.$platform.landingPage.includes('pages/pay/index')
) {
location.reload(); location.reload();
return; return;
} }
@ -214,7 +226,6 @@
position: relative; position: relative;
padding: 60rpx 20rpx 40rpx; padding: 60rpx 20rpx 40rpx;
.money-text { .money-text {
color: $red; color: $red;
font-size: 46rpx; font-size: 46rpx;

View File

@ -2,11 +2,11 @@ import request from '@/sheep/request';
const PayOrderApi = { const PayOrderApi = {
// 获得支付订单 // 获得支付订单
getOrder: (id) => { getOrder: (id, sync) => {
return request({ return request({
url: '/pay/order/get', url: '/pay/order/get',
method: 'GET', method: 'GET',
params: { id } params: { id, sync },
}); });
}, },
// 提交支付订单 // 提交支付订单
@ -14,9 +14,9 @@ const PayOrderApi = {
return request({ return request({
url: '/pay/order/submit', url: '/pay/order/submit',
method: 'POST', method: 'POST',
data data,
}); });
} },
}; };
export default PayOrderApi; export default PayOrderApi;

View File

@ -270,11 +270,7 @@ export default class SheepPay {
// 支付结果跳转,success:成功fail:失败 // 支付结果跳转,success:成功fail:失败
payResult(resultType) { payResult(resultType) {
sheep.$router.redirect('/pages/pay/result', { goPayResult(this.id, this.orderType, resultType);
id: this.id,
orderType: this.orderType,
payState: resultType,
});
} }
// 引导绑定微信 // 引导绑定微信
@ -359,3 +355,12 @@ export function getPayMethods(channels) {
} }
return payMethods; return payMethods;
} }
// 支付结果跳转,success:成功fail:失败
export function goPayResult(id, orderType, resultType) {
sheep.$router.redirect('/pages/pay/result', {
id,
orderType,
payState: resultType,
});
}