Browse Source

修改需求

zhs 3 years ago
parent
commit
db70cdd2b7

+ 6 - 5
src/main/java/com/travel/controller/ZfbPayController.java

@@ -9,6 +9,7 @@ import com.travel.model.SupplierRelease;
 import com.travel.model.ZFBPay;
 import com.travel.service.IndexService;
 import com.travel.service.ZFBPayService;
+import com.travel.util.AmountUtil;
 import com.travel.util.ParsingToken;
 import com.travel.util.SnowflakeUtil;
 import com.travel.zfb.ZfbPayUtils;
@@ -22,6 +23,7 @@ import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import java.io.IOException;
 import java.io.PrintWriter;
+import java.math.BigDecimal;
 import java.text.SimpleDateFormat;
 import java.util.*;
 
@@ -281,14 +283,13 @@ public class ZfbPayController extends ZfbPayUtils {
                                 supplierRelease2.setOrderType("2");
                                 zfbPayService.updatePrivateType(supplierRelease2);
                                 Map<String, Object> mapCommis = indexService.getSitesInfo();//查询系统配置
-                                //手续费
-                                Double poundage = Double.parseDouble(wxPay.getTotalFee()) * Double.parseDouble((String) mapCommis.get("percentageFee"));
+                                String amount = AmountUtil.moneyMul(wxPay.getTotalFee(), (String) mapCommis.get("percentageFee"));//手续费
                                 //实际金额 - 手续费 = 供应商收入
-                                poundage = Double.parseDouble(wxPay.getTotalFee()) - poundage;
-                                //用户购买报价单后将50%的资金转入供应商余额
+                                String poundage = AmountUtil.moneySub(wxPay.getTotalFee(), amount);
+                                //用户购买报价单后将供应商收入存入供应商余额
                                 Supplier supplier = new Supplier()
                                         .setCode(list.get(0).getCode())
-                                        .setBalanceOf(String.valueOf(poundage));
+                                        .setBalanceOf(poundage);
                                 zfbPayService.addSupplierBalanceOf(supplier);
                             } else {
                                 supplierRelease2.setOrderType("9");

+ 2 - 0
src/main/java/com/travel/mapper/ZFBPayMapper.java

@@ -46,4 +46,6 @@ public interface ZFBPayMapper {
     void minusBalanceOf(WxWithdrawal wxWithdrawal);
 
     void addSupplierBalanceOf(Supplier supplier);
+
+    void subtractBalance(@Param("bigDecimal2")String bigDecimal2, @Param("code")String code);
 }

+ 4 - 0
src/main/java/com/travel/service/impl/ZFBPayServiceImpl.java

@@ -9,6 +9,7 @@ import com.alipay.api.response.AlipayTradeRefundResponse;
 import com.travel.mapper.ZFBPayMapper;
 import com.travel.model.*;
 import com.travel.service.ZFBPayService;
+import com.travel.util.AmountUtil;
 import com.travel.util.DesDecry;
 import com.travel.zfb.ZfbPayUtils;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -16,6 +17,7 @@ import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.util.ClassUtils;
 
+import java.math.BigDecimal;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -118,6 +120,8 @@ public class ZFBPayServiceImpl extends ZfbPayUtils implements ZFBPayService {
                 }
                 Map<String, Object> map1 = refund(refund.getRefundFee(), wxPay);
                 if(map1.get("msg").equals("200")){
+                    String bigDecimal2 = AmountUtil.moneySub(wxPay.getBalanceOf(), refund.getRefundFee());//退款后的账户余额
+                    zfbPayMapper.subtractBalance(bigDecimal2, wxPay.getCode());//供应商余额变更
                     zfbPayMapper.updateRefundType(zfbRefund.getReleaseUuid(), zfbRefund.getRefundState());
                     return map1;
                 } else {

+ 214 - 0
src/main/java/com/travel/util/AmountUtil.java

@@ -0,0 +1,214 @@
+package com.travel.util;
+
+import java.math.BigDecimal;
+import java.text.DecimalFormat;
+
+public class AmountUtil {
+    public static DecimalFormat fnum = new DecimalFormat("#.00");
+
+    /**
+     * 格式化金额
+     *
+     * @param valueStr
+     * @return String
+     */
+    public static String formatMoney(String valueStr) {
+        if (valueStr == null || valueStr == "") {
+            valueStr = "0.00";
+        }
+        return fnum.format(new BigDecimal(valueStr));
+    }
+
+
+    /**
+     * 金额相加
+     *
+     * @param valueStr 基础值
+     * @param addStr   被加数
+     * @return String
+     */
+    public static String moneyAdd(String valueStr, String addStr) {
+        BigDecimal value = new BigDecimal(valueStr);
+        BigDecimal augend = new BigDecimal(addStr);
+        return fnum.format(value.add(augend));
+    }
+
+    /**
+     * 金额相加
+     *
+     * @param valueStr      基础值
+     * @param minusValueStr 被加数
+     * @return BigDecimal
+     */
+    public static BigDecimal moneyAdd(BigDecimal valueStr, BigDecimal minusValueStr) {
+        return valueStr.add(minusValueStr);
+    }
+
+    /**
+     * 金额相减
+     *
+     * @param valueStr      基础值
+     * @param minusValueStr 减数
+     * @return String
+     */
+    public static String moneySub(String valueStr, String minusValueStr) {
+        BigDecimal value = new BigDecimal(valueStr);
+        BigDecimal subtrahend = new BigDecimal(minusValueStr);
+        return fnum.format(value.subtract(subtrahend));
+    }
+
+    /**
+     * 金额相减
+     *
+     * @param value      基础值
+     * @param subtrahend 减数
+     * @return BigDecimal
+     */
+    public static BigDecimal moneySub(BigDecimal value, BigDecimal subtrahend) {
+        return value.subtract(subtrahend);
+    }
+
+
+    /**
+     * 金额相乘
+     *
+     * @param valueStr      基础值
+     * @param minusValueStr 被乘数
+     * @return String
+     */
+    public static String moneyMul(String valueStr, String minusValueStr) {
+        BigDecimal value = new BigDecimal(valueStr);
+        BigDecimal mulValue = new BigDecimal(minusValueStr);
+        return fnum.format(value.multiply(mulValue));
+    }
+
+    /**
+     * 金额相乘
+     *
+     * @param value    基础值
+     * @param mulValue 被乘数
+     * @return BigDecimal
+     */
+    public static BigDecimal moneyMul(BigDecimal value, BigDecimal mulValue) {
+        return value.multiply(mulValue);
+    }
+
+    /**
+     * 金额相除 <br/>
+     * 精确小位小数
+     *
+     * @param valueStr      基础值
+     * @param minusValueStr 被乘数
+     * @return String
+     */
+    public static String moneydiv(String valueStr, String minusValueStr) {
+        BigDecimal value = new BigDecimal(valueStr);
+        BigDecimal divideValue = new BigDecimal(minusValueStr);
+        return fnum.format(value.divide(divideValue, 2, BigDecimal.ROUND_HALF_UP));
+    }
+
+    /**
+     * 金额相除 <br/>
+     * 精确小位小数
+     *
+     * @param value       基础值
+     * @param divideValue 被乘数
+     * @return BigDecimal
+     */
+    public static BigDecimal moneydiv(BigDecimal value, BigDecimal divideValue) {
+        return value.divide(divideValue, 2, BigDecimal.ROUND_HALF_UP);
+    }
+
+
+    /**
+     * 值比较大小
+     * <br/>如果valueStr大于等于compValueStr,则返回true,否则返回false
+     * true 代表可用余额不足
+     *
+     * @param valueStr     (需要消费金额)
+     * @param compValueStr (可使用金额)
+     * @return boolean
+     */
+    public static boolean moneyComp(String valueStr, String compValueStr) {
+        BigDecimal value = new BigDecimal(valueStr);
+        BigDecimal compValue = new BigDecimal(compValueStr);
+        //0:等于    >0:大于    <0:小于
+        int result = value.compareTo(compValue);
+        if (result >= 0) {
+            return true;
+        } else {
+            return false;
+        }
+    }
+
+    /**
+     * 值比较大小
+     * <br/>如果valueStr大于等于compValueStr,则返回true,否则返回false
+     * true 代表可用余额不足
+     *
+     * @param valueStr     (需要消费金额)
+     * @param compValueStr (可使用金额)
+     * @return boolean
+     */
+    public static boolean moneyComp(BigDecimal valueStr, BigDecimal compValueStr) {
+        //0:等于    >0:大于    <0:小于
+        int result = valueStr.compareTo(compValueStr);
+        if (result >= 0) {
+            return true;
+        } else {
+            return false;
+        }
+    }
+
+    /**
+     * 金额乘以,省去小数点
+     *
+     * @param valueStr 基础值
+     * @return String
+     */
+    public static String moneyMulOfNotPoint(String valueStr, String divideStr) {
+        BigDecimal value = new BigDecimal(valueStr);
+        BigDecimal mulValue = new BigDecimal(divideStr);
+        valueStr = fnum.format(value.multiply(mulValue));
+        return fnum.format(value.multiply(mulValue)).substring(0, valueStr.length() - 3);
+    }
+
+    /**
+     * 给金额加逗号切割
+     *
+     * @param str
+     * @return String
+     */
+    public static String addComma(String str) {
+        try {
+            String banNum = "";
+            if (str.contains(".")) {
+                String[] arr = str.split("\\.");
+                if (arr.length == 2) {
+                    str = arr[0];
+                    banNum = "." + arr[1];
+                }
+            }
+            // 将传进数字反转
+            String reverseStr = new StringBuilder(str).reverse().toString();
+            String strTemp = "";
+            for (int i = 0; i < reverseStr.length(); i++) {
+                if (i * 3 + 3 > reverseStr.length()) {
+                    strTemp += reverseStr.substring(i * 3, reverseStr.length());
+                    break;
+                }
+                strTemp += reverseStr.substring(i * 3, i * 3 + 3) + ",";
+            }
+            // 将[789,456,] 中最后一个[,]去除
+            if (strTemp.endsWith(",")) {
+                strTemp = strTemp.substring(0, strTemp.length() - 1);
+            }
+            // 将数字重新反转
+            String resultStr = new StringBuilder(strTemp).reverse().toString();
+            resultStr += banNum;
+            return resultStr;
+        } catch (Exception e) {
+            return str;
+        }
+    }
+}

+ 11 - 3
src/main/resources/config/mapping/ZFBPayMapper.xml

@@ -75,11 +75,12 @@
     <select id="getRefundVal" resultType="ZFBPay" parameterType="String">
         SELECT
             a.*,
-            c.balance_of
+            c.balance_of,
+            c.code
         FROM
             bus_pay a
-                LEFT JOIN bus_supplier_release b ON a.release_uuid = b.uuid
-                LEFT JOIN sys_supplier c ON b.code = c.code
+            LEFT JOIN bus_supplier_release b ON a.release_uuid = b.uuid
+            LEFT JOIN sys_supplier c ON b.code = c.code
         WHERE
             a.release_uuid = #{releUuid}
     </select>
@@ -123,4 +124,11 @@
         WHERE
             code = #{code}
     </update>
+    <!-- 供应商退款后账户余额变更 -->
+    <update id="subtractBalance" parameterType="Supplier">
+        UPDATE sys_supplier
+        SET balance_of = #{bigDecimal2}
+        WHERE
+            code = #{code}
+    </update>
 </mapper>