From db03391c6bde1f7b1a93164930799fc434c0f9f2 Mon Sep 17 00:00:00 2001
From: 石广澎 <shiguangpeng@163.com>
Date: 星期四, 10 十月 2024 17:16:48 +0800
Subject: [PATCH] feat(支付): 数学计算工具

---
 common/util.js  |   61 ++++++++++++++++++++++++++++++
 manifest.json   |   15 +++++++
 pay/scanpay.vue |   36 +++++++++--------
 3 files changed, 93 insertions(+), 19 deletions(-)

diff --git a/common/util.js b/common/util.js
index 7efe01b..43a17d8 100644
--- a/common/util.js
+++ b/common/util.js
@@ -10,7 +10,43 @@
         return false
     }
 }
+/**
+ * 涓ゆ暟鐩镐箻 arg1 * arg2
+ * @Date 2020/5/9 13:19
+ **/
+export function accMul(arg1, arg2) {
+    let t = 0
+    arg1 = arg1 ? arg1.toString() : '0'
+    arg2 = arg2 ? arg2.toString() : '0'
+    if (arg1.includes('.')) {
+        t += arg1.split('.')[1].length
+    }
+    if (arg2.includes('.')) {
+        t += arg2.split('.')[1].length
+    }
+    const r1 = Number(arg1.replace('.', ''))
+    const r2 = Number(arg2.replace('.', ''))
+    return (r1 * r2) / Math.pow(10, t)
+}
 
+/**
+ * 涓ゆ暟鐩搁櫎 arg1 / arg2
+ * @Date 2020/5/9 13:18
+ **/
+export function accDiv(arg1, arg2) {
+    let t = 0
+    arg1 = arg1 ? arg1.toString() : '0'
+    arg2 = arg2 ? arg2.toString() : '0'
+    if (arg2.includes('.')) {
+        t = arg2.split('.')[1].length
+    }
+    if (arg1.includes('.')) {
+        t -= arg1.split('.')[1].length
+    }
+    const r1 = Number(arg1.replace('.', ''))
+    const r2 = Number(arg2.replace('.', ''))
+    return accMul((r1 / r2), Math.pow(10, t))
+}
 /**
  * 鍒ゆ柇闈炵┖
  * @param {Object} str
@@ -70,7 +106,30 @@
     }
     return parseFloat(val) / 100
 }
-
+/* 鍏冭浆鍒� */
+export function yuanToFen(amount) {
+    let fen = 0
+    if (!amount) {
+        return fen;
+    }
+    fen = accMul(amount,100)
+    console.log(amount,fen);
+    return fen
+}
+/* 鍒嗚浆鍏� */
+export function fenToYuan(amount) {
+    if (!amount) {
+        return "0";
+    }
+    amount = amount.toString();
+    if (amount.length == 1) {
+        return parseFloat("0.0" + amount);
+    } else if (amount.length == 2) {
+        return parseFloat("0." + amount);
+    } else {
+        return parseFloat(amount.substring(0, amount.length - 2) + "." + amount.substring(amount.length - 2));
+    }
+}
 // 鍒ゆ柇寰俊銆佹敮浠樺疂  2寰俊 5鏀粯瀹� 3鍏朵粬
 export function getPlat() {
     // #ifdef H5
diff --git a/manifest.json b/manifest.json
index fd766fd..e243e55 100644
--- a/manifest.json
+++ b/manifest.json
@@ -1,5 +1,5 @@
 {
-    "name" : "浣版儬浠�",
+    "name" : "鍐�椹夸粯",
     "appid" : "__UNI__3E21AAD",
     "description" : "鍐�椹夸粯",
     "versionName" : "1.0.0",
@@ -71,6 +71,19 @@
             "base" : "/",
             "mode" : "history"
         },
+        "devServer" : {
+            "proxy" : {
+                "/dev-api" : {
+                    "target" : "http://172.16.2.117:8080",
+                    "changeOrigin" : true,
+                    "secure" : false,
+                    "pathRewrite" : {
+                        "^/dev-api" : ""
+                    }
+                }
+            },
+            "port" : ""
+        },
         "optimization" : {
             "treeShaking" : {
                 "enable" : true
diff --git a/pay/scanpay.vue b/pay/scanpay.vue
index c9162ca..4256502 100644
--- a/pay/scanpay.vue
+++ b/pay/scanpay.vue
@@ -60,10 +60,10 @@
             <view @click="showCoupon" class="u-flex">
               <block v-if="couponInfo.id">
                 <view v-if="couponInfo.discountType==1" class="tag-pain">
-                  婊{ parseFloat((couponInfo.thresholdValue / 100).toFixed(2)) }}鍏冨噺{{ parseFloat((couponInfo.discount / 100).toFixed(2)) }}鍏冨埜
+                  婊{ $utils.fenToYuan(couponInfo.thresholdValue) }}鍏冨噺{{ $utils.fenToYuan(couponInfo.discount) }}鍏冨埜
                 </view>
                 <view v-if="couponInfo.discountType==2" class="tag-pain">
-                  {{ parseFloat(couponInfo.discount * 10).toFixed(1) }}鎶樺埜
+                  {{ $utils.accMul(couponInfo.discount, 10) }}鎶樺埜
                 </view>
               </block>
 
@@ -108,14 +108,14 @@
               <view class="num-box">
                 <view v-if="item.discountType==1" class="font-bold" style="color: #D31F28;">
                   <text class="u-font-36">锟�</text>
-                  <text class="money">{{ parseFloat(item.discount / 100) }}</text>
+                  <text class="money">{{ $utils.fenToYuan(item.discount) }}</text>
                 </view>
                 <view v-if="item.discountType==2" class="font-bold" style="color: #D31F28;">
-                  <text class="money">{{ parseFloat(item.discount * 10).toFixed(1) }}</text>
+                  <text class="money">{{ $utils.accMul(item.discount, 10) }}</text>
                   <text class="u-font-36">鎶�</text>
                 </view>
-                <view v-if="item.orderMax" class="u-font-24 u-m-t-20">浣庝簬{{ parseFloat(item.orderMax / 100) }}鍏冨彲鐢�</view>
-                <view v-else-if="item.thresholdValue" class="u-font-24 u-m-t-20">婊{ parseFloat(item.thresholdValue / 100) }}鍏冨彲鐢�</view>
+                <view v-if="item.orderMax" class="u-font-24 u-m-t-20">浣庝簬{{ $utils.fenToYuan(item.orderMax) }}鍏冨彲鐢�</view>
+                <view v-else-if="item.thresholdValue" class="u-font-24 u-m-t-20">婊{ $utils.fenToYuan(item.thresholdValue) }}鍏冨彲鐢�</view>
                 <view v-else class="u-font-24 u-m-t-20">鏃犻棬妲�</view>
               </view>
               <view class="butt"></view>
@@ -165,7 +165,8 @@
   saveOrder,
 } from 'common/api/index'
 
-import wx from 'weixin-js-sdk'; // 浣跨敤js-sdk
+import wx from 'weixin-js-sdk';
+import {accMul, fenToYuan} from 'common/util' // 浣跨敤js-sdk
 
 export default {
   data() {
@@ -215,31 +216,31 @@
         return 0
       }
       if (this.checkCoupon.discountType == 1) {
-        const num = (this.checkCoupon.discount / 100).toFixed(2)
+        const num = this.$utils.fenToYuan(this.couponInfo.discount)
         return parseFloat(num);
       }
       const dis = 1 - parseFloat(this.checkCoupon.discount)
-      const dic = Math.floor(Number((this.money || 0) * 100) * dis)
-      return (dic / 100).toFixed(2);
+      const dic = Math.floor(this.$utils.accMul(this.money,100) * dis)
+      return this.$utils.fenToYuan(dic).toFixed(2);
     },
     discount() {
       if(!(this.money || 0)||!this.couponInfo.id){
         return 0
       }
       if (this.couponInfo.discountType == 1) {
-        const num = (this.couponInfo.discount / 100).toFixed(2)
+        const num = this.$utils.fenToYuan(this.couponInfo.discount)
         return parseFloat(num);
       }
       const dis = 1 - parseFloat(this.couponInfo.discount)
-      const dic = Math.floor(Number((this.money || 0) * 100) * dis)
-      return (dic / 100).toFixed(2);
+      const dic = Math.floor(this.$utils.accMul(this.money,100) * dis)
+      return this.$utils.fenToYuan(dic).toFixed(2);
     },
     payMoney() {
       if(this.discount===0||!Number(this.money || 0)){
         return 0
       }
-      const num = Number((this.money || 0) * 100) - Number(this.discount*100);
-      return (num / 100).toFixed(2);
+      const num = this.$utils.accMul(this.money,100) - this.$utils.accMul(this.discount,100);
+      return this.$utils.fenToYuan(num).toFixed(2);
     }
   },
   onLoad(opt) {
@@ -451,9 +452,10 @@
     queryUseSweepPayCoupon() {
       queryUseSweepPayCoupon({
         params: {
+          score: 0,
           applyPayWayStr: this.payWay,
           cusid: this.shopInfo.id,
-          money: (this.money * 100).toFixed(0),
+          money: this.$utils.accMul(this.money,100),
         }
       }).then(res => {
         this.couponList = res
@@ -489,7 +491,7 @@
       // 閲戦 this.money
       uni.showLoading()
       const params = {
-        money: (this.money * 100).toFixed(0),
+        money: this.$utils.accMul(this.money,100),
         shopId: this.shopInfo.id,
         payWay: this.payWay,
         buyerNote: this.buyerNote,

--
Gitblit v1.9.1