From b48efe44b7e5597b65a175afd2c3738312a7723e Mon Sep 17 00:00:00 2001 From: "Stormeye.Wu" Date: Thu, 16 Aug 2018 21:22:37 +0800 Subject: [PATCH] =?UTF-8?q?[=E6=94=AF=E4=BB=98][=E4=BF=AE=E5=A4=8D]:api?= =?UTF-8?q?=E6=8F=8F=E8=BF=B0=E6=9B=B4=E6=96=B0=EF=BC=8C=E5=8F=8A=E4=BE=8B?= =?UTF-8?q?=E5=AD=90=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common/common.js | 38 ++++++++++++++++++++++++++++++--- pages/coupons/details/index.js | 39 +++++++++++++++++++++++----------- 2 files changed, 62 insertions(+), 15 deletions(-) diff --git a/common/common.js b/common/common.js index bbf2914..ab14adc 100755 --- a/common/common.js +++ b/common/common.js @@ -137,13 +137,13 @@ const func = { wx.request({ url: config.api.orderSave, header: { - "token": app.globalData.token + 'token': app.globalData.token }, - method: "Post", data: { couponId: couponId, token: app.globalData.token }, + method: "POST", success: function (res) { resolve(res) }, @@ -156,6 +156,9 @@ const func = { }) }) }, + /** + * 支付订单 + */ payOrderCreate: function (orderId) { return new Promise((resolve, reject) => { wx.request({ @@ -163,11 +166,40 @@ const func = { header: { "token": app.globalData.token }, - method: "Post", data: { orderId: orderId, token: app.globalData.token }, + method: "POST", + success: function (res) { + resolve(res) + }, + fail: function (err) { + reject(err) + }, + complete: function (res) { + console.log(res) + } + }) + }) + }, + /** + * 支付订单更新 + */ + payOrderUpdate: function (orderId, payOrderId, status, reason) { + return new Promise((resolve, reject) => { + wx.request({ + url: config.api.payOrderUpdate, + header: { + "token": app.globalData.token + }, + data: { + payOrderId: payOrderId, + orderId: orderId, + status: status, + reason: reason + }, + method: "POST", success: function (res) { resolve(res) }, diff --git a/pages/coupons/details/index.js b/pages/coupons/details/index.js index 31e3222..a11604a 100644 --- a/pages/coupons/details/index.js +++ b/pages/coupons/details/index.js @@ -26,8 +26,22 @@ Page({ wx.hideLoading(); console.log(res) if (res.data.code == 200) { - Common.payOrderCreate(res.data.data.id) + return res; + } else { + wx.showToast({ + title: res.data.message, + duration: 3000 + }) + } + }) + .then(res => { + orderId = '' + res.data.data.id; + return Common.payOrderCreate(orderId) + }) .then(res =>{ + console.log(res) + payOrderId = res.data.data.payOrderId; + if (res.data.code == 200) { wx.requestPayment({ timeStamp: res.data.data.timeStamp, nonceStr: res.data.data.nonceStr, @@ -35,6 +49,8 @@ Page({ signType: 'MD5', paySign: res.data.data.paySign, 'success': function (res) { + Common.payOrderUpdate(orderId, payOrderId, 1); // 支付成功 + console.log(res); console.log('支付成功'); wx.showToast({ title: '购买成功', @@ -45,11 +61,13 @@ Page({ }) }, 'fail': function (res) { - console.log('支付失败'); + Common.payOrderUpdate(orderId, payOrderId, 2); // 支付失败 console.log(res) + console.log('支付失败'); return; }, 'complete': function (res) { + console.log(res); console.log('支付完成'); var url = that.data.url; console.log('get url', url) @@ -69,19 +87,16 @@ Page({ wx.navigateBack() }, 2000) } + } else { + wx.showModal({ + title: '错误提示', + content: res.errMsg + }); } return; } }) - - }) - - } else { - wx.showToast({ - title: res.data.message, - duration: 3000 - }) - } - }) + } + }) } }) \ No newline at end of file