Commit 8b8a24fe by huangzhi

feat: 微信支付

parent 57d42869
...@@ -6,11 +6,11 @@ let h2Prefix ...@@ -6,11 +6,11 @@ let h2Prefix
let ydlH5Prefix let ydlH5Prefix
if (isDevelopment) { if (isDevelopment) {
// hostPrefix = 'https://testnewm.ydl.com' hostPrefix = 'https://testnewm.ydl.com'
// // hostPrefix = 'http://192.168.211.138' // hostPrefix = 'http://192.168.211.138'
// apiPrefix = 'https://testapi.ydl.com' apiPrefix = 'https://testapi.ydl.com'
hostPrefix = 'https://newm-test.ydl.com' // 下云 // hostPrefix = 'https://newm-test.ydl.com' // 下云
apiPrefix = 'https://api-test.ydl.com' // 下云 // apiPrefix = 'https://api-test.ydl.com' // 下云
h2Prefix = 'https://h2.yidianling.com' h2Prefix = 'https://h2.yidianling.com'
ydlH5Prefix = 'https://testh5.ydl.com' ydlH5Prefix = 'https://testh5.ydl.com'
} else { } else {
......
...@@ -208,18 +208,20 @@ export default { ...@@ -208,18 +208,20 @@ export default {
}, },
// 跳转订单 // 跳转订单
navigateToOrder() { navigateToOrder() {
uni.navigateTo({ // const aa =
url: `/pages/pay/pay?title=支付&id=${1123}`, // 'orderId=90230307003008&totalAmount=0.03&balance=9779&payType=5&title=%E6%94%AF%E4%BB%98%E4%B8%AD%E9%97%B4%E9%A1%B5%E9%9D%A2'
})
// if (!this.isLogin) {
// this.handleLogin()
// return
// }
// const url = `${hostPrefix}/h5-course/my/components/Buylist`
// uni.navigateTo({ // uni.navigateTo({
// url: `/pages/web/web?title=已购订单&loadUrl=${encodeURIComponent(url)}`, // url: `/pages/pay/pay?${aa}`,
// }) // })
if (!this.isLogin) {
this.handleLogin()
return
}
const url = `${hostPrefix}/h5-course/my/components/Buylist`
uni.navigateTo({
url: `/pages/web/web?title=已购订单&loadUrl=${encodeURIComponent(url)}`,
})
}, },
}, },
} }
......
...@@ -10,9 +10,16 @@ ...@@ -10,9 +10,16 @@
import { hostPrefix } from '@/config' import { hostPrefix } from '@/config'
import Decimal from 'decimal.js' import Decimal from 'decimal.js'
// 要付款的前 要付款totalAmount // totalAmount 活动后实际的商品价格
// balance 可用余额 // balance 可用余额
const computeAmountForCombination = (totalAmount, balance) => { // payType 微信只有三种支付模式 1: 余额 5: 微信 7: 微信 + 余额
const computeAmountForCombination = (totalAmount, balance, payType) => {
if (payType === 1) {
return { payAmount: 0, payBalance: totalAmount }
}
if (payType === 5) {
return { payAmount: totalAmount, payBalance: 0 }
}
let payBalance = 0 let payBalance = 0
let payAmount = 0 let payAmount = 0
if (balance === 0) { if (balance === 0) {
...@@ -25,7 +32,7 @@ const computeAmountForCombination = (totalAmount, balance) => { ...@@ -25,7 +32,7 @@ const computeAmountForCombination = (totalAmount, balance) => {
} else { } else {
payBalance = totalAmount payBalance = totalAmount
} }
// 真实要额外付款微信,从余额扣款 // payAmount 真实要微信付款的钱, payBalance从余额扣款
return { payAmount, payBalance } return { payAmount, payBalance }
} }
...@@ -35,18 +42,22 @@ export default { ...@@ -35,18 +42,22 @@ export default {
return { return {
orderId: '', // 订单id orderId: '', // 订单id
payType: 1, // 支付方式,1: 余额 5: 微信 7: 微信 + 余额 payType: 1, // 支付方式,1: 余额 5: 微信 7: 微信 + 余额
payAmount: 0, // 支付方式 还需支付(除去余额扣款后,微信需要支付) totalAmount: 0, // 活动后实际的商品价格
payBalance: 0, // 从余额扣款 balance: 0, // 账户余额
loading: false, loading: false,
openId: this.$store.state.user.openId,
buyType: 1, // 1 是拼团购买,其他是 单独或券后购买
} }
}, },
onLoad(options) { onLoad(options) {
// 赋值 const { orderId, totalAmount, balance, payType } = options
const { orderId, payType, payAmount, payBalance } = options
this.orderId = orderId this.orderId = orderId
this.totalAmount = totalAmount ? Number(totalAmount) : 0
this.balance = balance ? Number(balance) : 0
this.payType = Number(payType) this.payType = Number(payType)
this.payAmount = Number(payAmount) // this.buyType = Number(buyType)
this.payBalance = Number(payBalance) // this.payAmount = Number(payAmount)
// this.payBalance = Number(payBalance)
// // 页面访问埋点 // // 页面访问埋点
// setTrackData({ // setTrackData({
// events: [ // events: [
...@@ -86,24 +97,26 @@ export default { ...@@ -86,24 +97,26 @@ export default {
// }) // })
this.loading = true this.loading = true
const { orderId, payType } = this const { openId, orderId, payType } = this
// eslint-disable-next-line no-unused-vars // eslint-disable-next-line no-unused-vars
const { payAmount, payBalance } = computeAmountForCombination(this.totalAmount, this.balance) const { payAmount, payBalance } = computeAmountForCombination(
this.totalAmount,
this.balance,
this.payType,
)
try { try {
const wxUrl = encodeURIComponent('http://m.ydl.com?backPayId=' + this.payId) const wxUrl = encodeURIComponent('http://m.ydl.com?backPayId=' + this.payId)
const parmas = { const parmas = {
openId,
returnUrl: wxUrl, // 支付完成 returnUrl: wxUrl, // 支付完成
quitUrl: wxUrl, // 中断支付 quitUrl: wxUrl, // 中断支付
orderId, orderId,
payType, payType,
// todo payAmount, // 支付方式 还需支付(除去余额扣款后,微信需要支付)
payAmount: 0.01, payBalance, // 从账户余额中要扣款的钱
// payAmount,
payBalance,
payChannel: 'WX_MINI_APP', payChannel: 'WX_MINI_APP',
// appId: appId,??
} }
console.log('请求parmas::payAmount', payAmount)
console.log('请求parmas::', parmas) console.log('请求parmas::', parmas)
const res = await this.$request.post('/auth/cashierV2/unityPay', parmas, { const res = await this.$request.post('/auth/cashierV2/unityPay', parmas, {
...@@ -179,7 +192,10 @@ export default { ...@@ -179,7 +192,10 @@ export default {
title: '支付成功', title: '支付成功',
duration: 1500, duration: 1500,
}) })
const url = `${hostPrefix}/h5-course/pay/groupSuccess`
// 当前只有拼团业务才会被分享出来,在微信小程序中支付
const url = `${hostPrefix}/h5-course/pay/groupSuccess?ccc=qwe&ttt=123`
uni.navigateTo({ uni.navigateTo({
url: `/pages/web/web?title=${ url: `/pages/web/web?title=${
this.doctor.name ? `${this.doctor.name}的评价` : '' this.doctor.name ? `${this.doctor.name}的评价` : ''
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment