diff --git a/common/common.js b/common/common.js index 77acd42..eff6fc8 100755 --- a/common/common.js +++ b/common/common.js @@ -180,5 +180,30 @@ const func = { }) }) }, + payOrderUpdate: function (orderId, payOrderId, status) { + return new Promise((resolve, reject) => { + wx.request({ + url: config.api.payOrderCreate, + header: { + "token": app.globalData.token + }, + data: { + id: payOrderId, + orderId: orderId, + status: status + }, + method: "POST", + success: function (res) { + resolve(res) + }, + fail: function (err) { + reject(err) + }, + complete: function (res) { + console.log(res) + } + }) + }) + }, } module.exports = func; \ No newline at end of file diff --git a/config/config.js b/config/config.js index 34c0ef8..5d4d82c 100755 --- a/config/config.js +++ b/config/config.js @@ -32,6 +32,10 @@ var config = { * 支付订单 */ payOrderCreate: '/api/pay/create', + /** + * 订单状态更新 + */ + payOrderUpdate: '/api/pay/updatePayOrder', /** * 订单列表 */ diff --git a/pages/coupons/details/index.js b/pages/coupons/details/index.js index df48aed..5869ecc 100644 --- a/pages/coupons/details/index.js +++ b/pages/coupons/details/index.js @@ -17,6 +17,8 @@ Page({ }) }, orderfunc(){ + var orderId = ''; + var payOrderId = ''; wx.showLoading({ title: '加载中...', }) @@ -26,9 +28,22 @@ Page({ wx.hideLoading(); console.log(res) if (res.data.code == 200) { - - Common.payOrderCreate('' + res.data.data.id) - .then(res =>{ + 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, @@ -36,6 +51,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: '购买成功', @@ -46,11 +63,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) @@ -70,19 +89,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