yshop3.1正式发布

This commit is contained in:
xuwenbo
2020-09-14 21:01:28 +08:00
parent 5800da20d2
commit 8a85f44ff6
74 changed files with 9959 additions and 4639 deletions

View File

@ -73,80 +73,120 @@ export function delOrderHandle(orderId) {
}
// 使用订单号进行支付
export function payOrderHandle(orderId, type, from) {
export async function payOrderHandle(orderId, type, from) {
return new Promise((resolve, reject) => {
// dialog.loading.open("");
uni.showLoading({
title: "支付中",
mask: true
});
payOrder(orderId, type, from)
.then(res => {
handleOrderPayResults(res.data)
.then(async res => {
await handleOrderPayResults(res.data, type)
resolve()
})
.catch(err => {
dialog.loading.close();
dialog.toast({ mes: err.msg || "订单支付失败" });
reject()
uni.hideLoading()
uni.showToast({
title: err.msg || err.response.data.msg || err.response.data.message || '订单支付失败',
icon: "none",
duration: 2000,
});
});
});
}
// 处理调用支付接口的逻辑
// @type create(创建订单)||pay(支付订单)
export function handleOrderPayResults(data, type) {
switch (data.status) {
// 订单号已存在
case "ORDER_EXIST":
// 取消支付
case "EXTEND_ORDER":
uni.showToast({
title: res.msg,
icon: "none",
duration: 2000,
});
goOrderDetails(data.result.orderId, type)
break;
case "PAY_DEFICIENCY":
break;
// 支付出错
case "PAY_ERROR":
uni.showToast({
title: res.msg,
icon: "none",
duration: 2000,
});
goOrderDetails(data.result.orderId, type)
break;
// 未传递支付环境
case "SUCCESS":
uni.showToast({
title: res.msg,
icon: "none",
duration: 2000,
});
goOrderDetails(data.result.orderId, type)
break;
// H5支付
case "WECHAT_H5_PAY":
goOrderDetails(data.result.orderId, type)
console.log(data)
setTimeout(() => {
// #ifdef H5
// "https://wx.tenpay.com/cgi-bin/mmpayweb-bin/checkmweb?prepay_id=wx15171343713577e9f3a418b0865ef90000&package=2547890641"
// location.href = data.result.jsConfig.mweb_url;
// #endif
}, 100);
break;
// 小程序支付
case "WECHAT_PAY":
weappPay(data.result.jsConfig).finally(() => {
export function handleOrderPayResults(data, type, payType) {
console.log(data, type, payType)
console.log(data, type)
return new Promise((resolve, reject) => {
uni.hideLoading()
switch (data.status) {
// 订单号已存在
case "ORDER_EXIST":
resolve()
break;
// 取消支付
case "EXTEND_ORDER":
uni.showToast({
title: data.msg,
icon: "none",
duration: 2000,
});
resolve()
goOrderDetails(data.result.orderId, type)
});
break;
// APP支付
case "WECHAT_APP_PAY":
weappPay(data.result.jsConfig).finally(() => {
break;
case "PAY_DEFICIENCY":
break;
// 支付出错
case "PAY_ERROR":
uni.showToast({
title: data.msg,
icon: "none",
duration: 2000,
});
reject()
goOrderDetails(data.result.orderId, type)
});
break;
}
break;
// 未传递支付环境
case "SUCCESS":
uni.showToast({
title: data.msg || data.payMsg,
icon: "none",
duration: 2000,
});
resolve()
goOrderDetails(data.result.orderId, type)
break;
// H5支付
case "WECHAT_H5_PAY":
goOrderDetails(data.result.orderId, type)
console.log(data)
setTimeout(() => {
resolve()
// #ifdef H5
// "https://wx.tenpay.com/cgi-bin/mmpayweb-bin/checkmweb?prepay_id=wx15171343713577e9f3a418b0865ef90000&package=2547890641"
// location.href = data.result.jsConfig.mweb_url;
// #endif
}, 100);
break;
// 小程序支付
case "WECHAT_PAY":
weappPay(data.result.jsConfig).finally(() => {
resolve()
goOrderDetails(data.result.orderId, type)
}).then(res => {
// #ifdef MP-WEIXIN
subscribeMessage()
// #endif
})
break;
// APP支付
case "WECHAT_APP_PAY":
weappPay(data.result.jsConfig).finally(() => {
resolve()
goOrderDetails(data.result.orderId, type)
})
break;
}
})
}
export function subscribeMessage() {
// 调用订阅
console.log('调用订阅')
uni.requestSubscribeMessage({
tmplIds: ['W5r2c2kzhbq8uxStkPAVx_sk-5aapMFCqe7b7KU5jXI', '2CB_1UyQrbnlyjJa5syraqJ3cfztPPDOAHe3DEXpMjg', 'vuztugw9VbKbKJDAAVePkjqPpT5mdoREpd4Aq7EGPRU'],
success(res) {
console.log(res)
},
fail(error){
console.log(error)
}
})
}

View File

@ -1,3 +1,4 @@
import { subscribeMessage } from "@/libs/order";
import { getProvider } from "@/utils";
import WechatJSSDK from "wechat-jssdk/dist/client.umd";
import { getWechatConfig, wechatAuth } from "@/api/public";
@ -9,7 +10,6 @@ import dayjs from "dayjs";
// 支付模块
export const weappPay = (option) => {
return new Promise((resolve, reject) => {
console.log(option)
if (store.state.$deviceType == 'weixinh5') {
setTimeout(() => {
location.href = option.mweb_url;
@ -59,11 +59,16 @@ export const weappPay = (option) => {
clearTimeout(time)
resolve(success)
}, 3000)
// #ifdef MP-WEIXIN
subscribeMessage()
// #endif
},
fail: (error) => {
console.log(error)
if (error.errMsg == 'requestPayment:fail cancel') {
uni.showToast({ title: '已取消支付', icon: 'none', duration: 5000 });
} else {
uni.showToast({ title: error || error.msg, icon: 'none', duration: 5000 });
}
reject(error)
}
@ -119,6 +124,7 @@ export function clearAuthStatus() {
export function oAuth() {
console.log('处理微信授权')
console.log('处理微信授权cookie',cookie.get("spread"))
console.log(store)
console.log(store.state)
return new Promise((resolve, reject) => {
@ -142,8 +148,7 @@ export function auth(code) {
console.log('获取微信授权')
return new Promise((resolve, reject) => {
let loginType = cookie.get(LOGINTYPE);
debugger
wechatAuth(code, parseInt(cookie.get("spread")), loginType)
wechatAuth(code, cookie.get("spread"), loginType)
.then(({ data }) => {
console.log(data)
const expires_time = dayjs(data.expires_time);
@ -152,12 +157,10 @@ export function auth(code) {
cookie.set(WX_AUTH, code, expires_time);
cookie.remove(STATE_KEY);
loginType && cookie.remove(LOGINTYPE);
debugger
resolve();
})
.catch(reject);
}).catch(error => {
debugger
console.log(error)
})
}
@ -347,12 +350,20 @@ export function wxShowLocation() {
cancel() {
cookie.remove(LATITUDE);
cookie.remove(LONGITUDE);
this.$dialog.error("取消获取位置");
uni.showToast({
title: "取消获取位置",
icon: "none",
duration: 2000,
});
},
fail() {
cookie.remove(LATITUDE);
cookie.remove(LONGITUDE);
this.$dialog.error("授权失败");
uni.showToast({
title: "授权失败",
icon: "none",
duration: 2000,
});
}
});
}