【收银台】

1. 完成微信小程序的支付
pull/1/MERGE
YunaiV 2023-07-08 12:43:29 +08:00
parent 2afae4f007
commit 644b458969
7 changed files with 54 additions and 31 deletions

View File

@ -59,7 +59,7 @@
"quickapp" : {}, "quickapp" : {},
/* */ /* */
"mp-weixin" : { "mp-weixin" : {
"appid" : "wx63c280fe3248a3e7", "appid" : "wx62056c0d5e8db250",
"setting" : { "setting" : {
"urlCheck" : true, "urlCheck" : true,
"minified" : true, "minified" : true,

View File

@ -11,7 +11,7 @@
:datatime="invalidTime / 1000" :is-col="true" :bgColor="bgColor" /> :datatime="invalidTime / 1000" :is-col="true" :bgColor="bgColor" />
</view> </view>
</view> </view>
<view class="payment"> <view class="payment" v-if="channelCode.length > 0">
<view class="title"> <view class="title">
支付方式 支付方式
</view> </view>
@ -98,8 +98,9 @@
this.orderId = options.order_id this.orderId = options.order_id
} }
if (options.returnUrl) { if (options.returnUrl) {
this.returnUrl = options.returnUrl this.returnUrl = decodeURIComponent(options.returnUrl)
} }
debugger
this.getCashierOrder() this.getCashierOrder()
}, },
methods: { methods: {
@ -157,7 +158,8 @@
displayMode: 'url', // TODO displayMode: 'url', // TODO
returnUrl: this.getPayReturnUrl(), returnUrl: this.getPayReturnUrl(),
channelExtras: { channelExtras: {
openid: "ockUAwIZ-0OeMZl9ogcZ4ILrGba0" // openid: "ockUAwIZ-0OeMZl9ogcZ4ILrGba0" // wx_pub openid
openid: "oLefc4g5GjKWHJjLjMSXB3wX0fD0" // wx_lite openid
} }
}).then(res => { }).then(res => {
this.handleSubmitOrderResult(res.data); this.handleSubmitOrderResult(res.data);
@ -379,50 +381,41 @@
}) })
}) })
}, },
/**
* 发起微信小程序支付
*/
handleSubmitOrderResultForWxLite(displayContent) { handleSubmitOrderResultForWxLite(displayContent) {
const payConfig = JSON.parse(displayContent); const payConfig = JSON.parse(displayContent);
const that = this;
console.log(payConfig, '=================')
console.log(payConfig.timeStamp, '=================')
uni.requestPayment({ uni.requestPayment({
timeStamp: payConfig.timeStamp, timeStamp: payConfig.timeStamp,
nonceStr: payConfig.nonceStr, nonceStr: payConfig.nonceStr,
package: payConfig.packageValue, package: payConfig.packageValue,
signType: payConfig.signType, signType: payConfig.signType,
paySign: payConfig.paySign, paySign: payConfig.paySign,
success: function(res) { success: res => {
uni.hideLoading(); uni.hideLoading();
return that.$util.Tips({ debugger
return this.$util.Tips({
title: '支付成功', title: '支付成功',
icon: 'success' icon: 'success'
}, { }, () => {
tab: 5, this.goReturnUrl('success');
url: goPages
}); });
}, },
fail: function(e) { fail: e => {
uni.hideLoading(); uni.hideLoading();
return that.$util.Tips({ //
title: '取消支付'
}, {
tab: 5,
url: goPages + '&status=2'
});
},
complete: function(e) {
uni.hideLoading();
//
if (e.errMsg === 'requestPayment:cancel' if (e.errMsg === 'requestPayment:cancel'
|| e.errMsg === 'requestPayment:fail cancel') { || e.errMsg === 'requestPayment:fail cancel') {
return that.$util.Tips({ return this.$util.Tips({
title: '取消支付' title: '取消支付'
}); });
} }
return that.$util.Tips({ return this.$util.Tips({
title: e.errMsg, title: e.errMsg,
icon: 'error' icon: 'error'
}); });
}, }
}) })
}, },
@ -434,10 +427,16 @@
// #ifndef MP // #ifndef MP
this.cartArr = this.cartArr.filter(item => item.channelCode !== 'wx_lite') this.cartArr = this.cartArr.filter(item => item.channelCode !== 'wx_lite')
// #endif // #endif
// #ifdef MP
this.cartArr = this.cartArr.filter(item => item.channelCode !== 'wx_pub')
// #endif
// 1.2 // 1.2
// #ifdef H5
if (!this.$wechat.isWeixin()) { if (!this.$wechat.isWeixin()) {
this.cartArr = this.cartArr.filter(item => item.channelCode !== 'wx_pub') this.cartArr = this.cartArr.filter(item => item.channelCode !== 'wx_pub')
} }
// #endif
// 2. // 2.
PayChannelApi.getEnableChannelCodeList(appId).then(res => { PayChannelApi.getEnableChannelCodeList(appId).then(res => {

View File

@ -243,6 +243,14 @@
this.setTabList() this.setTabList()
}, },
onLoad() { onLoad() {
// wx.login({
// success (res) {
// if (res.code) {
// console.log(res.code, '======== code =======')
// }
// }
// })
var that = this; var that = this;
// //
uni.getSystemInfo({ uni.getSystemInfo({

View File

@ -425,7 +425,7 @@
* 打开支付组件 * 打开支付组件
*/ */
goPay() { goPay() {
const returnUrl = '/pages/order_pay_status/index?order_id=' + this.orderInfo.id; const returnUrl = encodeURIComponent('/pages/order_pay_status/index?order_id=' + this.orderInfo.id);
uni.navigateTo({ uni.navigateTo({
url: `/pages/goods/cashier/index?order_id=${this.orderInfo.payOrderId}&returnUrl=${returnUrl}` url: `/pages/goods/cashier/index?order_id=${this.orderInfo.payOrderId}&returnUrl=${returnUrl}`
}) })

View File

@ -337,7 +337,7 @@
...this.getSettlementReqVO(), ...this.getSettlementReqVO(),
mark: this.mark, mark: this.mark,
}).then(res => { }).then(res => {
const returnUrl = '/pages/order_pay_status/index?order_id=' + res.data.id; const returnUrl = encodeURIComponent('/pages/order_pay_status/index?order_id=' + res.data.id);
uni.navigateTo({ uni.navigateTo({
url: `/pages/goods/cashier/index?order_id=${res.data.payOrderId}&returnUrl=${returnUrl}` url: `/pages/goods/cashier/index?order_id=${res.data.payOrderId}&returnUrl=${returnUrl}`
}); });

View File

@ -217,7 +217,7 @@
* 打开支付组件 * 打开支付组件
*/ */
goPay(id, payOrderId) { goPay(id, payOrderId) {
const returnUrl = '/pages/order_pay_status/index?order_id=' + id; const returnUrl = encodeURIComponent('/pages/order_pay_status/index?order_id=' + id);
uni.navigateTo({ uni.navigateTo({
url: `/pages/goods/cashier/index?order_id=${payOrderId}&returnUrl=${returnUrl}` url: `/pages/goods/cashier/index?order_id=${payOrderId}&returnUrl=${returnUrl}`
}) })

View File

@ -10,6 +10,18 @@ import {
} from '../libs/login'; } from '../libs/login';
import store from '../store'; import store from '../store';
// TODO 芋艿:临时解决 uniapp 在小程序undefined 会被 tostring 的问题
function deleteUndefinedProperties(obj) {
for (let key in obj) {
if (obj.hasOwnProperty(key)) {
if (typeof obj[key] === 'object' && obj[key] !== null) {
deleteUndefinedProperties(obj[key]); // 递归调用,处理嵌套的对象
} else if (obj[key] === undefined) {
delete obj[key];
}
}
}
}
/** /**
* 发送请求 * 发送请求
@ -32,6 +44,8 @@ function baseRequest(url, method, data, {
} }
} }
deleteUndefinedProperties(data)
// TODO 补个 header 多租户 // TODO 补个 header 多租户
if (url.indexOf('app-api') >= 0) { if (url.indexOf('app-api') >= 0) {
header = { header = {
@ -44,8 +58,10 @@ function baseRequest(url, method, data, {
if (store.state.app.token) header[TOKENNAME] = store.state.app.token; if (store.state.app.token) header[TOKENNAME] = store.state.app.token;
return new Promise((reslove, reject) => { return new Promise((reslove, reject) => {
uni.request({ uni.request({
url: url.indexOf('app-api') < 0 ? Url + '/api/front/' + url // url: url.indexOf('app-api') < 0 ? Url + '/api/front/' + url
: 'http://127.0.0.1:48080/' + url, // TODO 芋艿:搞个 url 的配置 // : 'http://127.0.0.1:48080/' + url, // TODO 芋艿:搞个 url 的配置
url: url.indexOf('app-api') < 0 ? Url + '/api/front/' + url
: 'http://yunai.natapp1.cc/' + url, // TODO 芋艿:搞个 url 的配置
method: method || 'GET', method: method || 'GET',
header: header, header: header,
data: data || {}, data: data || {},