瀏覽代碼

fix 分账

release_toaliyun_real
lin 4 年之前
父節點
當前提交
f4424f051b
共有 7 個檔案被更改,包括 92 行新增15 行删除
  1. +10
    -6
      mallinkService/src/main/java/com/iformall/service/impl/WxPayOrderServiceImpl.java
  2. +25
    -6
      mallinkService/src/main/java/com/iformall/service/order/util/OrderHelper.java
  3. +6
    -0
      mallinkService/src/main/java/com/iformall/service/pay/service/share/PayShareAdapterService.java
  4. +9
    -0
      mallinkService/src/main/java/com/iformall/service/pay/service/share/douyin/TtPayShareService.java
  5. +27
    -0
      mallinkService/src/main/java/com/iformall/service/pay/service/share/entity/PayShareCalculateAmount.java
  6. +10
    -1
      mallinkService/src/main/java/com/iformall/service/pay/service/share/wx/WxPayShareService.java
  7. +5
    -2
      mallinkService/src/main/java/com/iformall/utils/PayUtils.java

+ 10
- 6
mallinkService/src/main/java/com/iformall/service/impl/WxPayOrderServiceImpl.java 查看文件

@@ -32,6 +32,8 @@ import com.iformall.service.pay.service.pay.PayAdapterService;
import com.iformall.service.pay.service.pay.entity.CreateUser; import com.iformall.service.pay.service.pay.entity.CreateUser;
import com.iformall.service.pay.service.pay.entity.PayAdapterResult; import com.iformall.service.pay.service.pay.entity.PayAdapterResult;
import com.iformall.service.pay.service.pay.entity.PayQueryAdapterResult; import com.iformall.service.pay.service.pay.entity.PayQueryAdapterResult;
import com.iformall.service.pay.service.share.PayShareAdapterService;
import com.iformall.service.pay.service.share.entity.PayShareCalculateAmount;
import com.iformall.service.pay.service.share.entity.ShareNotifyAdapterResult; import com.iformall.service.pay.service.share.entity.ShareNotifyAdapterResult;
import com.iformall.utils.*; import com.iformall.utils.*;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
@@ -390,20 +392,22 @@ public class WxPayOrderServiceImpl implements WxPayOrderService {
record.setShare(isShare.getCode()); record.setShare(isShare.getCode());
record.setComposeOrder(composeOrder.getComposeOrderType()); record.setComposeOrder(composeOrder.getComposeOrderType());
if (isShare == EnumPayShare.YES) { if (isShare == EnumPayShare.YES) {
PayShareAdapterService payShareServie = payServiceFactory.getPayShareAdapterService(payWay.getCode());
PayShareCalculateAmount recordShareAmount = payShareServie.calculateAmount(record.getPayAmount(), payAccount);
// 分账金额 // 分账金额
int mallCharge = OrderHelper.getMallCharge(record.getPayAmount(), payAccount);
Integer share_amount = record.getPayAmount() - mallCharge;
Integer share_amount = recordShareAmount.getShareAmount();
record.setShareAmount(share_amount); record.setShareAmount(share_amount);
record.setRateAmount(OrderHelper.getRateAmount(record.getPayAmount(),mallCharge, payAccount));
record.setRateAmount(recordShareAmount.getRateAmount());
//设置子订单分账金额 //设置子订单分账金额
Map<String,WxComposeChildOrderShare> childShares = new HashMap<String,WxComposeChildOrderShare>(); Map<String,WxComposeChildOrderShare> childShares = new HashMap<String,WxComposeChildOrderShare>();
OrderAdapterService orderAdapterService = orderFactory.getOrderAdapterService(composeOrder.getComposeOrderType()); OrderAdapterService orderAdapterService = orderFactory.getOrderAdapterService(composeOrder.getComposeOrderType());
List<WxOrder> orderList = orderAdapterService.getChildOrders(composeOrder, appInfo.getTenantId()); List<WxOrder> orderList = orderAdapterService.getChildOrders(composeOrder, appInfo.getTenantId());
if(null != orderList && orderList.size() > 0) { if(null != orderList && orderList.size() > 0) {
for (WxOrder o : orderList) { for (WxOrder o : orderList) {
int orderMallCharge = OrderHelper.getMallCharge(o.getPayment(), payAccount);
Integer orderShareAmount = o.getPayment() - orderMallCharge;
Integer orderRateAmount = OrderHelper.getRateAmount(o.getPayment(),orderMallCharge, payAccount);
PayShareCalculateAmount oShareAmount = payShareServie.calculateAmount(o.getPayment(), payAccount);
Integer orderShareAmount = oShareAmount.getShareAmount();
Integer orderRateAmount = oShareAmount.getRateAmount();
childShares.put(String.valueOf(o.getId()), new WxComposeChildOrderShare(o.getPayment(), orderShareAmount, orderRateAmount)); childShares.put(String.valueOf(o.getId()), new WxComposeChildOrderShare(o.getPayment(), orderShareAmount, orderRateAmount));
} }
record.setChildOrderShare(JSON.toJSONString(childShares)); record.setChildOrderShare(JSON.toJSONString(childShares));


+ 25
- 6
mallinkService/src/main/java/com/iformall/service/order/util/OrderHelper.java 查看文件

@@ -50,19 +50,38 @@ public class OrderHelper {
return orderStatus; return orderStatus;
} }
//分账金额,扣掉商场设置的手续费率
//分账金额,扣掉商场设置的手续费率,默认取最小整数,不四舍五入
public static int getMallCharge(Integer payment,WxPayAccount payAccount) { public static int getMallCharge(Integer payment,WxPayAccount payAccount) {
int iChargeFee = PayUtils.getPayRate(payment, payAccount.getRate(), false); int iChargeFee = PayUtils.getPayRate(payment, payAccount.getRate(), false);
return iChargeFee; return iChargeFee;
} }
//分账金额,扣掉商场设置的手续费率,是否四舍五入
public static int getMallCharge(Integer payment,WxPayAccount payAccount,boolean round) {
int iChargeFee = PayUtils.getPayRate(payment, payAccount.getRate(), round);
return iChargeFee;
}
//费率差,微信、支付宝交易的费率. iChargeFee:商场扣掉的手续费
public static Integer getRateAmount(Integer payment,int mallCharge, WxPayAccount payAccount) {
public static void main(String[] args) {
System.out.println(getMallCharge(null, null));
}
//微信、支付宝交易的手续费.
public static int getRealRateAmount(Integer payment,WxPayAccount payAccount) {
if(payAccount.getRealRate() != null) { if(payAccount.getRealRate() != null) {
int iRealChargeFee = PayUtils.getPayRate(payment, payAccount.getRealRate(), true); int iRealChargeFee = PayUtils.getPayRate(payment, payAccount.getRealRate(), true);
if(mallCharge > iRealChargeFee) {
return mallCharge - iRealChargeFee;
}
return iRealChargeFee;
}
return -1;
}
//费率差. iChargeFee:商场扣掉的手续费
public static Integer getRateAmount(Integer payment,int mallCharge, WxPayAccount payAccount) {
int iRealChargeFee = getRealRateAmount(payment, payAccount);
if (iRealChargeFee < 0) {
return null;
}
if(mallCharge > iRealChargeFee) {
return mallCharge - iRealChargeFee;
} }
return null; return null;
} }


+ 6
- 0
mallinkService/src/main/java/com/iformall/service/pay/service/share/PayShareAdapterService.java 查看文件

@@ -12,6 +12,7 @@ import com.iformall.enums.EnumProfitSharingOrderType;
import com.iformall.enums.EnumProfitSharingReceiverType; import com.iformall.enums.EnumProfitSharingReceiverType;
import com.iformall.exception.MallinkException; import com.iformall.exception.MallinkException;
import com.iformall.service.pay.service.share.entity.ShareAccountResult; import com.iformall.service.pay.service.share.entity.ShareAccountResult;
import com.iformall.service.pay.service.share.entity.PayShareCalculateAmount;
import com.iformall.service.pay.service.share.entity.PayShareQueryResult; import com.iformall.service.pay.service.share.entity.PayShareQueryResult;
import com.iformall.service.pay.service.share.entity.PayShareResult; import com.iformall.service.pay.service.share.entity.PayShareResult;
import com.iformall.service.pay.service.share.entity.ShareNotifyAdapterResult; import com.iformall.service.pay.service.share.entity.ShareNotifyAdapterResult;
@@ -34,6 +35,11 @@ public interface PayShareAdapterService {
*/ */
public Integer getProfitSharingType(); public Integer getProfitSharingType();
/**
* 计算商场分账金额和实际费率金额
*/
public PayShareCalculateAmount calculateAmount(Integer payAmount,WxPayAccount payAccount);
/** /**
* 无分账接收方分账 ,钱直接分给小程序方 调用API分账 * 无分账接收方分账 ,钱直接分给小程序方 调用API分账
* @param appInfo * @param appInfo


+ 9
- 0
mallinkService/src/main/java/com/iformall/service/pay/service/share/douyin/TtPayShareService.java 查看文件

@@ -11,7 +11,9 @@ import com.iformall.douyin.pay.preOrder.Settle;
import com.iformall.douyin.pay.preOrder.SettleResult; import com.iformall.douyin.pay.preOrder.SettleResult;
import com.iformall.enums.*; import com.iformall.enums.*;
import com.iformall.exception.MallinkException; import com.iformall.exception.MallinkException;
import com.iformall.service.order.util.OrderHelper;
import com.iformall.service.pay.service.share.PayShareBaseAdapterService; import com.iformall.service.pay.service.share.PayShareBaseAdapterService;
import com.iformall.service.pay.service.share.entity.PayShareCalculateAmount;
import com.iformall.service.pay.service.share.entity.PayShareQueryResult; import com.iformall.service.pay.service.share.entity.PayShareQueryResult;
import com.iformall.service.pay.service.share.entity.PayShareResult; import com.iformall.service.pay.service.share.entity.PayShareResult;
import com.iformall.service.pay.service.share.entity.ShareAccountResult; import com.iformall.service.pay.service.share.entity.ShareAccountResult;
@@ -37,6 +39,13 @@ public class TtPayShareService extends PayShareBaseAdapterService{
public Integer getProfitSharingType() { public Integer getProfitSharingType() {
return EnumProfitSharingType.PROFIT_SHARING_TYPE_DOUYIN.getCode(); return EnumProfitSharingType.PROFIT_SHARING_TYPE_DOUYIN.getCode();
} }
@Override
public PayShareCalculateAmount calculateAmount(Integer payAmount, WxPayAccount payAccount) {
int mallCharge = OrderHelper.getMallCharge(payAmount, payAccount,true);
Integer realRateAmount = OrderHelper.getRealRateAmount(payAmount, payAccount);
return new PayShareCalculateAmount(payAmount,mallCharge,realRateAmount);
}


@Override @Override
public PayShareResult noReciverShare(WxAppinfo appInfo,WxPayAccount payAccount,WxProfitSharingOrder record,String transcationId,Integer amount) { public PayShareResult noReciverShare(WxAppinfo appInfo,WxPayAccount payAccount,WxProfitSharingOrder record,String transcationId,Integer amount) {


+ 27
- 0
mallinkService/src/main/java/com/iformall/service/pay/service/share/entity/PayShareCalculateAmount.java 查看文件

@@ -0,0 +1,27 @@
package com.iformall.service.pay.service.share.entity;

import java.io.Serializable;

import lombok.AllArgsConstructor;
import lombok.Data;

@Data
@AllArgsConstructor
public class PayShareCalculateAmount implements Serializable{

private static final long serialVersionUID = -3701322871877301001L;

private Integer payAmount;
private Integer mallCharge;//商场拿走的钱
private Integer realRateAmount;//平台手续费
//分账的钱
public Integer getShareAmount() {
return payAmount - mallCharge;
}
//费率差
public Integer getRateAmount() {
return mallCharge - realRateAmount;
}
}

+ 10
- 1
mallinkService/src/main/java/com/iformall/service/pay/service/share/wx/WxPayShareService.java 查看文件

@@ -39,9 +39,11 @@ import com.iformall.pay.WxProfitSharingFinishP;
import com.iformall.pay.WxProfitSharingP; import com.iformall.pay.WxProfitSharingP;
import com.iformall.pay.WxProfitSharingQueryP; import com.iformall.pay.WxProfitSharingQueryP;
import com.iformall.pay.WxProfitSharingReceiverP; import com.iformall.pay.WxProfitSharingReceiverP;
import com.iformall.service.order.util.OrderHelper;
import com.iformall.service.pay.service.share.PayShareAdapterService; import com.iformall.service.pay.service.share.PayShareAdapterService;
import com.iformall.service.pay.service.share.PayShareBaseAdapterService; import com.iformall.service.pay.service.share.PayShareBaseAdapterService;
import com.iformall.service.pay.service.share.entity.ShareAccountResult; import com.iformall.service.pay.service.share.entity.ShareAccountResult;
import com.iformall.service.pay.service.share.entity.PayShareCalculateAmount;
import com.iformall.service.pay.service.share.entity.PayShareQueryResult; import com.iformall.service.pay.service.share.entity.PayShareQueryResult;
import com.iformall.service.pay.service.share.entity.PayShareResult; import com.iformall.service.pay.service.share.entity.PayShareResult;
import com.iformall.service.pay.service.share.entity.ShareNotifyAdapterResult; import com.iformall.service.pay.service.share.entity.ShareNotifyAdapterResult;
@@ -71,6 +73,13 @@ public class WxPayShareService extends PayShareBaseAdapterService{
public Integer getProfitSharingType() { public Integer getProfitSharingType() {
return EnumProfitSharingType.PROFIT_SHARING_TYPE_WECHAT.getCode(); return EnumProfitSharingType.PROFIT_SHARING_TYPE_WECHAT.getCode();
} }
@Override
public PayShareCalculateAmount calculateAmount(Integer payAmount, WxPayAccount payAccount) {
int mallCharge = OrderHelper.getMallCharge(payAmount, payAccount);
Integer realRateAmount = OrderHelper.getRealRateAmount(payAmount, payAccount);
return new PayShareCalculateAmount(payAmount,mallCharge,realRateAmount);
}


@Override @Override
public PayShareResult noReciverShare(WxAppinfo appInfo,WxPayAccount payAccount,WxProfitSharingOrder record,String transcationId,Integer amount) { public PayShareResult noReciverShare(WxAppinfo appInfo,WxPayAccount payAccount,WxProfitSharingOrder record,String transcationId,Integer amount) {
@@ -444,7 +453,7 @@ public class WxPayShareService extends PayShareBaseAdapterService{
} }
return null; return null;
} }
// public static void main(String[] args) { // public static void main(String[] args) {
// System.out.println(queryOrderShareAmount("1511925291","4200001516202205010431149938","XHZfpVA0NzoXgLEjsujctUTcyj8Zur2C")); // System.out.println(queryOrderShareAmount("1511925291","4200001516202205010431149938","XHZfpVA0NzoXgLEjsujctUTcyj8Zur2C"));
// //System.out.println(test("1511925291", "1604439800", "wxed2f44705544b892", "4200001455202205127949391954", "XHZfpVA0NzoXgLEjsujctUTcyj8Zur2C", "684670745960046592", "D:\\apiclient_cert.p12")); // //System.out.println(test("1511925291", "1604439800", "wxed2f44705544b892", "4200001455202205127949391954", "XHZfpVA0NzoXgLEjsujctUTcyj8Zur2C", "684670745960046592", "D:\\apiclient_cert.p12"));


+ 5
- 2
mallinkService/src/main/java/com/iformall/utils/PayUtils.java 查看文件

@@ -23,8 +23,7 @@ public class PayUtils {
Double dPayRate = 1.0D * payAmount * rate / 10000; Double dPayRate = 1.0D * payAmount * rate / 10000;
long dChargeFee = Math.round(dPayRate); long dChargeFee = Math.round(dPayRate);
return Long.valueOf(dChargeFee).intValue(); return Long.valueOf(dChargeFee).intValue();
}
else if(payAmount > dBaseAmount.intValue()) {
}else if(payAmount > dBaseAmount.intValue()) {
// 大于基础分,不小于他的最小整数 // 大于基础分,不小于他的最小整数
Double dChargeFee = Math.ceil(payAmount * 1.0D * rate / 10000); Double dChargeFee = Math.ceil(payAmount * 1.0D * rate / 10000);
return dChargeFee.intValue(); return dChargeFee.intValue();
@@ -35,6 +34,10 @@ public class PayUtils {
return Long.valueOf(dChargeFee).intValue(); return Long.valueOf(dChargeFee).intValue();
} }
} }
public static void main(String[] args) {
System.out.println(getPayRate(990, 7001, true));
}


/* /*
public static void main(String[] args) { public static void main(String[] args) {


Loading…
取消
儲存