wallet:接入钱包充值

pull/3/head
YunaiV 2023-09-30 18:54:26 +08:00
parent 5981432ff7
commit 03ceb0bcf3
2 changed files with 78 additions and 188 deletions

View File

@ -9,3 +9,13 @@ export function getPayWallet() {
export function getWalletTransactionPage(data) { export function getWalletTransactionPage(data) {
return request.get("app-api/pay/wallet-transaction/page", data); return request.get("app-api/pay/wallet-transaction/page", data);
} }
// 获得钱包充值套餐列表
export function getWalletRechargePackageList() {
return request.get("app-api/pay/wallet-recharge-package/list");
}
// 创建钱包充值记录(发起充值)
export function createWalletRecharge(data) {
return request.post("app-api/pay/wallet-recharge/create", data);
}

View File

@ -4,32 +4,38 @@
<view class="payment-top acea-row row-column row-center-wrapper"> <view class="payment-top acea-row row-column row-center-wrapper">
<span class="name">我的余额</span> <span class="name">我的余额</span>
<view class="pic"> <view class="pic">
<span class="pic-font">{{ userInfo.nowMoney || 0 }}</span> <span class="pic-font">{{ fen2yuan(wallet.balance || 0) }}</span>
</view> </view>
</view> </view>
<view class="payment"> <view class="payment">
<view class="nav acea-row row-around row-middle"> <view class="nav acea-row row-around row-middle">
<view class="item" :class="active==index?'on':''" v-for="(item,index) in navRecharge" :key="index" @click="navRecharges(index)">{{item}}</view> <view class="item" :class="active==index?'on':''" v-for="(item,index) in navRecharge" :key="index" @click="navRecharges(index)">{{item}}</view>
</view> </view>
<!-- 充值 -->
<view class='tip picList' v-if='!active'> <view class='tip picList' v-if='!active'>
<view class="pic-box pic-box-color acea-row row-center-wrapper row-column" :class="activePic === index ? 'pic-box-color-active' : ''" <view class="pic-box pic-box-color acea-row row-center-wrapper row-column" :class="activePic === index ? 'pic-box-color-active' : ''"
v-for="(item, index) in picList" :key="index" @click="picCharge(index, item)"> v-for="(item, index) in picList" :key="index" @click="picCharge(index, item)">
<view class="pic-number-pic"> <view class="pic-number-pic">
{{ item.price }}<span class="pic-number"> </span> {{ fen2yuan(item.payPrice) }}<span class="pic-number"> </span>
</view> </view>
<view class="pic-number">赠送{{ item.giveMoney }} </view> <view class="pic-number">赠送{{ fen2yuan(item.bonusPrice) }} </view>
</view> </view>
<view class="pic-box pic-box-color acea-row row-center-wrapper" :class="parseFloat(activePic)===parseFloat(picList.length)?'pic-box-color-active':''" @click="picCharge(picList.length)"> <view class="pic-box pic-box-color acea-row row-center-wrapper" :class="parseFloat(activePic)===parseFloat(picList.length)?'pic-box-color-active':''"
<input type="number" placeholder="其他" v-model="money" :maxlength="50000" class="pic-box-money pic-number-pic uni-input" :class="parseFloat(activePic) === parseFloat(picList.length) ? 'pic-box-color-active' : ''" /> @click="picCharge(picList.length)">
<input type="number" placeholder="其他" v-model="money" :maxlength="50000" class="pic-box-money pic-number-pic uni-input"
:class="parseFloat(activePic) === parseFloat(picList.length) ? 'pic-box-color-active' : ''" />
</view> </view>
<view class="tips-box"> <view class="tips-box">
<view class="tips mt-30">注意事项</view> <view class="tips mt-30">注意事项</view>
<view class="tips-samll" v-for="item in rechargeAttention" :key="item"> <view class="tips-samll" v-for="item in rechargeAttention" :key="item">
{{ item }} {{ item }}
</view> </view>
</view> </view>
</view> <button class='but' formType="submit"> 立即充值 </button>
<view class="tip" v-else> </view>
<!-- 佣金提现 -->
<view class="tip" v-else>
<view class='input'><text></text><input placeholder="0.00" type='number' placeholder-class='placeholder' :value="number" <view class='input'><text></text><input placeholder="0.00" type='number' placeholder-class='placeholder' :value="number"
name="number"></input></view> name="number"></input></view>
<view class="tips-title"> <view class="tips-title">
@ -42,60 +48,45 @@
{{ item }} {{ item }}
</view> </view>
</view> </view>
</view> <button class='but' formType="submit"> 立即转入 </button>
<button class='but' formType="submit"> {{active ? '立即转入': '立即充值' }}</button> </view>
</view> </view>
</form> </form>
<!-- #ifdef MP -->
<!-- <authorize @onLoadFun="onLoadFun" :isAuto="isAuto" :isShowAuth="isShowAuth" @authColse="authColse"></authorize> -->
<!-- #endif -->
<home></home> <home></home>
</view> </view>
</template> </template>
<script> <script>
import { import { transferIn } from '@/api/user.js';
rechargeRoutine, import * as WalletApi from '@/api/pay/wallet.js';
rechargeWechat, import * as Util from '@/utils/util.js';
getRechargeApi, import { toLogin } from '@/libs/login.js';
transferIn, import { mapGetters } from "vuex";
appWechat
} from '@/api/user.js';
import { wechatQueryPayResult } from '@/api/order.js';
import {
toLogin
} from '@/libs/login.js';
import {
mapGetters
} from "vuex";
// #ifdef MP
import authorize from '@/components/Authorize';
// #endif
import home from '@/components/home'; import home from '@/components/home';
export default { export default {
components: { components: {
// #ifdef MP
authorize,
// #endif
home home
}, },
data() { data() {
let that = this;
return { return {
now_money: 0, wallet: {},
now_money: 0,
navRecharge: ['账户充值', '佣金转入'], navRecharge: ['账户充值', '佣金转入'],
active: 0, active: 0,
number: '', number: '',
placeholder: "0.00", placeholder: "0.00",
from: '', from: '',
isAuto: false, //
isShowAuth: false, //
picList: [], picList: [],
activePic: 0, activePic: 0,
money: "", money: "",
numberPic: '', rechar_id: 0, //
rechar_id: 0, rechargeAttention: [
rechargeAttention: [] '1、充值金额最少为 1 元',
'2、充值后只能用于消费',
'3、提现金额需要有手续费',
'4、提现到账需要 2~3 天时间'
]
}; };
}, },
computed: mapGetters(['isLogin', 'systemPlatform','userInfo']), computed: mapGetters(['isLogin', 'systemPlatform','userInfo']),
@ -110,23 +101,13 @@
} }
}, },
onLoad(options) { onLoad(options) {
// #ifdef H5 if (!this.isLogin) {
this.from = this.$wechat.isWeixin() ? "public" : "weixinh5"; toLogin();
// #endif
if (true) {
alert('充值功能暂未实现!预期 10 月份');
return; return;
}
if (this.isLogin) {
this.getRecharge();
} else {
toLogin();
} }
this.getRecharge();
}, },
methods: { methods: {
/** /**
* 选择金额 * 选择金额
*/ */
@ -134,47 +115,42 @@
this.activePic = idx; this.activePic = idx;
if (item === undefined) { if (item === undefined) {
this.rechar_id = 0; this.rechar_id = 0;
this.numberPic = "";
} else { } else {
this.money = ""; this.money = "";
this.rechar_id = item.id; this.rechar_id = item.id;
this.numberPic = item.price;
} }
}, },
/** /**
* 充值额度选择 * 充值额度选择
*/ */
getRecharge() { getRecharge() {
getRechargeApi() //
.then(res => { WalletApi.getPayWallet().then(res=>{
this.picList = res.data.rechargeQuota; this.wallet = res.data;
if (this.picList[0]) { })
this.rechar_id = this.picList[0].id;
this.numberPic = this.picList[0].price;
}
this.rechargeAttention = res.data.rechargeAttention || [];
})
.catch(res => {
this.$dialog.toast({
mes: res
});
});
},
//
WalletApi.getWalletRechargePackageList().then(res => {
this.picList = res.data;
if (this.picList.length > 0) {
this.rechar_id = this.picList[0].id;
}
}).catch(res => {
this.$dialog.toast({
mes: res
});
});
},
onLoadFun: function() { onLoadFun: function() {
this.getRecharge(); this.getRecharge();
}, },
//
authColse: function(e) {
this.isShowAuth = e
},
navRecharges: function(index) { navRecharges: function(index) {
this.active = index; this.active = index;
}, },
/*
/**
* 用户充值 * 用户充值
*/ */
submitSub: function(e) { submitSub: function(e) {
@ -223,7 +199,7 @@
title: '正在支付', title: '正在支付',
}) })
let money = parseFloat(this.money); let money = parseFloat(this.money);
if (this.rechar_id == 0) { if (this.rechar_id === 0) {
if (Number.isNaN(money)) { if (Number.isNaN(money)) {
return that.$util.Tips({ return that.$util.Tips({
title: '充值金额必须为数字' title: '充值金额必须为数字'
@ -231,131 +207,35 @@
} }
if (money <= 0) { if (money <= 0) {
return that.$util.Tips({ return that.$util.Tips({
title: '充值金额不能为0' title: '充值金额不能为 0'
}); });
} }
if (money > 50000) { if (money > 50000) {
return that.$util.Tips({ return that.$util.Tips({
title: '充值金额最大值为50000' title: '充值金额最大值为 50000'
}); });
} }
} else {
money = this.numberPic
} }
// #ifdef MP WalletApi.createWalletRecharge({
rechargeRoutine({ payPrice: money ? money * 100 : undefined,
price: money, packageId: this.rechar_id
type: 0,
rechar_id: this.rechar_id
}).then(res => { }).then(res => {
uni.hideLoading(); const returnUrl = encodeURIComponent('/pages/users/user_payment/index');
let jsConfig = res.data.data.jsConfig; uni.navigateTo({
uni.requestPayment({ url: `/pages/goods/cashier/index?order_id=${res.data.payOrderId}&returnUrl=${returnUrl}`
timeStamp: jsConfig.timeStamp, })
nonceStr: jsConfig.nonceStr,
package: jsConfig.packages,
signType: jsConfig.signType,
paySign: jsConfig.paySign,
success: function(res) {
that.$store.commit("changInfo", {
amount1: 'nowMoney',
amount2: that.$util.$h.Add(value, that.userinfo.nowMoney)
});
//that.$set(that, 'userinfo.nowMoney', that.$util.$h.Add(value, that.userinfo.nowMoney));
return that.$util.Tips({
title: '支付成功',
icon: 'success'
}, {
tab: 5,
url: '/pages/users/user_money/index'
});
},
fail: function(err) {
return that.$util.Tips({
title: '支付失败'
});
},
complete: function(res) {
if (res.errMsg == 'requestPayment:cancel') return that.$util.Tips({
title: '取消支付'
});
}
})
}).catch(err => { }).catch(err => {
uni.hideLoading(); uni.hideLoading();
return that.$util.Tips({ return that.$util.Tips({
title: err title: err
}) })
}); });
// #endif
// #ifdef H5
rechargeWechat({
price: money,
from: that.from,
rechar_id: that.rechar_id,
payType: 0
}).then(res => {
let jsConfig = res.data.jsConfig;
let orderNo = res.data.orderNo;
let data = {
timestamp:jsConfig.timeStamp,
nonceStr:jsConfig.nonceStr,
package:jsConfig.packages,
signType:jsConfig.signType,
paySign:jsConfig.paySign
};
if (that.from == "weixinh5") {
let domain = encodeURIComponent(location.href.split('/pages')[0]);
let urls = jsConfig.mwebUrl + '&redirect_url='+ domain + '/pages/users/user_money/index';
location.replace(urls);
return that.$util.Tips({
tab: 5,
url: '/pages/users/user_money/index'
});
// return that.$util.Tips({
// title: '',
// icon: 'success'
// }, {
// tab: 5,
// url: '/pages/users/user_money/index'
// });
} else {
that.$wechat.pay(data)
.finally(() => {
that.$store.commit("changInfo", {
amount1: 'nowMoney',
amount2: that.$util.$h.Add(value, that.userinfo.nowMoney)
});
// that.$set(that, 'userinfo.nowMoney', that.$util.$h.Add(value, that.userinfo.nowMoney));
wechatQueryPayResult(orderNo).then(res => {
return that.$util.Tips({
title: '支付成功',
icon: 'success'
}, {
tab: 5,
url: '/pages/users/user_money/index'
});
}).cache(err => {
return that.$util.Tips({
title: err
});
})
})
.catch(function(err) {
return that.$util.Tips({
title: '支付失败'
});
});
}
}).catch(res=>{
uni.hideLoading();
return that.$util.Tips({
title: res
});
})
// #endif
} }
} },
fen2yuan(price) {
return Util.fen2yuan(price)
}
} }
} }
</script> </script>