diff --git a/App.vue b/App.vue index 3c17ec9..e90813a 100644 --- a/App.vue +++ b/App.vue @@ -15,15 +15,17 @@ snNo: '', // 设备sn号 platformType: '', //区分平台 //正式 - url: 'https://hsg.dctpay.com/user', - graurl: 'https://pay.dctpay.com/crest', - imgUrl: 'https://pay.dctpay.com/filesystem/', - imageWxImg: 'https://hsgcs.dctpay.com/filesystem/wxApplets/', + // url: 'https://hsg.dctpay.com/user', + // graurl: 'https://pay.dctpay.com/crest', + // imgUrl: 'https://pay.dctpay.com/filesystem/', + // imageWxImg: 'https://hsgcs.dctpay.com/filesystem/wxApplets/', + // redirectUrl:'https://pay.dctpay.com/scanPay', //测试 - // url: 'https://hsgcs.dctpay.com/user', - // graurl:'https://gratia-pay.dctpay.com/crest', - // imgUrl: 'https://hsgcs.dctpay.com/filesystem/', - // imageWxImg: 'https://hsgcs.dctpay.com/filesystem/wxApplets/', + url: 'https://hsgcs.dctpay.com/user', + graurl:'https://gratia-pay.dctpay.com/crest', + imgUrl: 'https://hsgcs.dctpay.com/filesystem/', + imageWxImg: 'https://hsgcs.dctpay.com/filesystem/wxApplets/', + redirectUrl:'https://gratia-pay.dctpay.com/scanPay', isClick: true, //防止重复点击 }, onLaunch: function() { @@ -42,7 +44,7 @@ that.globalData.platformType = 'UQRCODEPAY'; } - uni.getStorage({ + /* uni.getStorage({ key: 'openId', success(e) { if (e.data) { @@ -66,7 +68,13 @@ that.globalData.token = e.data; } } - }) + }) */ + + that.globalData.openId = uni.getStorageSync("openId"); + that.globalData.userInfo = uni.getStorageSync("user"); + that.globalData.token = uni.getStorageSync("token"); + + }, onHide: function() { console.log('App Hide') diff --git a/Utils/Api.js b/Utils/Api.js index 00d4372..88f5085 100644 --- a/Utils/Api.js +++ b/Utils/Api.js @@ -68,3 +68,8 @@ export const queryUserDiscountList = params => { export const getUnionUserId = params => { return POST('POST', `${grabase}/tradeOrder/getUnionUserId`, params).then(res => res.data); } + +//取消订单 +export const cancelOrder = params => { + return POST('POST', `${grabase}/tradeOrder/cancelOrder`, params).then(res => res.data); +} \ No newline at end of file diff --git a/pages/index/index.vue b/pages/index/index.vue index e486f33..d700148 100644 --- a/pages/index/index.vue +++ b/pages/index/index.vue @@ -200,20 +200,22 @@ - - - + + + 恭喜!获得了到店优惠 - {{tradeDetail.rebateActivityActualPrice}} + {{tradeDetail.rebateActivityActualPrice}} 到店付款可当现金用 - - 去支付 + + 去支付 @@ -234,7 +236,8 @@ phone, getUserAccount, queryUserDiscountList, - calculation + calculation, + cancelOrder } from '../../Utils/Api.js'; // #ifdef H5 var jweixin = require('jweixin-module'); @@ -287,13 +290,13 @@ storediscountType: '', //门店优惠类型 storediscountCondition: '', //门店优惠条件 storediscountPrice: '', //门店优惠价格 - storeDiscountId: '' ,//门店活动id - - tradeDetail:null,//订单详情 + storeDiscountId: '', //门店活动id + + tradeDetail: null, //订单详情 /* 弹窗 */ - popupHeight:485, - popupWidth:330, - outTradeNo:'',//订单编号 + popupHeight: 485, + popupWidth: 330, + outTradeNo: '', //订单编号 } }, mounted() {}, @@ -306,7 +309,7 @@ this.getUserAccount(); this.queryUserDiscountList(); } - + this.popupHeight = this.rpxTopx(this.popupHeight); this.popupWidth = this.rpxTopx(this.popupWidth); }, @@ -337,11 +340,11 @@ }, methods: { rpxTopx(temp) { - let deviceWidth = uni.getSystemInfoSync().windowWidth; //获取设备屏幕宽度 - - let rpx = (750 / deviceWidth) * Number(temp) + let deviceWidth = uni.getSystemInfoSync().windowWidth; //获取设备屏幕宽度 + + let rpx = (750 / deviceWidth) * Number(temp) return Math.floor(rpx); - + }, Timer() {}, //发送验证码 @@ -705,9 +708,9 @@ // if (userAgent.match(/Alipay/i) == "alipay") { // this.createJSAPIOrder('ALIPAY'); // } else if (userAgent.match(/MicroMessenger/i) == "micromessenger") { - + if (app.globalData.isClick) { - this.createJSAPIOrder(); + this.createJSAPIOrder(); app.globalData.isClick = false; } // } @@ -734,19 +737,17 @@ this.tradeDetail = null; this.outTradeNo = ""; createJSAPIOrder(datas).then(res => { - uni.hideLoading(); + uni.hideLoading(); if (res.return_code == '000000') { - - if(res.return_data.tradeDetail&&res.return_data.tradeDetail.rebateActivityPart){ + this.outTradeNo = res.return_data.outTradeNo; + if (res.return_data.tradeDetail && res.return_data.tradeDetail.rebateActivityPart) { this.tradeDetail = res.return_data.tradeDetail; - this.outTradeNo = res.return_data.outTradeNo; this.$refs.popupTip.show(); return } - this.jsapiPay(res.return_data.outTradeNo); - - } else { + + } else { app.globalData.isClick = true; uni.showToast({ title: res.return_msg, @@ -756,27 +757,25 @@ } }) }, - tapToPay(){ + tapToPay() { this.$refs.popupTip.hide(); - this.$nextTick(()=>{ - if(this.outTradeNo){ + this.$nextTick(() => { + if (this.outTradeNo) { this.jsapiPay(this.outTradeNo); } }) - - }, //唤起支付参数 - jsapiPay(item) { - uni.showLoading({ + jsapiPay(item) { + uni.showLoading({ title: '请求中', - mask:true, + mask: true, }) let datas = { outTradeNo: item } - this.outTradeNo = ""; - jsapiPay(datas).then(res => { + + jsapiPay(datas).then(res => { uni.hideLoading(); if (res.return_code == '000000') { if (res.return_data.payParam && app.globalData.platformType == 'WECHAT') { @@ -797,7 +796,7 @@ icon: 'none', duration: 2000 }) - } else { + } else { app.globalData.isClick = true; uni.showToast({ title: res.return_msg, @@ -807,6 +806,29 @@ } }) }, + //取消支付 + cancelOrder(outTradeNo) { + let params = { + "outTradeNo": outTradeNo + } + cancelOrder(params).then(res => { + app.globalData.isClick = true; + this.outTradeNo = ""; + if (res.return_code == '000000') { + // uni.showToast({ + // title: "已取消订单", + // icon: 'none', + // duration: 2000 + // }) + } else { + uni.showToast({ + title: res.return_msg, + icon: 'none', + duration: 2000 + }) + } + }) + }, //删除金额 deleteVal() { // this.plateNumberList.pop(); @@ -913,7 +935,7 @@ }, //微信支付 - wechatpayRequest: function(self) { + wechatpayRequest: function(self) { let that = this; uni.showLoading({ title: '支付中...' @@ -931,11 +953,11 @@ jweixin.ready(function() { jweixin.checkJsApi({ jsApiList: ['chooseWXPay'], // 需要检测的JS接口列表,所有JS接口列表见附录2, - success: function(res) { - app.globalData.isClick = true; + success: function(res) { + // app.globalData.isClick = true; }, - fail: function(res) { - app.globalData.isClick = true; + fail: function(res) { + // app.globalData.isClick = true; } }); jweixin.chooseWXPay({ @@ -954,16 +976,20 @@ title: '支付成功' }) }, - cancel: function(r) { - app.globalData.isClick = true; + cancel: function(r) { + that.cancelOrder(that.outTradeNo); //取消订单 + // app.globalData.isClick = true; }, - fail: function(res) { - app.globalData.isClick = true; + fail: function(res) { + that.cancelOrder(that.outTradeNo); //取消订单 + // app.globalData.isClick = true; } }); }); - jweixin.error(function(res) { - app.globalData.isClick = true; + // config信息验证失败会执行error函数,如签名过期导致验证失败,具体错误信息可以打开config的debug模式查看,也可以在返回的res参数中查看,对于SPA可以在这里更新签名 + jweixin.error(function(res) { + that.cancelOrder(that.outTradeNo); //取消订单 + // app.globalData.isClick = true; uni.showToast({ icon: 'none', title: '支付失败了', @@ -999,17 +1025,21 @@ uni.showToast({ title: '支付成功' }) + }, - cancel: function(r) { - app.globalData.isClick = true; + cancel: function(r) { + // app.globalData.isClick = true; + that.cancelOrder(that.outTradeNo); //取消订单 }, - fail: function(res) { - app.globalData.isClick = true; + fail: function(res) { + // app.globalData.isClick = true; + that.cancelOrder(that.outTradeNo); //取消订单 } }); }); - jweixin.error(function(res) { - app.globalData.isClick = true; + jweixin.error(function(res) { + // app.globalData.isClick = true; + that.cancelOrder(that.outTradeNo); //取消订单 uni.showToast({ icon: 'none', title: '支付失败了', @@ -1020,13 +1050,40 @@ }, //支付宝支付 alipayRequest(item) { + let that = this; alipayApi.tradePay({ - tradeNO: item - }, function(res) { - app.globalData.isClick = true; - // alert(JSON.stringify(res)); - //支付完成的逻辑 - }); + tradeNO: item, + success: function(res) { + if(res.resultCode==9000){ + app.globalData.isClick = true; + // uni.showToast({ + // title:"支付成功!", + // icon:'none' + // }) + }else{ + // uni.showToast({ + // title:"支付失败!", + // icon:'none' + // }) + that.cancelOrder(that.outTradeNo); //取消订单 + } + }, + fail: function(res) { + uni.showToast({ + title:res, + icon:'none' + }) + that.cancelOrder(that.outTradeNo); //取消订单 + + }, + }, + + /* function(res) { + app.globalData.isClick = true; + // alert(JSON.stringify(res)); + //支付完成的逻辑 + } */ + ); }, @@ -1085,9 +1142,9 @@ border-radius: 45rpx; font-size: 28rpx; } - - - + + + } .re { @@ -1244,53 +1301,61 @@ } } - + /* 活动金弹窗 */ - .pr{ + .pr { position: relative; } + .popImg { width: 100%; height: 100%; min-height: 430px; } - .popContain{ + + .popContain { position: absolute; top: 0; // padding: 20px; box-sizing: border-box; text-align: center; - font-size:28rpx; - .tip-color{ - color:#BF0E0F; + font-size: 28rpx; + + .tip-color { + color: #BF0E0F; } - .tip-top{ + + .tip-top { color: white; letter-spacing: 2px; } - .tip-price{ - margin-top:143px; + + .tip-price { + margin-top: 143px; font-weight: bold; display: flex; align-items: baseline; justify-content: center; - .font45{ + + .font45 { font-size: 45px; font-style: oblique; margin-right: 5px; } } - .tip-desc{ + + .tip-desc { font-size: 18px; font-weight: bold; margin-top: 10px; } } - .btnPay{ + + .btnPay { color: #FFFFFF; background: linear-gradient(to right, #F46538, #E8411A); width: 60%; - margin:22px auto 16px; + margin: 22px auto 16px; height: 50px; display: flex; justify-content: center; diff --git a/pages/welcome/welcome.vue b/pages/welcome/welcome.vue index ba5feab..4afb22e 100644 --- a/pages/welcome/welcome.vue +++ b/pages/welcome/welcome.vue @@ -96,10 +96,11 @@ import { getH5AccessToken(params).then(res => { if (res.return_code == '000000' && res.return_data.openid) { app.globalData.openId = res.return_data.openid; - uni.setStorage({ + uni.setStorageSync("openId",res.return_data.openid) + /* uni.setStorage({ key: "openId", data: res.return_data.openid - }) + }) */ uni.reLaunch({ url: '../index/index' }) @@ -116,10 +117,11 @@ import { getAlipayUserId(params).then(res => { if (res.return_code == '000000' && res.return_data.userId) { app.globalData.openId = res.return_data.userId; - uni.setStorage({ + uni.setStorageSync("openId",res.return_data.userId) + /* uni.setStorage({ key: "openId", data: res.return_data.userId - }) + }) */ uni.reLaunch({ url: '../index/index' }) @@ -138,10 +140,11 @@ import { getUnionUserId(params).then(res => { if (res.return_code == '000000' && res.return_data.respData.userId) { app.globalData.openId = res.return_data.respData.userId; - uni.setStorage({ + uni.setStorageSync("openId",res.return_data.respData.userId); + /* uni.setStorage({ key: "openId", data: res.return_data.respData.userId - }) + }) */ uni.reLaunch({ url: '../index/index' }) @@ -152,17 +155,19 @@ import { }, //重定向方法 jumpWeb() { + let redirectUrl = app.globalData.redirectUrl; if (app.globalData.platformType == 'WECHAT') { location.href = - 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxa075e8509802f826&redirect_uri=https://hsg.dctpay.com/wechat_authorize/?redirect_uri=https://pay.dctpay.com/scanPay&response_type=code&scope=snsapi_base#wechat_redirect'; + 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxa075e8509802f826&redirect_uri=https://hsg.dctpay.com/wechat_authorize/?redirect_uri='+redirectUrl+'&response_type=code&scope=snsapi_base#wechat_redirect'; } if (app.globalData.platformType == 'ALIPAY') { + let str =encodeURIComponent(redirectUrl+"?sn=1000017476") location.href = - 'https://openauth.alipay.com/oauth2/publicAppAuthorize.htm?app_id=2021003176605875&scope=auth_base&redirect_uri=https://pay.dctpay.com/redirect?redirect_uri=https%3A%2F%2Fpay.dctpay.com%2FscanPay%3Fsn%3D1000017476'; + 'https://openauth.alipay.com/oauth2/publicAppAuthorize.htm?app_id=2021003176605875&scope=auth_base&redirect_uri=https://pay.dctpay.com/redirect?redirect_uri='+str; } if (app.globalData.platformType == 'UQRCODEPAY') { location.href = - 'https://qr.95516.com/qrcGtwWeb-web/api/userAuth?version=1.0.0&redirectUrl=https://pay.dctpay.com/scanPay'; + 'https://qr.95516.com/qrcGtwWeb-web/api/userAuth?version=1.0.0&redirectUrl='+redirectUrl; } }, }