Просмотр исходного кода

fix: 修复充值金额校验穿透,退款金额统一为可退口径并增加 0 元拦截

skyline 3 недель назад
Родитель
Сommit
6a172c9a55

+ 12 - 9
charge-front/src/pages-user/wallet-recharge/wallet-recharge.vue

@@ -84,6 +84,7 @@ import {onLoad} from "@dcloudio/uni-app";
 import {back, to} from "@/utils/navigate";
 import { requireAuth } from "@/utils/auth";
 import {debounce} from "@/utils/util";
+import { fenToYuan } from "@/utils/money";
 import StyleDialog from "@/components/style-dialog/style-dialog.vue";
 
 const balance = ref(0);
@@ -101,10 +102,8 @@ const stationVisible = ref(false)
 
 
 const handleShowActivityStationDialog = () => {
-  console.log(stationVisible)
   if(activityStationList.value&&activityStationList.value.length>0&&payOptionsDiscount.value[payOption.value]){
     stationVisible.value = true;
-    console.log(stationVisible)
   }
 }
 
@@ -138,7 +137,7 @@ const confirm = () => {
   const params = payValue.value
       ? Number(payValue.value)
       : payOptions.value[payOption.value];
-  if (params > 10000 || params <= 0) {
+  if (!params || params <= 0 || params > 10000) {
     uni.showModal({
       title: "温馨提示",
       content: "每次最大充值金额10000,请修改金额",
@@ -185,19 +184,23 @@ onLoad((options: any) => {
   if (!requireAuth()) {
     return;
   }
-  console.log(options)
   if (options.value) {
-    payOption.value = payOptions.value.findIndex(
-        (item) => item === Number((Number(options.value) / 100).toFixed(2))
+    const match = payOptions.value.findIndex(
+        (item) => item === Number(fenToYuan(options.value))
     );
+    if (match >= 0) {
+      payOption.value = match;
+    } else {
+      // 金额不匹配预设档位时,填入自定义金额,避免 payOption 落空导致校验穿透
+      payValue.value = Number(fenToYuan(options.value));
+    }
     needBack.value = !!options.back;
   }
 
   if (options.discount) {
-    payValue.value = Number((Number(options.discount) / 100).toFixed(2));
+    payValue.value = Number(fenToYuan(options.discount));
   }
   fetchProfile().then((res) => {
-    // console.log(res);
     balance.value = res.balance;
     if (res && res.activityList && res.activityList.length) {
       let stationList = res.activityList[0].stationList;
@@ -206,7 +209,7 @@ onLoad((options: any) => {
       }
 
       res.activityList[0].rechargeRightsList.forEach((item: any) => {
-        const val = Number((Number(item.amountMin) / 100).toFixed(2));
+        const val = Number(fenToYuan(item.amountMin));
         const fi = payOptions.value.findIndex((o) => o === val);
         if (fi >= 0) {
           payOptionsDiscount.value[fi] = ((item.discount || 0) / 10).toFixed(1);

+ 13 - 3
charge-front/src/pages-user/wallet-refund/wallet-refund.vue

@@ -77,7 +77,7 @@
 </template>
 
 <script setup lang="ts">
-import { applyRefund } from "@/api/user";
+import { applyRefund, fetchProfile } from "@/api/user";
 import { onLoad } from "@dcloudio/uni-app";
 import { ref } from "vue";
 
@@ -99,12 +99,19 @@ onLoad(() => {
   if (getApp<any>().globalData.user) {
     user.value = getApp<any>().globalData.user;
     allRefund();
+  } else {
+    // 直接进入页面时 globalData 可能未初始化,拉取用户信息兜底
+    fetchProfile().then((res) => {
+      user.value = res;
+      allRefund();
+    });
   }
 });
 
 const allRefund = () => {
   if (user.value) {
-    value.value = Number(user.value.balance);
+    // 与"可退金额"文案及后端实际退款口径保持一致
+    value.value = Number(user.value.refundableAmount);
   }
 };
 const changeReason = (i: number) => {
@@ -117,6 +124,10 @@ const submit = () => {
   if (submitting.value) {
     return;
   }
+  if (!value.value || value.value <= 0) {
+    uni.showToast({ title: "当前无可退金额", icon: "none" });
+    return;
+  }
   submitting.value = true;
   uni.showLoading({
     title: "提交中",
@@ -138,7 +149,6 @@ const submit = () => {
       success.value = true;
     })
     .catch((err) => {
-      console.log(err);
       uni.hideLoading();
       uni.showModal({
         content: err.errMsg,