瀏覽代碼

[支付][新增]:支付后更新订单及couponOrder状态

tags/2.2.4
Stormeye.Wu 6 年之前
父節點
當前提交
94382c6128
共有 3 個文件被更改,包括 59 次插入14 次删除
  1. +25
    -0
      common/common.js
  2. +4
    -0
      config/config.js
  3. +30
    -14
      pages/coupons/details/index.js

+ 25
- 0
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;

+ 4
- 0
config/config.js 查看文件

@@ -32,6 +32,10 @@ var config = {
* 支付订单
*/
payOrderCreate: '/api/pay/create',
/**
* 订单状态更新
*/
payOrderUpdate: '/api/pay/updatePayOrder',
/**
* 订单列表
*/


+ 30
- 14
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
})
}
})
}
})
}
})

Loading…
取消
儲存