From ed592c44e218dc42767d961308370039bd34de98 Mon Sep 17 00:00:00 2001 From: "Stormeye.Wu" Date: Thu, 23 Aug 2018 12:52:00 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E4=BB=98=E9=A1=B5=E9=9D=A2=E6=9B=B4?= =?UTF-8?q?=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/config.js | 8 +- pages/coupons/details/index.js | 198 ++++++++++-------- pages/coupons/details/index.wxml | 2 +- .../phoneinput/phoneinput.js | 0 .../phoneinput/phoneinput.json | 0 .../phoneinput/phoneinput.wxml | 0 .../phoneinput/phoneinput.wxss | 0 7 files changed, 123 insertions(+), 85 deletions(-) rename pages/{getphoneInfo => }/phoneinput/phoneinput.js (100%) rename pages/{getphoneInfo => }/phoneinput/phoneinput.json (100%) rename pages/{getphoneInfo => }/phoneinput/phoneinput.wxml (100%) rename pages/{getphoneInfo => }/phoneinput/phoneinput.wxss (100%) diff --git a/config/config.js b/config/config.js index 093085f..1df5018 100755 --- a/config/config.js +++ b/config/config.js @@ -1,7 +1,7 @@ var config = { name: "富茂", - url: "https://ciformall.youlane.cn/C/api", - //url: "http://dac6735a.ngrok.io/C/api", + //url: "https://ciformall.youlane.cn/C/api", + url: "http://0da722ce.ngrok.io/C/api", api: { /** * 接口用途:login @@ -19,6 +19,10 @@ var config = { * 检查用户授权状态 */ checkUserStatus: '/user/checkUserStatus', + /** + * 检查用户手机授权状态 + */ + checkPhoneStatus: '/user/checkPhoneStatus', /** * 优惠券查询 */ diff --git a/pages/coupons/details/index.js b/pages/coupons/details/index.js index 6c1c83c..d5c1207 100644 --- a/pages/coupons/details/index.js +++ b/pages/coupons/details/index.js @@ -31,7 +31,8 @@ Page({ payOrderUpdate: (orderId, payOrderId, status, reason) => { // 支付成功 return Http.post({ - url: Http.config.api.payOrderUpdate, data: { + url: Http.config.api.payOrderUpdate, + data: { payOrderId: payOrderId, orderId: orderId, status: status, @@ -39,93 +40,126 @@ Page({ } }) }, - newOrderfunc() { + payment: (res) => { + var that = this; + var payOrderId = '' + res.payOrderId; + wx.requestPayment({ + timeStamp: res.timeStamp, + nonceStr: res.nonceStr, + package: res.package, + signType: 'MD5', + paySign: res.paySign, + 'success': (res) => { + that.payOrderUpdate(that.data.orderId, payOrderId, 1) // 支付成功 + console.log(res); + console.log('支付成功'); + wx.showToast({ + title: '购买成功', + duration: 2500 + }) + wx.navigateBack({ + delta: 2 + }) + }, + 'fail': (res) => { + that.payOrderUpdate(that.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; 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 + url: config.api.checkPhoneStatus, + data: {} }) - 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; + .then(res => { + return Http.post({ + url: Http.config.api.orderSave, + data: { + couponId: that.data.couponId } }) - } - - }) + }).catch(err => { + console.log(err) + if (err.code == 11005) { + // 用户手机未授权 + wx.redirectTo({ + url: '../../getphoneInfo/index', + }) + } + if (err.code == 11006) { + // 用户手机已加密 + wx.redirectTo({ + url: '../../phoneinput/phoneinput', + }) + } + }) + .then(res => { + const orderId = '' + res.data.id; + that.setData({ + orderId: orderId + }) + if (res.data.payment > 0) { + // real pay + return Http.post({ + url: Http.config.api.payOrderCreate, + data: { + orderId: orderId + } + }) + } else { + // 免费券 + that.payOrderUpdate(orderId, "0", 1) // 支付成功 + .then(res => { + wx.showToast({ + title: "支付成功", + duration: 3000 + }) + }) + } + }).then(res => { + console.log(res) + if (res) { + var payOrderId = '' + res.payOrderId; + wx.hideLoading(); + //payment(res); + that.payOrderUpdate(that.data.orderId, payOrderId, 1) // 支付成功 + } + }) }, }) \ No newline at end of file diff --git a/pages/coupons/details/index.wxml b/pages/coupons/details/index.wxml index 4235ba3..3971689 100644 --- a/pages/coupons/details/index.wxml +++ b/pages/coupons/details/index.wxml @@ -45,6 +45,6 @@ - + \ No newline at end of file diff --git a/pages/getphoneInfo/phoneinput/phoneinput.js b/pages/phoneinput/phoneinput.js similarity index 100% rename from pages/getphoneInfo/phoneinput/phoneinput.js rename to pages/phoneinput/phoneinput.js diff --git a/pages/getphoneInfo/phoneinput/phoneinput.json b/pages/phoneinput/phoneinput.json similarity index 100% rename from pages/getphoneInfo/phoneinput/phoneinput.json rename to pages/phoneinput/phoneinput.json diff --git a/pages/getphoneInfo/phoneinput/phoneinput.wxml b/pages/phoneinput/phoneinput.wxml similarity index 100% rename from pages/getphoneInfo/phoneinput/phoneinput.wxml rename to pages/phoneinput/phoneinput.wxml diff --git a/pages/getphoneInfo/phoneinput/phoneinput.wxss b/pages/phoneinput/phoneinput.wxss similarity index 100% rename from pages/getphoneInfo/phoneinput/phoneinput.wxss rename to pages/phoneinput/phoneinput.wxss