feat(orderDetail): 实现微信和支付宝扫码支付功能

- 新增微信和支付宝扫码支付的逻辑和接口调用
- 实现支付状态轮询机制,以获取实时支付结果
- 优化现金支付流程,统一支付成功后的处理逻辑
- 引入新的 API接口:getOrder 和 submitOrder
main
Tuzki 8 months ago
parent 21b1c45334
commit 1f378676f9
  1. 15
      api/seal/seal.js
  2. 317
      pages/orderDetail/orderDetail.vue

@ -46,6 +46,21 @@ export function paymentOrder(data) {
'data': data
})
}
// 获得支付订单状态
export function getOrder(id) {
return request({
url: '/pay/order/get?id=' + id,
method: 'get'
})
}
// 微信,支付宝扫码收款接口
export function submitOrder(data) {
return request({
url: '/pay/order/submit',
method: 'post',
data: data
})
}
//修改订单门票打印次数
export function printTicket(data) {
return request({

@ -43,13 +43,13 @@
</view>
<view class="m-botom">
<button class="m-btn m-btn-line" @click="cancelOrder">取消订单</button>
<button class="m-btn" @click="resvcePrice">确认收款</button>
<button class="m-btn" @click="resvcePrice(choose)">确认收款</button>
</view>
</view>
</template>
<script>
import { paymentOrder,printTicket,cancelOrder } from '@/api/seal/seal.js';
import { paymentOrder, printTicket, cancelOrder, submitOrder, getOrder } from '@/api/seal/seal.js';
export default {
data() {
return {
@ -57,17 +57,18 @@ export default {
orderPrice: 0.0,
cashValue: 0,
choose: 'cash',
interval: undefined,
way: [
// {
// id: 1,
// title: '',
// imgPath: '/static/images/index/icon_wechat.png'
// },
// {
// id: 2,
// title: '',
// imgPath: '/static/images/index/icon_alipay.png'
// },
{
id: 1,
title: '微信支付',
imgPath: '/static/images/index/icon_wechat.png'
},
{
id: 2,
title: '支付宝支付',
imgPath: '/static/images/index/icon_alipay.png'
},
// {
// id: 3,
// title: '',
@ -82,20 +83,22 @@ export default {
};
},
onLoad(params) {
uni.removeStorageSync('ALL_TICKET')
uni.removeStorageSync('EVENT')
uni.removeStorageSync('ALL_TICKET');
uni.removeStorageSync('EVENT');
if (params.order) {
uni.setStorageSync('payOrder', params.order);
this.orderDetail = null;
this.orderDetail = JSON.parse(params.order);
console.log('this.orderDetail', this.orderDetail);
this.orderPrice = this.orderDetail.orderInfo.settlementAmount;
}
},
onUnload() {
this.back()
this.back();
},
methods: {
cancelOrder(){
const that = this
cancelOrder() {
const that = this;
uni.showModal({
title: '提示',
content: '确定放弃支付吗',
@ -103,68 +106,246 @@ export default {
if (res.confirm) {
uni.showLoading({
title: '请稍后...'
})
cancelOrder(that.orderDetail.orderInfo.orderNumber).then(res=>{
uni.hideLoading();
uni.showToast({
icon:'none',
title:'已取消'
});
cancelOrder(that.orderDetail.orderInfo.orderNumber)
.then((res) => {
uni.hideLoading();
uni.showToast({
icon: 'none',
title: '已取消'
});
setTimeout(() => {
uni.reLaunch({
url: '/pages/index'
});
}, 2100);
})
setTimeout(()=>{
uni.reLaunch({
url:'/pages/index'
})
},2100)
}).catch(err=>{
uni.hideLoading();
console.log(err)
})
.catch((err) => {
uni.hideLoading();
console.log(err);
});
} else if (res.cancel) {
console.log('用户点击取消');
}
}
});
},
resvcePrice() {
const obj = {
orderNumber: this.orderDetail.orderInfo.orderNumber,
settlementAmount: Number(this.orderPrice),
payMethod: 'cash',
actualAmount: this.cashValue,
changeAmount: this.cashValue - Number(this.orderPrice)
};
paymentOrder(obj).then(res=>{
console.log(res)
const ob = {
orderNumber:this.orderDetail.orderInfo.orderNumber
}
printTicket(ob).then(ress=>{
const datas = JSON.stringify(this.orderDetail.orderInfo.ticketList)
// console.log(data)
uni.navigateTo({
url:'/pages/payResult/payResult?status=success&detail='+datas+'&tickets='+ress.data
createQueryInterval() {
let that = this
if (this.interval) {
return;
}
this.interval = setInterval(() => {
getOrder(that.orderDetail.orderInfo.belongingPayOrderId).then((response) => {
//
if (response.data.status === 10) {
that.clearQueryInterval();
uni.hideLoading();
uni.showToast({
icon: 'none',
title: '支付成功!',
duration: 1000
});
const ob = {
orderNumber: that.orderDetail.orderInfo.orderNumber
};
printTicket(ob)
.then((ress) => {
const datas = JSON.stringify(that.orderDetail.orderInfo.ticketList);
// console.log(data)
uni.navigateTo({
url: '/pages/payResult/payResult?status=success&detail=' + datas + '&tickets=' + ress.data
});
})
.catch((err) => {
console.log(err);
});
}
//
if (response.data.status === 20) {
that.clearQueryInterval();
uni.hideLoading();
uni.showToast({
icon: 'none',
title: '支付已关闭!',
duration: 1000
});
}
});
}, 1000 * 2);
},
/** 清空查询任务 */
clearQueryInterval() {
//
clearInterval(this.interval);
this.interval = undefined;
},
resvcePrice(val) {
let that = this
console.log(val);
if (val == 1) {
uni.hideLoading();
uni.scanCode({
scanType: ['barCode','qrCode'],
success: function (resposon) {
console.log('条码内容:' + resposon.result);
// console.log('this.orderDetail', this.orderDetail);
const obj = {
channelCode: 'wx_bar',
channelExtras: {
auth_code: resposon.result
},
id: that.orderDetail.orderInfo.belongingPayOrderId,
returnUrl: ''
};
debugger
submitOrder(obj).then((res) => {
console.log('支付结果',res)
const data = res.data;
if (data.status === 10) {
that.clearQueryInterval();
uni.showToast({
icon: 'none',
title: '支付成功!',
duration: 1000
});
const ob = {
orderNumber: that.orderDetail.orderInfo.orderNumber
};
printTicket(ob)
.then((ress) => {
const datas = JSON.stringify(that.orderDetail.orderInfo.ticketList);
// console.log(data)
uni.navigateTo({
url: '/pages/payResult/payResult?status=success&detail=' + datas + '&tickets=' + ress.data
});
})
.catch((err) => {
console.log(err);
});
return;
}
//
uni.showLoading({
title: '支付中...',
mask:true
});
this.createQueryInterval();
}).catch(err=>{
// uni.showLoading({
// title: '...'
// });
// this.createQueryInterval();
})
}
});
}
if (val == 2) {
//
uni.hideLoading();
uni.scanCode({
scanType: ['barCode','qrCode'],
success: function (resposon) {
console.log('条码内容:' + resposon.result);
// console.log('this.orderDetail', this.orderDetail);
const obj = {
channelCode: 'alipay_bar',
channelExtras: {
auth_code: resposon.result
},
id: that.orderDetail.orderInfo.belongingPayOrderId,
returnUrl: ''
};
debugger
submitOrder(obj).then((res) => {
console.log('支付结果',res)
const data = res.data;
if (data.status === 10) {
that.clearQueryInterval();
uni.showToast({
icon: 'none',
title: '支付成功!',
duration: 1000
});
const ob = {
orderNumber: that.orderDetail.orderInfo.orderNumber
};
printTicket(ob)
.then((ress) => {
const datas = JSON.stringify(that.orderDetail.orderInfo.ticketList);
// console.log(data)
uni.navigateTo({
url: '/pages/payResult/payResult?status=success&detail=' + datas + '&tickets=' + ress.data
});
})
.catch((err) => {
console.log(err);
});
return;
}
//
uni.showLoading({
title: '支付中...',
mask:true
});
this.createQueryInterval();
}).catch(err=>{
// uni.showLoading({
// title: '...'
// });
// this.createQueryInterval();
})
}
});
}
if (val == 'cash') {
const obj = {
orderNumber: this.orderDetail.orderInfo.orderNumber,
settlementAmount: Number(this.orderPrice),
payMethod: 'cash',
actualAmount: this.cashValue,
changeAmount: this.cashValue - Number(this.orderPrice)
};
paymentOrder(obj)
.then((res) => {
console.log(res);
const ob = {
orderNumber: this.orderDetail.orderInfo.orderNumber
};
printTicket(ob)
.then((ress) => {
const datas = JSON.stringify(this.orderDetail.orderInfo.ticketList);
// console.log(data)
uni.navigateTo({
url: '/pages/payResult/payResult?status=success&detail=' + datas + '&tickets=' + ress.data
});
})
.catch((err) => {
console.log(err);
});
})
}).catch(err=>{
console.log(err)
})
}).catch(err=>{
console.log(err)
// uni.navigateTo({
// url:'/pages/payResult/payResult?status=fail'
// })
})
.catch((err) => {
console.log(err);
// uni.navigateTo({
// url:'/pages/payResult/payResult?status=fail'
// })
});
}
},
back() {
let that = this
cancelOrder(that.orderDetail.orderInfo.orderNumber).then(res=>{
console.log(res)
}).catch(err=>{
console.log(err)
})
let that = this;
cancelOrder(that.orderDetail.orderInfo.orderNumber)
.then((res) => {
console.log(res);
})
.catch((err) => {
console.log(err);
});
uni.navigateBack({
delta:1,
})
delta: 1
});
}
}
};

Loading…
Cancel
Save