Browse Source

[支付][修改]:通道费计算算法修改,千分之6时,小于83分,四舍五入, 大于83分, 不小于它的最小整数

release_toaliyun_real
Stormeye Wu 7 years ago
parent
commit
55510fd7d3
7 changed files with 68 additions and 100 deletions
  1. +0
    -37
      mallinkCallback/src/main/java/com/iformall/utils/PayUtil.java
  2. +5
    -4
      mallinkService/src/main/java/com/iformall/service/impl/WxCardSpendServiceImpl.java
  3. +5
    -4
      mallinkService/src/main/java/com/iformall/service/impl/WxCouponOrderServiceImpl.java
  4. +5
    -16
      mallinkService/src/main/java/com/iformall/service/impl/WxPayOrderServiceImpl.java
  5. +3
    -2
      mallinkService/src/main/java/com/iformall/service/impl/WxSubsidyServiceImpl.java
  6. +50
    -0
      mallinkService/src/main/java/com/iformall/utils/PayUtils.java
  7. +0
    -37
      mallinkSysAdmin/src/main/java/com/iformall/utils/PayUtil.java

+ 0
- 37
mallinkCallback/src/main/java/com/iformall/utils/PayUtil.java View File

@@ -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<EncodeHintType, Object> 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;
}
}

+ 5
- 4
mallinkService/src/main/java/com/iformall/service/impl/WxCardSpendServiceImpl.java View File

@@ -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());


+ 5
- 4
mallinkService/src/main/java/com/iformall/service/impl/WxCouponOrderServiceImpl.java View File

@@ -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());


+ 5
- 16
mallinkService/src/main/java/com/iformall/service/impl/WxPayOrderServiceImpl.java View File

@@ -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);
}
}

+ 3
- 2
mallinkService/src/main/java/com/iformall/service/impl/WxSubsidyServiceImpl.java View File

@@ -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 {


+ 50
- 0
mallinkService/src/main/java/com/iformall/utils/PayUtils.java View File

@@ -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);
}

}

+ 0
- 37
mallinkSysAdmin/src/main/java/com/iformall/utils/PayUtil.java View File

@@ -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<EncodeHintType, Object> 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;
}
}

Loading…
Cancel
Save