From 74e34fc94ac31e89306e2d0d99ffa4c075ad097c Mon Sep 17 00:00:00 2001 From: wangdong <1551135706@qq.com> Date: Wed, 31 Jul 2024 19:00:07 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E8=B7=B3=E8=BD=AC=E7=AC=AC=E4=B8=89?= =?UTF-8?q?=E6=96=B9=E6=94=AF=E4=BB=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/cashier/index.js | 9 +++++++ pages/checkout/cashier/index.vue | 42 ++++++++++++++++++++++++-------- 2 files changed, 41 insertions(+), 10 deletions(-) diff --git a/api/cashier/index.js b/api/cashier/index.js index 0710a62..13904eb 100644 --- a/api/cashier/index.js +++ b/api/cashier/index.js @@ -5,6 +5,7 @@ const api = { orderInfo: 'cashier/orderInfo', orderPay: 'cashier/orderPay', tradeQuery: 'cashier/tradeQuery', + unify: 'goods/unify', } /** @@ -33,3 +34,11 @@ export function orderPay(orderId, data) { export function tradeQuery(param) { return request.get(api.tradeQuery, param) } + +/** + * 查询第三方支付信息 + * @param {Object} param + */ +export function unify(param) { + return request.get(api.unify, param) +} diff --git a/pages/checkout/cashier/index.vue b/pages/checkout/cashier/index.vue index b536735..37e8ba5 100644 --- a/pages/checkout/cashier/index.vue +++ b/pages/checkout/cashier/index.vue @@ -182,10 +182,10 @@ // 选择支付方式 handleSelectPayType(index) { - if (this.methods[index].method == 'huifu') { - this.$toast('抱歉,此支付方式暂未完善') - return - } + // if (this.methods[index].method == 'huifu') { + // this.$toast('抱歉,此支付方式暂未完善') + // return + // } this.curPaymentItem = this.methods[index] }, @@ -230,14 +230,36 @@ // 按钮禁用 if (app.disabled) return app.disabled = true - // 提交到后端API - CashierApi.orderPay(app.orderId, { - method: app.curPaymentItem.method, - client: app.platform, - extra: app.getExtraAsUnify(app.curPaymentItem.method) + if (app.curPaymentItem.method !== 'huifu') { + // 提交到后端API + CashierApi.orderPay(app.orderId, { + method: app.curPaymentItem.method, + client: app.platform, + extra: app.getExtraAsUnify(app.curPaymentItem.method) + }) + .then(result => app.onSubmitCallback(result)) + .finally(err => setTimeout(() => app.disabled = false, 10)) + } else { + console.log(app.curPaymentItem.method); + CashierApi.unify({ + outTradeNo: new Date().getTime(), + totalFee: 1, + }) + .then(result => { + const { miniPayRequest } = result.data.data; + let appPayRequest = ''; + appPayRequest = encodeURIComponent(JSON.stringify({ + sign: miniPayRequest.sign, + prepayid: miniPayRequest.prepayid, + })); + console.log(appPayRequest); + uni.navigateToMiniProgram({ + appId: miniPayRequest.miniuser, + path: `${miniPayRequest.minipath}?appPayRequest=${appPayRequest}`, + }); }) - .then(result => app.onSubmitCallback(result)) .finally(err => setTimeout(() => app.disabled = false, 10)) + } }, // 获取第三方支付的扩展参数 From cc67bbd14fe1358a3984268cc0ac6f1dc96f029f Mon Sep 17 00:00:00 2001 From: wangdong <1551135706@qq.com> Date: Wed, 31 Jul 2024 19:56:05 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E8=B7=B3=E8=BD=AC=E7=AC=AC=E4=B8=89?= =?UTF-8?q?=E6=96=B9=E6=94=AF=E4=BB=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- App.vue | 11 +++++++ pages/checkout/cashier/index.vue | 56 +++++++++++++++++--------------- 2 files changed, 40 insertions(+), 27 deletions(-) diff --git a/App.vue b/App.vue index 94e18c9..f1bb974 100644 --- a/App.vue +++ b/App.vue @@ -24,6 +24,17 @@ // 获取商城基础信息 this.getStoreInfo() }, + onShow(options) { + console.log('app onShow', options); + let extraData = options.referrerInfo.extraData; + if (extraData) { + // wx.showToast({ + // title: params.errStr, + // icon: 'none', + // }); + uni.$emit('appShow', extraData); + } + }, methods: { diff --git a/pages/checkout/cashier/index.vue b/pages/checkout/cashier/index.vue index 37e8ba5..5e987d5 100644 --- a/pages/checkout/cashier/index.vue +++ b/pages/checkout/cashier/index.vue @@ -135,11 +135,19 @@ // 记录订单ID this.orderId = Number(orderId) // 获取收银台信息 - this.getCashierInfo() + this.getCashierInfo(); + uni.$on('appShow', this.solveShowMsg); }, methods: { - + solveShowMsg(msgData) { + console.log(msgData); + if (msgData.errCode === '0000') { + this.onShowSuccess({ message: msgData.errStr }); + } else { + this.onPayFail({ message: msgData.errStr }); + } + }, // 获取收银台信息 getCashierInfo() { const app = this @@ -230,36 +238,30 @@ // 按钮禁用 if (app.disabled) return app.disabled = true - if (app.curPaymentItem.method !== 'huifu') { // 提交到后端API - CashierApi.orderPay(app.orderId, { - method: app.curPaymentItem.method, - client: app.platform, - extra: app.getExtraAsUnify(app.curPaymentItem.method) - }) - .then(result => app.onSubmitCallback(result)) - .finally(err => setTimeout(() => app.disabled = false, 10)) - } else { - console.log(app.curPaymentItem.method); - CashierApi.unify({ - outTradeNo: new Date().getTime(), - totalFee: 1, + CashierApi.orderPay(app.orderId, { + method: app.curPaymentItem.method, + client: app.platform, + extra: app.getExtraAsUnify(app.curPaymentItem.method) }) .then(result => { - const { miniPayRequest } = result.data.data; - let appPayRequest = ''; - appPayRequest = encodeURIComponent(JSON.stringify({ - sign: miniPayRequest.sign, - prepayid: miniPayRequest.prepayid, - })); - console.log(appPayRequest); - uni.navigateToMiniProgram({ - appId: miniPayRequest.miniuser, - path: `${miniPayRequest.minipath}?appPayRequest=${appPayRequest}`, - }); + console.log(result); + if (app.curPaymentItem.method === 'huifu') { + const { miniPayRequest } = result.data.payment; + let appPayRequest = ''; + appPayRequest = encodeURIComponent(JSON.stringify({ + sign: miniPayRequest.sign, + prepayid: miniPayRequest.prepayid, + })); + uni.navigateToMiniProgram({ + appId: miniPayRequest.miniuser, + path: `${miniPayRequest.minipath}?appPayRequest=${appPayRequest}`, + }); + } else { + app.onSubmitCallback(result) + } }) .finally(err => setTimeout(() => app.disabled = false, 10)) - } }, // 获取第三方支付的扩展参数