let Common = require('../../../common/common.js') var app = getApp() const Http = require("../../../utils/HttpBasics") Page({ data: { data: {}, couponId: null, orderId: '' }, onLoad(e) { console.log(e) wx.showLoading({ title: '加载中...', }) Http.get({ url: Http.config.api.couponDetail, data: { id: e.id } }).then(res => { wx.hideLoading(); this.setData({ data: res, couponId: e.id }) }) }, /** * 支付订单更新 */ payOrderUpdate: (orderId, payOrderId, status, reason) => { // 支付成功 return Http.post({ url: Http.config.api.payOrderUpdate, data: { payOrderId: payOrderId, orderId: orderId, status: status, reason: reason } }) }, newOrderfunc() { wx.showLoading({ title: '加载中...', }) Http.post({ url: Http.config.api.orderSave, data: { couponId: this.data.couponId } }).then(res => { const orderId = '' + res.id; this.setData({ orderId: orderId }) if (res.payment > 0) { return Http.post({ url: Http.config.api.payOrderCreate, data: { orderId: orderId } }) } else { // 免费卷 this.payOrderUpdate(orderId, "0", 1) // 支付成功 .then(res => { wx.showToast({ title: "支付成功", duration: 3000 }) }) } }).then(res => { console.log(res) if (res) { var payOrderId = '' + res.payOrderId; wx.hideLoading(); wx.requestPayment({ timeStamp: res.timeStamp, nonceStr: res.nonceStr, package: res.package, signType: 'MD5', paySign: res.paySign, 'success': (res) => { this.payOrderUpdate(this.data.orderId, payOrderId, 1)// 支付成功 console.log(res); console.log('支付成功'); wx.showToast({ title: '购买成功', duration: 2500 }) wx.navigateBack({ delta: 2 }) }, 'fail': (res) => { this.payOrderUpdate(this.data.orderId, payOrderId, 2)// 支付失败 console.log(res) console.log('支付失败'); return; }, 'complete': (res) => { console.log(res); console.log('支付完成'); var url = this.data.url; console.log('get url', url) if (res.errMsg == 'requestPayment:ok') { wx.showModal({ title: '提示', content: '支付成功' }); if (url) { setTimeout(function () { wx.redirectTo({ url: '/pages' + url }); }, 2000) } else { setTimeout(() => { wx.navigateBack() }, 2000) } } else { wx.showModal({ title: '错误提示', content: res.errMsg }); } return; } }) } }) }, orderfunc() { var that = this /* var couponOrderId = '189631451703017472'; var orderId = '189631451640102912'; var payOrderId = '189631462532710400'; var status = 1; var reason = ''; Common.refundCouponOrder(couponOrderId) .then(res => { console.log(res); if (res.data.code == 200) { Common.refundOrderCreate(orderId, payOrderId) .then(res => { console.log(res); }) } else { wx.showToast({ title: res.data.message, duration: 3000 }) } }) */ /* Common.payOrderUpdate(orderId, payOrderId, status, reason) .then(res =>{ console.log(res); }) */ wx.showLoading({ title: '加载中...', }) var couponId = '' + this.data.couponId; console.log("order coupon: " + couponId) Common.orderSave(couponId) .then(res => { console.log(res) if (res.data.code == 200) { var orderId = '' + res.data.data.id; this.setData({ orderId: '' + res.data.data.id }) if (res.data.data.payment > 0) { return Common.payOrderCreate(orderId) } else { Common.payOrderUpdate(orderId, "0", 1) // 支付成功 .then(res => { wx.showToast({ title: res.data.message, duration: 3000 }) }) } } else { wx.hideLoading(); wx.showToast({ title: res.data.message, duration: 3000 }) } }) .then(res => { console.log(res) var payOrderId = '' + res.data.data.payOrderId; if (res.data.code == 200) { wx.requestPayment({ timeStamp: res.data.data.timeStamp, nonceStr: res.data.data.nonceStr, package: res.data.data.package, signType: 'MD5', paySign: res.data.data.paySign, 'success': function (res) { Common.payOrderUpdate(that.data.orderId, payOrderId, 1); // 支付成功 console.log(res); console.log('支付成功'); wx.showToast({ title: '购买成功', duration: 2500 }) wx.navigateBack({ delta: 2 }) }, 'fail': function (res) { 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) if (res.errMsg == 'requestPayment:ok') { wx.showModal({ title: '提示', content: '支付成功' }); if (url) { setTimeout(function () { wx.redirectTo({ url: '/pages' + url }); }, 2000) } else { setTimeout(() => { wx.navigateBack() }, 2000) } } else { wx.showModal({ title: '错误提示', content: res.errMsg }); } return; } }) } else { wx.showModal({ title: '错误提示', content: res.data.message }); } }) wx.hideLoading(); } })