From a1995c88e8fcbabecdc3626e25935187608b247d Mon Sep 17 00:00:00 2001 From: YunaiV Date: Tue, 24 Sep 2024 09:04:57 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E5=8A=9F=E8=83=BD=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E3=80=91=E6=94=AF=E4=BB=98=EF=BC=9A=E6=9F=A5=E8=AF=A2=E6=94=AF?= =?UTF-8?q?=E4=BB=98=E8=AE=A2=E5=8D=95=E6=97=B6=EF=BC=8C=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=20sync=20=E4=B8=BB=E5=8A=A8=E8=BD=AE=E8=AF=A2=EF=BC=8C?= =?UTF-8?q?=E8=A7=A3=E5=86=B3=E6=94=AF=E4=BB=98=E5=AE=9D=E3=80=81=E5=BE=AE?= =?UTF-8?q?=E4=BF=A1=E5=AD=98=E5=9C=A8=E5=BB=B6=E8=BF=9F=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/pay/index.vue | 41 ++++++++++++++++++++++++++--------------- sheep/api/pay/order.js | 8 ++++---- sheep/platform/pay.js | 15 ++++++++++----- 3 files changed, 40 insertions(+), 24 deletions(-) diff --git a/pages/pay/index.vue b/pages/pay/index.vue index 103e9e4d..11069038 100644 --- a/pages/pay/index.vue +++ b/pages/pay/index.vue @@ -81,7 +81,7 @@ import { fen2yuan, useDurationTime } from '@/sheep/hooks/useGoods'; import PayOrderApi from '@/sheep/api/pay/order'; 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); @@ -135,12 +135,22 @@ // 状态转换:payOrder.status => payStatus function checkPayStatus() { - if (state.orderInfo.status === 10 - || state.orderInfo.status === 20 ) { // 支付成功 + if (state.orderInfo.status === 10 || state.orderInfo.status === 20) { + // 支付成功 state.payStatus = 2; + // 跳转回支付成功页 + uni.showModal({ + title: '提示', + content: '订单已支付', + showCancel: false, + success: function () { + goPayResult(state.orderInfo.id, state.orderType); + }, + }); return; } - if (state.orderInfo.status === 30) { // 支付关闭 + if (state.orderInfo.status === 30) { + // 支付关闭 state.payStatus = -1; return; } @@ -155,26 +165,26 @@ // 设置支付订单信息 async function setOrder(id) { // 获得支付订单信息 - const { data, code } = await PayOrderApi.getOrder(id); + const { data, code } = await PayOrderApi.getOrder(id, true); if (code !== 0 || !data) { state.payStatus = -2; return; } state.orderInfo = data; - // 获得支付方式 - await setPayMethods(); // 设置支付状态 checkPayStatus(); + // 获得支付方式 + await 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) { - return + return; } - state.payMethods = getPayMethods(data) - state.payMethods.find(item => { + state.payMethods = getPayMethods(data); + state.payMethods.find((item) => { if (item.value && !item.disabled) { state.payment = item.value; return true; @@ -183,9 +193,11 @@ } onLoad((options) => { - if (sheep.$platform.name === 'WechatOfficialAccount' - && sheep.$platform.os === 'ios' - && !sheep.$platform.landingPage.includes('pages/pay/index')) { + if ( + sheep.$platform.name === 'WechatOfficialAccount' && + sheep.$platform.os === 'ios' && + !sheep.$platform.landingPage.includes('pages/pay/index') + ) { location.reload(); return; } @@ -214,7 +226,6 @@ position: relative; padding: 60rpx 20rpx 40rpx; - .money-text { color: $red; font-size: 46rpx; diff --git a/sheep/api/pay/order.js b/sheep/api/pay/order.js index f9853596..f7bef28f 100644 --- a/sheep/api/pay/order.js +++ b/sheep/api/pay/order.js @@ -2,11 +2,11 @@ import request from '@/sheep/request'; const PayOrderApi = { // 获得支付订单 - getOrder: (id) => { + getOrder: (id, sync) => { return request({ url: '/pay/order/get', method: 'GET', - params: { id } + params: { id, sync }, }); }, // 提交支付订单 @@ -14,9 +14,9 @@ const PayOrderApi = { return request({ url: '/pay/order/submit', method: 'POST', - data + data, }); - } + }, }; export default PayOrderApi; diff --git a/sheep/platform/pay.js b/sheep/platform/pay.js index d714374d..ced3aa07 100644 --- a/sheep/platform/pay.js +++ b/sheep/platform/pay.js @@ -270,11 +270,7 @@ export default class SheepPay { // 支付结果跳转,success:成功,fail:失败 payResult(resultType) { - sheep.$router.redirect('/pages/pay/result', { - id: this.id, - orderType: this.orderType, - payState: resultType, - }); + goPayResult(this.id, this.orderType, resultType); } // 引导绑定微信 @@ -359,3 +355,12 @@ export function getPayMethods(channels) { } return payMethods; } + +// 支付结果跳转,success:成功,fail:失败 +export function goPayResult(id, orderType, resultType) { + sheep.$router.redirect('/pages/pay/result', { + id, + orderType, + payState: resultType, + }); +}