263 lines
6.2 KiB
JavaScript
263 lines
6.2 KiB
JavaScript
import { apiInitPay } from '../api/common';
|
|
import { useUserStore } from '../store/user';
|
|
import { baseUrl } from '../utils/request';
|
|
import { getConfig } from '@/pages/index/api';
|
|
import i18n from '../lang';
|
|
|
|
/**
|
|
* @desc 获取全局配置参数
|
|
*/
|
|
export const getConfigInfo = () => {
|
|
getConfig().then((res) => {
|
|
if (res.success) {
|
|
const bottomNavList = res.data?.bottomNavList;
|
|
// if (bottomNavList.length > 0) {
|
|
// bottomNavList.map((item) => {
|
|
// uni.setTabBarItem({
|
|
// ...item,
|
|
// });
|
|
// });
|
|
// }
|
|
}
|
|
});
|
|
};
|
|
|
|
/**
|
|
* @desc 退款协议
|
|
* @params companyCode 退款协议需要conpanyCode
|
|
* @params isRefund false非退款协议 true退款协议
|
|
* @return html富文本
|
|
*/
|
|
export function serviceApi(companyCode, isRefund) {
|
|
return new Promise((resolve, reject) => {
|
|
let id;
|
|
if (isRefund) {
|
|
id = companyCode === 'turbojet' ? 34 : 35;
|
|
} else {
|
|
id = 1;
|
|
}
|
|
request
|
|
.post(api.infoMessage, {
|
|
id: id,
|
|
})
|
|
.then((res) => {
|
|
if (res.success) {
|
|
resolve(res.data.content);
|
|
} else {
|
|
uni.showToast({
|
|
icon: 'none',
|
|
title: res.message,
|
|
});
|
|
reject();
|
|
}
|
|
});
|
|
});
|
|
}
|
|
|
|
//
|
|
/**
|
|
* @desc APP调用第三方程序 集成微信,支付寶跳轉
|
|
*/
|
|
export function launchApp() {
|
|
if (
|
|
plus.runtime.isApplicationExist({
|
|
pname: 'com.tencent.mm',
|
|
action: 'weixin://',
|
|
}) &&
|
|
paymentKey.value.includes('wx')
|
|
) {
|
|
// 跳转应用
|
|
plus.runtime.launchApplication(
|
|
{
|
|
pname: 'com.tencent.mm',
|
|
action: 'weixin://',
|
|
},
|
|
function (e) {
|
|
console.log('e', e);
|
|
}
|
|
);
|
|
// 检查支付通道
|
|
plus.payment.getChannels((res) => {
|
|
console.log('getChannels', res);
|
|
});
|
|
// 后台获取支付参数
|
|
request
|
|
.post(api.pay, {
|
|
groupId: groupId.value,
|
|
payAgentId: payAgentId.value,
|
|
})
|
|
.then((res) => {
|
|
// 拉起微信支付
|
|
plus.payment.request(
|
|
'wxpay',
|
|
res.data,
|
|
function (resp) {
|
|
console.log('resp', resp);
|
|
},
|
|
function (err) {
|
|
console.log('err', err);
|
|
}
|
|
);
|
|
});
|
|
}
|
|
// 判断支付宝
|
|
if (
|
|
plus.runtime.isApplicationExist({
|
|
pname: 'com.eg.android.AlipayGphone',
|
|
action: 'alipay://',
|
|
}) &&
|
|
paymentKey.value.includes('zfb')
|
|
) {
|
|
plus.runtime.launchApplication(
|
|
{
|
|
pname: 'com.eg.android.AlipayGphone',
|
|
action: 'alipay://',
|
|
},
|
|
function (e) {
|
|
console.log('launchApplication', e.message);
|
|
}
|
|
);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @desc 处理支付
|
|
* @params groupId 订单组id
|
|
* @return 支付参数
|
|
*/
|
|
export const handlePay = (groupId) => {
|
|
return new Promise(async (resolve, reject) => {
|
|
const res = await apiInitPay(groupId);
|
|
if (res.success) {
|
|
console.log(res.data);
|
|
const payInfo = res.data;
|
|
// 半屏支付
|
|
if (payInfo.payType === 'mpSkip') {
|
|
uni.openEmbeddedMiniProgram({
|
|
...payInfo.mpSkipParam,
|
|
success: (res) => {
|
|
console.log('success', res);
|
|
resolve(res.data);
|
|
},
|
|
fail: (err) => {
|
|
console.log('fail', err);
|
|
resolve(err.message);
|
|
},
|
|
});
|
|
} else if (payInfo.payType === 'direct') {
|
|
handleDirectPay(groupId, () => {
|
|
resolve();
|
|
});
|
|
}
|
|
} else {
|
|
resolve(res.message);
|
|
}
|
|
});
|
|
};
|
|
|
|
export function handleDirectPay(orderNo, callback) {
|
|
const userStore = useUserStore();
|
|
let __userToken = userStore.userToken;
|
|
let __lang = userStore.lang;
|
|
let __platform = userStore.platform;
|
|
let orderNum = typeof orderNo === 'object' ? orderNo.join(',') : orderNo;
|
|
uni.showLoading({
|
|
mask: true,
|
|
title: 'loading...',
|
|
});
|
|
uni.request({
|
|
url: baseUrl + '/sale/pay/pay',
|
|
method: 'POST',
|
|
data: {
|
|
groupId: orderNum,
|
|
__token: __userToken,
|
|
__platform: __platform,
|
|
__language: __lang,
|
|
channelId: 33,
|
|
},
|
|
success: (res) => {
|
|
if (res.data.code === 0) {
|
|
let requestParams = {};
|
|
// #ifdef MP-BAIDU
|
|
requestParams = {
|
|
orderInfo: {
|
|
...res.data.data,
|
|
...res.data.data.thirdParams,
|
|
},
|
|
};
|
|
// #endif
|
|
console.log(res.data.data);
|
|
// #ifndef MP-BAIDU
|
|
requestParams = {
|
|
orderInfo: res.data.data.thirdParams ? res.data.data.thirdParams.frontData.tradeNo : '',
|
|
timeStamp: res.data.data.timeStamp,
|
|
nonceStr: res.data.data.nonceStr,
|
|
package: res.data.data.package,
|
|
signType: res.data.data.signType,
|
|
paySign: res.data.data.paySign,
|
|
};
|
|
// #endif
|
|
uni.requestPayment({
|
|
...requestParams,
|
|
success(res) {
|
|
// #ifdef MP-ALIPAY
|
|
if (res.resultCode === '6001') {
|
|
uni.showToast({
|
|
icon: 'none',
|
|
title: i18n.global.t('cancelPay'),
|
|
duration: 2000,
|
|
});
|
|
}
|
|
if (res.resultCode === '9000') {
|
|
uni.showToast({
|
|
icon: 'none',
|
|
title: i18n.global.t('paySuccess'),
|
|
duration: 2000,
|
|
});
|
|
}
|
|
// #endif
|
|
// #ifndef MP-ALIPAY
|
|
uni.showToast({
|
|
icon: 'none',
|
|
title: i18n.global.t('paySuccess'),
|
|
});
|
|
// #endif
|
|
},
|
|
fail(res) {
|
|
console.log('fail-res', res);
|
|
uni.showToast({
|
|
icon: 'none',
|
|
title: i18n.global.t('payFailed'),
|
|
mask: true,
|
|
});
|
|
},
|
|
complete() {
|
|
callback();
|
|
},
|
|
});
|
|
} else {
|
|
// 创建失败
|
|
uni.showToast({
|
|
icon: 'none',
|
|
title: res.data.message,
|
|
mask: true,
|
|
});
|
|
callback();
|
|
}
|
|
},
|
|
fail: (err) => {
|
|
console.log('fail-err', err);
|
|
uni.showToast({
|
|
icon: 'none',
|
|
title: err.message,
|
|
});
|
|
setTimeout(() => {
|
|
callback();
|
|
}, 1500);
|
|
},
|
|
complete() {
|
|
uni.hideLoading();
|
|
},
|
|
});
|
|
}
|