| @@ -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) | |||
| }, | |||
| @@ -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 | |||
| }) | |||
| } | |||
| }) | |||
| } | |||
| }) | |||
| } | |||
| }) | |||