add pay fail manage

This commit is contained in:
RainSun 2019-11-26 23:53:42 +08:00
parent 7cbf57e146
commit 337737f493
3 changed files with 199 additions and 149 deletions

4
app.js
View File

@ -4,6 +4,7 @@ App({
//设置高度
wx.getSystemInfo({
success: e => {
this.globalData.is_apple = e.system.search('iOS') == -1 ? false : true
this.globalData.rpx = e.windowWidth/750;
this.globalData.StatusBar = e.statusBarHeight;
let custom = wx.getMenuButtonBoundingClientRect();
@ -25,6 +26,7 @@ App({
'https://qrcode-1256486458.cos.ap-chengdu.myqcloud.com/bg/bg3.jpg',
'https://qrcode-1256486458.cos.ap-chengdu.myqcloud.com/bg/bg4.jpg',
'https://qrcode-1256486458.cos.ap-chengdu.myqcloud.com/bg/bg5.jpg',
'https://qrcode-1256486458.cos.ap-chengdu.myqcloud.com/bg/bg6.jpg',]
'https://qrcode-1256486458.cos.ap-chengdu.myqcloud.com/bg/bg6.jpg',],
is_apple:false,
}
})

View File

@ -150,7 +150,7 @@ const reflash = (openId, callBack) => {
})
}
const checkOrder = (out_trade_no, callBack) => {
const checkOrder = (out_trade_no, callBack, cancelCallBack) => {
wx.request({
url: 'https://qr.powerrain.cn/checkOrder',
method: 'POST',
@ -162,11 +162,22 @@ const checkOrder = (out_trade_no, callBack) => {
},
success: function (res) {
if(res.data.errcode !== 200) {
// 后端还没收到payjs的回调
wx.hideLoading();
wx.showToast({
title: "订单状态获取失败",
icon: "none"
})
wx.showModal({
title: '警告',
content: '未查询到订单信息,您付款成功了吗?',
confirmText:'付完了',
cancelText:'还没有',
success (res) {
if (res.confirm) {
checkOrder(out_trade_no, callBack, cancelCallBack)
} else if (res.cancel) {
console.log('用户点击取消')
cancelCallBack && cancelCallBack()
}
}
})
} else {
wx.hideLoading();
callBack && callBack(res.data.order_id)

View File

@ -2,7 +2,7 @@
const api = require('../../lib/api')
const util = require('../../lib/util')
const app = getApp()
const g = app.globalData
const g = app.globalData
Page({
/**
@ -12,19 +12,19 @@ Page({
CustomBar: g.CustomBar, //顶部到胶囊底部的高度
StatusBar: g.StatusBar, //安卓bar高度
src: g.bgs[g.bgIndex], //背景图片地址
yiyan:null, //一言
yiyan: null, //一言
show: false, //控制utils页面的显示动画
display:{ //显示页面状态控制
'createBox':true,
'store':false,
'safe':false,
'start':false,
'example':false,
'maked':false
display: { //显示页面状态控制
'createBox': true,
'store': false,
'safe': false,
'start': false,
'example': false,
'maked': false
},
animating: false, //动画进行时ture->禁止触发下个动画
codes: [], //已完成的用户二维码
codeSrc:null, //预览用图片地址
codeSrc: null, //预览用图片地址
createCode: { //创建二维码所用数据
wxcode: '',
qqcode: '',
@ -46,9 +46,9 @@ Page({
onLoad: function (options) {
wx.hideShareMenu()
this.setData({
yiyan : wx.getStorageSync('yiyan'),
yiyan: wx.getStorageSync('yiyan'),
})
if(this.data.yiyan.hitokoto.length > 15) {
if (this.data.yiyan.hitokoto.length > 15) {
this.setData({
hitokotoStyle: "text-indent:2em;"
})
@ -106,10 +106,11 @@ Page({
},
// 各种界面展示的动画处理
showUtils: function(e) {
var type = e.currentTarget.dataset.type
if(this.data.animating) return
if(type == 'maked' && this.data.codes.length == 0) {
showUtils: function (e) {
if (e) var type = e.currentTarget.dataset.type
else var is_pay_back = true
if (this.data.animating) return
if (type == 'maked' && this.data.codes.length == 0) {
wx.showToast({
title: '空空如也呢',
icon: 'none'
@ -118,67 +119,107 @@ Page({
}
var that = this
this.data.animating = true
if(this.data.show) {
if (this.data.show) {
//拉起主页
// 如果是start页先弹窗问是否返回 是就清除数据
if(this.data.display['start']) {
wx.showModal({
title: '警告',
content: '此时返回将清除已录入的数据',
success (res) {
if (res.confirm) {
that.data.createCode = {
wxcode: '',
qqcode: '',
alcode: '',
username: '',
openId: wx.getStorageSync('openid'),
node: '',
timeout: '',
month: 0
}
that.setData({
createCode: that.data.createCode,
orderParams:{}
})
that.data.codeSrc = null
let display = that.data.display
for(var i in display) {
if(i != 'createBox') display[i] = false
}
display['createBox'] = true
that.setData({
display: display,
show:false
})
setTimeout(function(){
that.data.animating = false
},500)
} else if (res.cancel) {
console.log('用户点击取消')
that.data.animating = false
}
if (this.data.display['start']) {
if (is_pay_back) {
that.data.createCode = {
wxcode: '',
qqcode: '',
alcode: '',
username: '',
openId: wx.getStorageSync('openid'),
node: '',
timeout: '',
month: 0
}
})
that.setData({
createCode: that.data.createCode,
orderParams: {}
})
that.data.codeSrc = null
let display = that.data.display
for (var i in display) {
if (i != 'createBox') display[i] = false
}
display['createBox'] = true
that.setData({
display: display,
show: false
})
setTimeout(function () {
that.data.animating = false
}, 500)
} else {
wx.showModal({
title: '警告',
content: '此时返回将清除已录入的数据',
success(res) {
if (res.confirm) {
that.data.createCode = {
wxcode: '',
qqcode: '',
alcode: '',
username: '',
openId: wx.getStorageSync('openid'),
node: '',
timeout: '',
month: 0
}
that.setData({
createCode: that.data.createCode,
orderParams: {}
})
that.data.codeSrc = null
let display = that.data.display
for (var i in display) {
if (i != 'createBox') display[i] = false
}
display['createBox'] = true
that.setData({
display: display,
show: false
})
setTimeout(function () {
that.data.animating = false
}, 500)
} else if (res.cancel) {
console.log('用户点击取消')
that.data.animating = false
}
}
})
}
} else {
this.data.codeSrc = null
let display = this.data.display
for(var i in display) {
if(i != 'createBox') display[i] = false
for (var i in display) {
if (i != 'createBox') display[i] = false
}
display['createBox'] = true
this.setData({
display: display,
show:false
show: false
})
setTimeout(function(){
setTimeout(function () {
that.data.animating = false
},500)
}, 500)
}
} else {
//拉起utils页
//阻止点击返回键
if(!type) {
if (!type) {
this.data.animating = false
return
}
if (type == 'start' && g.is_apple) {
wx.showModal({
title: '警告',
content: '本应用不支持苹果手机',
showCancel: false
})
this.data.animating = false
return
}
@ -186,31 +227,24 @@ Page({
show: true,
})
let display = this.data.display
for(var i in display) {
if(i != type) display[i] = false
for (var i in display) {
if (i != type) display[i] = false
}
display[type] = true
setTimeout(function(){
setTimeout(function () {
that.setData({
display: display
})
that.data.animating = false
if(type == 'example') that.rouseQRcode(true,null)
if(type == 'start') {
wx.showModal({
title: '提示',
content: '由于技术原因,将于下个版本支持苹果手机',
showCancel: false
})
}
},500)
if (type == 'example') that.rouseQRcode(true, null)
}, 500)
}
},
//处理数据
manageCodes:function(callBack) {
manageCodes: function (callBack) {
let codes = wx.getStorageSync('codes')
for( let i in codes) {
for (let i in codes) {
let end = this.TimeDown(codes[i]['timeout'])
codes[i]['end'] = end;
}
@ -220,7 +254,7 @@ Page({
callBack && callBack()
},
//时间处理辅助轮
TimeDown: function(arg) {
TimeDown: function (arg) {
arg = parseInt(arg)
//结束时间
var endDate = new Date(arg);
@ -234,28 +268,28 @@ Page({
var modulo = totalSeconds % (60 * 60 * 24);
//小时数
var hours = Math.floor(modulo / (60 * 60));
return days + "天" + hours + "小时"
},
//删除二维码
delCode:function(e) {
delCode: function (e) {
var id = e.currentTarget.dataset.id
var that = this
wx.showModal({
title: '警告',
content: '此操作不可恢复,并且不会返还费用',
success (res) {
success(res) {
if (res.confirm) {
wx.showLoading({
title: '操作中',
mask:true
mask: true
})
api.delCode(id,function(){
api.delCode(id, function () {
//刷新并处理数据
api.reflash(wx.getStorageSync('openid'),function(info) {
api.reflash(wx.getStorageSync('openid'), function (info) {
wx.setStorageSync('codes', info);
that.manageCodes(function(){
that.manageCodes(function () {
wx.showToast({
title: "删除成功"
})
@ -266,25 +300,25 @@ Page({
console.log('用户点击取消')
}
}
})
})
},
//从已完成跳转二维码显示
bindToRouse:function(e) {
bindToRouse: function (e) {
var data = e.currentTarget.dataset.data
this.rouseQRcode(false,data)
this.rouseQRcode(false, data)
},
//唤起二维码(参数制作)
rouseQRcode:function(isExample,data) {
rouseQRcode: function (isExample, data) {
//isExample == true 是从示例进来的
//isExample == false 是从创建完或者已创建进来的
wx.showLoading({
title: '绘制中',
mask:true
mask: true
})
this.data.animating = true
if(isExample) {
if (isExample) {
var status = {
wx: true,
qq: true,
@ -297,27 +331,27 @@ Page({
// 在这里还要完成页面的切换操作
// 只改display
var display = this.data.display
for(var i in display) {
if(i != 'example') display[i] = false
for (var i in display) {
if (i != 'example') display[i] = false
}
display['example'] = true
this.setData({
display:display
display: display
})
// data 的内容是一条记录的row
var id = data._id['$oid']
var text = data.username
var status = {
wx: data.wxcode? true:false,
qq: data.qqcode? true:false,
al: data.alcode? true:false
wx: data.wxcode ? true : false,
qq: data.qqcode ? true : false,
al: data.alcode ? true : false
}
}
this.drawQRcode(status,text,id)
this.drawQRcode(status, text, id)
},
//绘制二维码
drawQRcode:function(status,text,id) {
drawQRcode: function (status, text, id) {
//传入的信息
// var status = {
// wx: true,
@ -329,46 +363,46 @@ Page({
//基本的信息
var canvasimgbg = null
var rpx = g.rpx
var fontSet1 = 'bold ' + parseInt(50*rpx) +'px sans-serif'
var fontSet2 = parseInt(35*rpx) + 'px sans-serif'
var fontSet1 = 'bold ' + parseInt(50 * rpx) + 'px sans-serif'
var fontSet2 = parseInt(35 * rpx) + 'px sans-serif'
var that = this
var app = []
if(status.wx) app.push(25)
if(status.qq) app.push(279)
if(status.al) app.push(153)
if (status.wx) app.push(25)
if (status.qq) app.push(279)
if (status.al) app.push(153)
wx.downloadFile({
url: that.data.src,
success: function (res) {
canvasimgbg = res.tempFilePath
var canvas = wx.createCanvasContext('qrcode');
canvas.drawImage(canvasimgbg, 0, 0, 632*rpx, 1054*rpx);
canvas.drawImage(canvasimgbg, 0, 0, 632 * rpx, 1054 * rpx);
wx.downloadFile({
url: 'https://api.ooopn.com/qr/api.php?text=https%3A%2F%2Fqr.powerrain.cn%2Fqr%3Fid%3D'+id,
success:function(res) {
url: 'https://api.ooopn.com/qr/api.php?text=https%3A%2F%2Fqr.powerrain.cn%2Fqr%3Fid%3D' + id,
success: function (res) {
canvasimgbg = res.tempFilePath
canvas.drawImage(canvasimgbg, 66*rpx, 66*rpx, 500*rpx, 500*rpx);
canvas.drawImage(canvasimgbg, 66 * rpx, 66 * rpx, 500 * rpx, 500 * rpx);
canvas.font = fontSet1;
canvas.textAlign = 'center';
canvas.setFillStyle('white')
canvas.fillText(text, 316*rpx, 660*rpx)
canvas.fillText(text, 316 * rpx, 660 * rpx)
canvas.font = fontSet2;
canvas.fillText('本二维码支持以下APP向我付款', 316*rpx, 760*rpx)
canvas.fillText('本二维码支持以下APP向我付款', 316 * rpx, 760 * rpx)
wx.downloadFile({
url: 'https://qrcode-1256486458.cos.ap-chengdu.myqcloud.com/sprite/sprite1.png',
success:function(res) {
success: function (res) {
canvasimgbg = res.tempFilePath
//先画左右,再画中间
canvas.drawImage(canvasimgbg, app[0], 0, 103, 100, 66*rpx, 830*rpx, 100*rpx, 100*rpx);
canvas.drawImage(canvasimgbg, app[1], 0, 103, 100, 463*rpx, 830*rpx, 100*rpx, 100*rpx);
if(app[2])
canvas.drawImage(canvasimgbg, app[2], 0, 103, 100, 264*rpx, 830*rpx, 100*rpx, 100*rpx);
canvas.draw(true,()=>{});
canvas.drawImage(canvasimgbg, app[0], 0, 103, 100, 66 * rpx, 830 * rpx, 100 * rpx, 100 * rpx);
canvas.drawImage(canvasimgbg, app[1], 0, 103, 100, 463 * rpx, 830 * rpx, 100 * rpx, 100 * rpx);
if (app[2])
canvas.drawImage(canvasimgbg, app[2], 0, 103, 100, 264 * rpx, 830 * rpx, 100 * rpx, 100 * rpx);
canvas.draw(true, () => { });
// 导出为临时图片
wx.canvasToTempFilePath({
x: 0,
y: 0,
width: 632*rpx,
height: 1054*rpx,
width: 632 * rpx,
height: 1054 * rpx,
destWidth: 1264,
destHeight: 2108,
canvasId: 'qrcode',
@ -391,22 +425,22 @@ Page({
})
},
preview: function() {
preview: function () {
wx.previewImage({
urls: [this.data.codeSrc],
})
},
//上传支付宝二维码
scanCode: function(e) {
scanCode: function (e) {
var type = e.currentTarget.dataset.type
var that = this
wx.scanCode({
success (res) {
success(res) {
//utils里边写个校验返回true false
//写入
var check = util.checkInput(type,res.result)
if(check) {
var check = util.checkInput(type, res.result)
if (check) {
that.data.createCode[type] = check
that.setData({
createCode: that.data.createCode
@ -415,11 +449,11 @@ Page({
title: '录入成功',
icon: 'success',
})
}else {
} else {
return
}
},
fail (err) {
fail(err) {
wx.showToast({
title: '扫码失败',
icon: 'none',
@ -429,11 +463,11 @@ Page({
},
//输入用户名,月份啥的
inputChange: function(e) {
inputChange: function (e) {
var type = e.currentTarget.dataset.type
var value = e.detail.value
var check = util.checkInput(type,value)
if(check) {
var check = util.checkInput(type, value)
if (check) {
this.data.createCode[type] = check
this.setData({
createCode: this.data.createCode
@ -443,7 +477,7 @@ Page({
},
//提交
submit: function() {
submit: function () {
if (Object.keys(this.data.orderParams).length != 0) {
this.setData({
preparePay: true
@ -456,17 +490,17 @@ Page({
console.log(res)
wx.showLoading({
title: '订单创建中',
mask:true
mask: true
})
api.createOder(res.totalFee,res.data,function(parms) {
that.setData({
api.createOder(res.totalFee, res.data, function (parms) {
that.setData({
preparePay: true,
orderParams: parms
})
wx.hideLoading()
})
},
/**
@ -477,22 +511,22 @@ Page({
* 可通过 res.detail.payjsOrderId 拿到 PAYJS 订单号
* 可通过 res.detail.responseData 拿到详细支付信息
*/
bindPaySuccess (res) {
bindPaySuccess(res) {
wx.showLoading({
title: '订单查询中',
mask:true
mask: true
});
var that = this
console.log('success', res)
console.log('[支付成功] PAYJS 订单号:', res.detail.payjsOrderId)
console.log('outTradeNo', res.detail.outTradeNo)
// 进行checkOrder
api.checkOrder(res.detail.outTradeNo,function(order_id) {
api.checkOrder(res.detail.outTradeNo, function (order_id) {
//重置createCode
var data = that.data.createCode
data._id = {}
data._id['$oid'] = order_id
that.data.createCode = {
that.data.createCode = {
wxcode: '',
qqcode: '',
alcode: '',
@ -504,15 +538,18 @@ Page({
}
that.setData({
createCode: that.data.createCode,
orderParams:{}
orderParams: {}
})
//调起绘制二维码的界面
wx.hideLoading()
that.rouseQRcode(false,data)
}, function () {
if (that.data.show)
that.showUtils()
})
//刷新并处理数据
api.reflash(wx.getStorageSync('openid'),function(info) {
api.reflash(wx.getStorageSync('openid'), function (info) {
wx.setStorageSync('codes', info);
that.manageCodes()
})
@ -526,17 +563,17 @@ Page({
*
* 如果下单成功但是用户取消支付则可在 res.detail.info.payjsOrderId 拿到 payjs 订单号
*/
bindPayFail (res) {
bindPayFail(res) {
console.log('fail', res)
if (res.detail.error) {
// 后端订单生成完成
// !!!!苹果手机会卡在这里!!!
console.error('发起支付失败', res.detail.info)
} else if (res.detail.navigateSuccess) {
// 跳转到了付款界面但是没付款
console.log('[取消支付] PAYJS 订单号:', res.detail.info.payjsOrderId)
} else {
// 用户放弃了付款,没跳转,再次跳转还可以进行支付
// 目测啥都不用干
@ -548,7 +585,7 @@ Page({
* 无论支付成功或失败均会执行
* 应当在此销毁 payjs 组件
*/
bindPayComplete () {
bindPayComplete() {
console.log('complete')
this.setData({
preparePay: false, // 销毁 payjs 组件
@ -560,7 +597,7 @@ Page({
* 当前仅用于监听 paying 数据
* 当用户跳转到 PAYJS 小程序并等待返回的过程中 paying 值为 true
*/
bindDataChange (res) {
bindDataChange(res) {
if (res.detail.paying) {
this.setData({
paying: res.detail.paying