石广澎
2024-10-10 db03391c6bde1f7b1a93164930799fc434c0f9f2
feat(支付): 数学计算工具
3个文件已修改
112 ■■■■ 已修改文件
common/util.js 61 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
manifest.json 15 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pay/scanpay.vue 36 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
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
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
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,