diff --git a/mallinkCallback/src/main/java/com/iformall/utils/PayUtil.java b/mallinkCallback/src/main/java/com/iformall/utils/PayUtil.java deleted file mode 100644 index 9776aad04..000000000 --- a/mallinkCallback/src/main/java/com/iformall/utils/PayUtil.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.iformall.utils; - -import com.google.zxing.BarcodeFormat; -import com.google.zxing.EncodeHintType; -import com.google.zxing.MultiFormatWriter; -import com.google.zxing.WriterException; -import com.google.zxing.common.BitMatrix; -import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel; - -import java.awt.image.BufferedImage; -import java.util.Hashtable; -import java.util.Map; - -public class PayUtil { - /** - * 根据url生成二位图片对象 - * - * @param codeUrl - * @return - * @throws WriterException - */ - public static BufferedImage getQRCodeImge(String codeUrl) throws WriterException { - Map hints = new Hashtable(); - hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.M); - hints.put(EncodeHintType.CHARACTER_SET, "UTF8"); - int width = 256; - BitMatrix bitMatrix = (new MultiFormatWriter()).encode(codeUrl, BarcodeFormat.QR_CODE, width, width, hints); - BufferedImage image = new BufferedImage(width, width, 1); - for(int x = 0; x < width; ++x) { - for(int y = 0; y < width; ++y) { - image.setRGB(x, y, bitMatrix.get(x, y) ? -16777216 : -1); - } - } - - return image; - } -} diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxCardSpendServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxCardSpendServiceImpl.java index 4f2f3c97d..9ecf6408b 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxCardSpendServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxCardSpendServiceImpl.java @@ -13,6 +13,7 @@ import com.iformall.enums.*; import com.iformall.exception.MallinkException; import com.iformall.mapper.*; import com.iformall.service.*; +import com.iformall.utils.PayUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -123,8 +124,8 @@ public class WxCardSpendServiceImpl implements WxCardSpendService { // 4. 扣减计算 Double paymentD = 1.0 * cardInfo.getSaleAmount() * record.getDeductionAmount() / cardInfo.getAmount(); Integer payment = paymentD.intValue(); - Double dChargeFee = Math.ceil(payment * 1.0D * payAccount.getRate() / 10000); - Integer real_payment = payment - dChargeFee.intValue(); + int iChargeFee = PayUtils.getPayRate(payment, payAccount.getRate()); + Integer real_payment = payment - iChargeFee; Integer remain_real_pament = cardInfo.getRemainingShareFeeAmount() - real_payment; Integer remaingAmount = cardInfo.getRemainingAmount()-record.getDeductionAmount(); @@ -189,8 +190,8 @@ public class WxCardSpendServiceImpl implements WxCardSpendService { logger.info("补贴额: " + subsidyFee); if(subsidyFee > 0) { // 有补贴时入库 - Double dSubChargeFee = Math.ceil(subsidyFee * 1.0D * payAccount.getRate() / 10000); - Integer realSubsidyFee = subsidyFee - dSubChargeFee.intValue(); + int iSubChargeFee = PayUtils.getPayRate(subsidyFee, payAccount.getRate()); + Integer realSubsidyFee = subsidyFee - iSubChargeFee; WxMerchantSubsidy merchantSubsidy = new WxMerchantSubsidy(); merchantSubsidy.setId(idWorker.nextId()); merchantSubsidy.setTenantId(record.getTenantId()); diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxCouponOrderServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxCouponOrderServiceImpl.java index e436598b6..eb7ff53f8 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxCouponOrderServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxCouponOrderServiceImpl.java @@ -21,6 +21,7 @@ import com.iformall.mapper.*; import com.iformall.mq.MqBaseProducer; import com.iformall.service.*; import com.iformall.utils.DateUtils; +import com.iformall.utils.PayUtils; import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -480,11 +481,11 @@ public class WxCouponOrderServiceImpl implements WxCouponOrderService { } if (subsidyNum != null && subsidyNum.intValue() > 0) { // 有补贴时入库 - Double dSubChargeFee = Math.ceil(subsidyNum * 1.0D * payAccount.getRate() / 10000); - Integer realSubsidyFee = subsidyNum - dSubChargeFee.intValue(); + int iSubChargeFee = PayUtils.getPayRate(subsidyNum, payAccount.getRate()); + Integer realSubsidyFee = subsidyNum - iSubChargeFee; - Double priceChargeFee = Math.ceil(coupon.getSalePrice() * 1.0D * payAccount.getRate() / 10000); - Integer realPayment = coupon.getSalePrice() - priceChargeFee.intValue(); + int iPriceChargeFee = PayUtils.getPayRate(coupon.getSalePrice(), payAccount.getRate()); + Integer realPayment = coupon.getSalePrice() - iPriceChargeFee; WxMerchantSubsidy merchantSubsidy = new WxMerchantSubsidy(); merchantSubsidy.setId(idWorker.nextId()); diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxPayOrderServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxPayOrderServiceImpl.java index 2a5b16477..a1a2fc734 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxPayOrderServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxPayOrderServiceImpl.java @@ -14,10 +14,7 @@ import com.iformall.exception.MallinkException; import com.iformall.mapper.*; import com.iformall.pay.*; import com.iformall.service.*; -import com.iformall.utils.BeanUtils; -import com.iformall.utils.MapUtil; -import com.iformall.utils.Utility; -import com.iformall.utils.XmlUtil; +import com.iformall.utils.*; import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -219,8 +216,8 @@ public class WxPayOrderServiceImpl implements WxPayOrderService { record.setShare(isShare.getCode()); if (isShare == EnumPayShare.YES) { // 分账金额 - Double dChargeFee = Math.ceil(record.getPayAmount() * 1.0D * payAccount.getRate() / 10000); - Integer share_amount = record.getPayAmount() - dChargeFee.intValue(); + int iChargeFee = PayUtils.getPayRate(record.getPayAmount(), payAccount.getRate()); + Integer share_amount = record.getPayAmount() - iChargeFee; record.setShareAmount(share_amount); } @@ -458,8 +455,8 @@ public class WxPayOrderServiceImpl implements WxPayOrderService { record.setShare(isShare.getCode()); if (isShare == EnumPayShare.YES) { // 分账金额 - Double dChargeFee = Math.ceil(record.getPayAmount() * 1.0D * payAccount.getRate() / 10000); - Integer share_amount = record.getPayAmount() - dChargeFee.intValue(); + int iChargeFee = PayUtils.getPayRate(record.getPayAmount(), payAccount.getRate()); + Integer share_amount = record.getPayAmount() - iChargeFee; record.setShareAmount(share_amount); if (share_amount <= 0) { isShare = EnumPayShare.NO; @@ -1532,12 +1529,4 @@ public class WxPayOrderServiceImpl implements WxPayOrderService { public void deleteById(Long id) { wxPayOrderMapper.deleteByPrimaryKey(id); } - - public static void main(String[] args) { - Integer v = 50; - Integer rate = 6; - Double dChargeFee = Math.ceil(v * 1.0D * 60 / 10000); - Integer share_amount = v - dChargeFee.intValue(); - System.out.println("share value " + share_amount); - } } diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxSubsidyServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxSubsidyServiceImpl.java index eb9358d6f..1ec3a1d08 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxSubsidyServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxSubsidyServiceImpl.java @@ -21,6 +21,7 @@ import com.iformall.pay.WxPayment; import com.iformall.service.WxAppinfoService; import com.iformall.service.WxSubsidyService; import com.iformall.utils.BeanUtils; +import com.iformall.utils.PayUtils; import com.iformall.utils.Utility; import com.iformall.utils.XmlUtil; import org.apache.commons.lang3.StringUtils; @@ -113,8 +114,8 @@ public class WxSubsidyServiceImpl implements WxSubsidyService { record.setPayTimeEnd(curDate); record.setAmount(totalFee); // 分账金额 - Double dChargeFee = Math.ceil(record.getAmount() * 1.0D * payAccount.getRate() / 10000); - Integer share_amount = record.getAmount() - dChargeFee.intValue(); + int iChargeFee = PayUtils.getPayRate(record.getAmount(), payAccount.getRate()); + Integer share_amount = record.getAmount() - iChargeFee; record.setShareAmount(share_amount); record.setShareRemainAmount(share_amount); try { diff --git a/mallinkService/src/main/java/com/iformall/utils/PayUtils.java b/mallinkService/src/main/java/com/iformall/utils/PayUtils.java new file mode 100755 index 000000000..d7ea670ba --- /dev/null +++ b/mallinkService/src/main/java/com/iformall/utils/PayUtils.java @@ -0,0 +1,50 @@ +package com.iformall.utils; + +/** + * 分账手续费 + * + * @author stormeye.wu + * @email wuguoqiang@iformall.com + * @date 2019年1月5月 + */ +public class PayUtils { + + /** + * getPayRate + * @param payAmount 支付总钱数(分) + * @param rate 万分之几 + * @return + */ + public static int getPayRate(int payAmount, int rate) { + Double dBaseAmount = 5.0D * 1000 / rate; + // 基础分 千分之6 83分 + if(payAmount > dBaseAmount.intValue()) { + // 大于基础分,不小于他的最小整数 + Double dChargeFee = Math.ceil(payAmount * 1.0D * rate / 10000); + return dChargeFee.intValue(); + } else { + // 小于基础分,四舍五入 + Double dPayRate = 1.0D * payAmount * rate / 10000; + long dChargeFee = Math.round(dPayRate); + return Long.valueOf(dChargeFee).intValue(); + } + } + + public static void main(String[] args) { + int iValue = getPayRate(100, 60); + System.out.println(iValue); + + iValue = getPayRate(200, 60); + System.out.println(iValue); + + iValue = getPayRate(82, 60); + System.out.println(iValue); + + iValue = getPayRate(83, 60); + System.out.println(iValue); + + iValue = getPayRate(84, 60); + System.out.println(iValue); + } + +} diff --git a/mallinkSysAdmin/src/main/java/com/iformall/utils/PayUtil.java b/mallinkSysAdmin/src/main/java/com/iformall/utils/PayUtil.java deleted file mode 100644 index 9776aad04..000000000 --- a/mallinkSysAdmin/src/main/java/com/iformall/utils/PayUtil.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.iformall.utils; - -import com.google.zxing.BarcodeFormat; -import com.google.zxing.EncodeHintType; -import com.google.zxing.MultiFormatWriter; -import com.google.zxing.WriterException; -import com.google.zxing.common.BitMatrix; -import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel; - -import java.awt.image.BufferedImage; -import java.util.Hashtable; -import java.util.Map; - -public class PayUtil { - /** - * 根据url生成二位图片对象 - * - * @param codeUrl - * @return - * @throws WriterException - */ - public static BufferedImage getQRCodeImge(String codeUrl) throws WriterException { - Map hints = new Hashtable(); - hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.M); - hints.put(EncodeHintType.CHARACTER_SET, "UTF8"); - int width = 256; - BitMatrix bitMatrix = (new MultiFormatWriter()).encode(codeUrl, BarcodeFormat.QR_CODE, width, width, hints); - BufferedImage image = new BufferedImage(width, width, 1); - for(int x = 0; x < width; ++x) { - for(int y = 0; y < width; ++y) { - image.setRGB(x, y, bitMatrix.get(x, y) ? -16777216 : -1); - } - } - - return image; - } -}