|
|
|
|
@ -274,17 +274,197 @@
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 支付订单
|
|
|
|
|
const payOrder = (order) => {
|
|
|
|
|
// 微信支付
|
|
|
|
|
const wechatPay = async (orderInfo) => {
|
|
|
|
|
// #ifdef MP-WEIXIN
|
|
|
|
|
// 微信小程序支付
|
|
|
|
|
try {
|
|
|
|
|
const paymentResult = await uni.requestPayment({
|
|
|
|
|
provider: "wxpay",
|
|
|
|
|
timeStamp: orderInfo.timeStamp,
|
|
|
|
|
nonceStr: orderInfo.nonceStr,
|
|
|
|
|
package: orderInfo.package,
|
|
|
|
|
signType: orderInfo.signType,
|
|
|
|
|
paySign: orderInfo.paySign,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
console.log("微信支付成功:", paymentResult);
|
|
|
|
|
return {
|
|
|
|
|
success: true,
|
|
|
|
|
data: paymentResult
|
|
|
|
|
};
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error("微信支付失败:", error);
|
|
|
|
|
if (error.errMsg === "requestPayment:fail cancel") {
|
|
|
|
|
throw new Error("用户取消支付");
|
|
|
|
|
}
|
|
|
|
|
throw new Error("微信支付失败");
|
|
|
|
|
}
|
|
|
|
|
// #endif
|
|
|
|
|
|
|
|
|
|
// #ifdef H5
|
|
|
|
|
// H5微信支付
|
|
|
|
|
if (typeof WeixinJSBridge !== "undefined") {
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
WeixinJSBridge.invoke(
|
|
|
|
|
"getBrandWCPayRequest", {
|
|
|
|
|
appId: 'wxc504638e03981812',
|
|
|
|
|
timeStamp: orderInfo.timeStamp,
|
|
|
|
|
nonceStr: orderInfo.nonceStr,
|
|
|
|
|
package: orderInfo.package,
|
|
|
|
|
signType: orderInfo.signType,
|
|
|
|
|
paySign: orderInfo.paySign,
|
|
|
|
|
},
|
|
|
|
|
(res) => {
|
|
|
|
|
if (res.err_msg === "get_brand_wcpay_request:ok") {
|
|
|
|
|
resolve({
|
|
|
|
|
success: true,
|
|
|
|
|
data: res
|
|
|
|
|
});
|
|
|
|
|
} else if (res.err_msg === "get_brand_wcpay_request:cancel") {
|
|
|
|
|
reject(new Error("用户取消支付"));
|
|
|
|
|
} else {
|
|
|
|
|
reject(new Error("微信支付失败"));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
// 不在微信环境,跳转到支付页面
|
|
|
|
|
const payUrl = orderInfo.mwebUrl; // 后端返回的H5支付链接
|
|
|
|
|
window.location.href = payUrl;
|
|
|
|
|
return {
|
|
|
|
|
success: true,
|
|
|
|
|
redirect: true
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
// #endif
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// 支付宝支付(仅H5环境)
|
|
|
|
|
const alipayPay = async (orderInfo) => {
|
|
|
|
|
// #ifdef H5
|
|
|
|
|
// H5支付宝支付
|
|
|
|
|
const payUrl = orderInfo.payUrl; // 后端返回的支付宝H5支付链接
|
|
|
|
|
window.location.href = payUrl;
|
|
|
|
|
return {
|
|
|
|
|
success: true,
|
|
|
|
|
redirect: true
|
|
|
|
|
};
|
|
|
|
|
// #endif
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
function showModalAsync(options) {
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
uni.showModal({
|
|
|
|
|
...options,
|
|
|
|
|
success: (res) => {
|
|
|
|
|
resolve(res); // 将用户操作结果传递给 await
|
|
|
|
|
},
|
|
|
|
|
fail: (err) => {
|
|
|
|
|
reject(err); // 处理失败情况
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 支付订单
|
|
|
|
|
const payOrder = async (order) => {
|
|
|
|
|
try {
|
|
|
|
|
uni.showLoading({
|
|
|
|
|
title: "正在处理支付...",
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// 根据订单的支付渠道调用对应的支付方法
|
|
|
|
|
let paymentResult;
|
|
|
|
|
|
|
|
|
|
if (order.pay_channel === "wxpay") {
|
|
|
|
|
const res = await uni.login({
|
|
|
|
|
provider: 'weixin'
|
|
|
|
|
})
|
|
|
|
|
const orderResult = await RPC.post('/membership/order/pay_by_wechat_mini', {
|
|
|
|
|
code: res.code,
|
|
|
|
|
"order_no": order.order_no
|
|
|
|
|
})
|
|
|
|
|
uni.showLoading({
|
|
|
|
|
title: "正在跳转微信支付...",
|
|
|
|
|
});
|
|
|
|
|
console.log('orderResult', orderResult)
|
|
|
|
|
paymentResult = await wechatPay(orderResult);
|
|
|
|
|
} else if (order.pay_channel === "alipay") {
|
|
|
|
|
const orderResult = await RPC.post('/membership/order/pay_by_alipay', {
|
|
|
|
|
order_no: order.order_no
|
|
|
|
|
})
|
|
|
|
|
uni.showLoading({
|
|
|
|
|
title: "正在跳转支付宝...",
|
|
|
|
|
});
|
|
|
|
|
paymentResult = await alipayPay(orderResult);
|
|
|
|
|
} else if (order.pay_channel === 'wallet') {
|
|
|
|
|
const res = await showModalAsync({
|
|
|
|
|
title: '确认支付',
|
|
|
|
|
content: '确定继续支付这个订单吗?',
|
|
|
|
|
success: async (res) => {
|
|
|
|
|
content: '确认使用钱包余额支付?'
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// 同步判断逻辑
|
|
|
|
|
if (res.confirm) {
|
|
|
|
|
paymentResult = await RPC.post('/membership/order/pay_by_wallet', {
|
|
|
|
|
order_no: order.order_no
|
|
|
|
|
})
|
|
|
|
|
console.log('paymentResult', paymentResult)
|
|
|
|
|
} else if (res.cancel) {
|
|
|
|
|
console.log('用户点击了取消');
|
|
|
|
|
paymentResult = { success: false }
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uni.hideLoading();
|
|
|
|
|
console.log('paymentResult', paymentResult)
|
|
|
|
|
|
|
|
|
|
// 处理支付结果
|
|
|
|
|
if (paymentResult?.success) {
|
|
|
|
|
if (paymentResult.redirect) {
|
|
|
|
|
// H5跳转支付,不需要额外处理
|
|
|
|
|
uni.showToast({
|
|
|
|
|
title: "正在跳转支付页面...",
|
|
|
|
|
icon: "loading",
|
|
|
|
|
duration: 2000,
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
// 支付成功
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
uni.showToast({
|
|
|
|
|
title: "支付成功",
|
|
|
|
|
icon: "success",
|
|
|
|
|
});
|
|
|
|
|
// 更新订单状态
|
|
|
|
|
const index = list.value.findIndex(item => item.id === order.id)
|
|
|
|
|
if (index !== -1) {
|
|
|
|
|
list.value[index].status = 'paid'
|
|
|
|
|
}
|
|
|
|
|
// 刷新订单列表
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
getList()
|
|
|
|
|
}, 500)
|
|
|
|
|
}, 1000)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} catch (error) {
|
|
|
|
|
uni.hideLoading();
|
|
|
|
|
console.error("支付失败:", error);
|
|
|
|
|
let errorMessage = "支付失败,请重试";
|
|
|
|
|
if (error.message === "用户取消支付") {
|
|
|
|
|
errorMessage = "支付已取消";
|
|
|
|
|
} else if (error.message) {
|
|
|
|
|
errorMessage = error.message;
|
|
|
|
|
} else if (error) {
|
|
|
|
|
errorMessage = error
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uni.showToast({
|
|
|
|
|
title: errorMessage,
|
|
|
|
|
icon: "none",
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const page = ref(1)
|
|
|
|
|
|