完善支付逻辑

This commit is contained in:
ywyonui 2025-07-21 17:56:49 +08:00
parent b0be4002d4
commit 0892a4771e
3 changed files with 51 additions and 15 deletions

View File

@ -27,10 +27,10 @@
<script lang="ts" setup> <script lang="ts" setup>
import { onLoad } from "@dcloudio/uni-app"; import { onLoad } from "@dcloudio/uni-app";
import { jzGetQkExpiredTime, jzXkCancelApi } from "@/api/base/server"; import { jzGetQkExpiredTime, jzXkCancelApi, jzXkJfCxjApi } from "@/api/base/server";
import { useUserStore } from "@/store/modules/user"; import { useUserStore } from "@/store/modules/user";
import { useDataStore } from "@/store/modules/data"; import { useDataStore } from "@/store/modules/data";
const { getCurXs, getUser, initWs, setWsCallback } = useUserStore(); const { getCurXs, initWs, setWsCallback } = useUserStore();
const { getData } = useDataStore(); const { getData } = useDataStore();
const payUrl = ref(""); const payUrl = ref("");
@ -108,8 +108,6 @@ const cancelRegistration = () => {
}); });
}; };
onLoad(async (options: any) => { onLoad(async (options: any) => {
if (options.payUrl) { if (options.payUrl) {
payUrl.value = decodeURIComponent(options.payUrl); payUrl.value = decodeURIComponent(options.payUrl);
@ -120,9 +118,39 @@ onLoad(async (options: any) => {
} else { } else {
uni.showToast({ title: '缺少支付地址', icon: 'none' }) uni.showToast({ title: '缺少支付地址', icon: 'none' })
setTimeout(() => { setTimeout(() => {
uni.navigateBack() goBack();
}, 1000) }, 1000)
} }
try {
const res = await jzXkJfCxjApi({
orderNumber: getData.orderNumber,
xsId: getData.xsId,
xkId: getData.xkId
});
// 01-02-03-04-
const { orderStat, respCode } = res.result;
if ("0000000000" === respCode) {
if ("02" === orderStat) {
uni.reLaunch({
url: "/pages/base/course-selection/payment-success",
});
} else if ("03" === orderStat) {
uni.reLaunch({
url: "/pages/base/course-selection/payment-fail",
});
}
} else {
uni.showToast({
title: "订单查询失败",
icon: "error",
});
setTimeout(() => {
goBack();
}, 2000);
}
} catch (error) {
console.log("订单查询失败", error);
}
}); });
onBeforeUnmount(() => { onBeforeUnmount(() => {

View File

@ -44,7 +44,7 @@ import { jzGetQkExpiredTime, jzXkCancelApi, jzXkFqJfjApi } from "@/api/base/serv
import { useUserStore } from "@/store/modules/user"; import { useUserStore } from "@/store/modules/user";
import { useDataStore } from "@/store/modules/data"; import { useDataStore } from "@/store/modules/data";
const { getCurXs, getUser } = useUserStore(); const { getCurXs, getUser } = useUserStore();
const { getData } = useDataStore(); const { getData, setData } = useDataStore();
// //
const curXs = computed(() => getCurXs); const curXs = computed(() => getCurXs);
@ -131,8 +131,12 @@ const payNow = async () => {
openId: getUser.openId, openId: getUser.openId,
}); });
if (res.resultCode === 1 && res.result) { if (res.resultCode === 1 && res.result) {
setData({
...getData,
...res.result
});
uni.redirectTo({ uni.redirectTo({
url: `/pages/base/course-selection/pay-wait?payUrl=${encodeURIComponent(res.result)}` url: `/pages/base/course-selection/pay-wait?payUrl=${encodeURIComponent(res.result.cashierPayHtml)}`
}); });
} }
} catch (error) { } catch (error) {

View File

@ -62,15 +62,19 @@ export const useUserStore = defineStore({
this.wsCallback = callback; this.wsCallback = callback;
}, },
initWs() { initWs() {
if (!this.ws) { if (this.ws) {
this.ws = useWebSocket(`/zhxy/webSocket/${this.userdata.userId}`, (type: string, res: any) => { if (typeof this.ws.closeConnect === 'function') {
// 判断this.wsCallback是函数调用 this.ws.closeConnect();
if (typeof this.wsCallback === "function") { }
this.wsCallback(type, res); this.ws = null;
}
});
this.ws.reconnect();
} }
this.ws = useWebSocket(`/zhxy/webSocket/${this.userdata.userId}`, (type: string, res: any) => {
// 判断this.wsCallback是函数调用
if (typeof this.wsCallback === "function") {
this.wsCallback(type, res);
}
});
this.ws.reconnect();
}, },
/** /**
* @description: * @description: