| @@ -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.PayAdapterResult; | |||
| 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.utils.*; | |||
| import org.apache.commons.lang3.StringUtils; | |||
| @@ -390,20 +392,22 @@ public class WxPayOrderServiceImpl implements WxPayOrderService { | |||
| record.setShare(isShare.getCode()); | |||
| record.setComposeOrder(composeOrder.getComposeOrderType()); | |||
| 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.setRateAmount(OrderHelper.getRateAmount(record.getPayAmount(),mallCharge, payAccount)); | |||
| record.setRateAmount(recordShareAmount.getRateAmount()); | |||
| //设置子订单分账金额 | |||
| Map<String,WxComposeChildOrderShare> childShares = new HashMap<String,WxComposeChildOrderShare>(); | |||
| OrderAdapterService orderAdapterService = orderFactory.getOrderAdapterService(composeOrder.getComposeOrderType()); | |||
| List<WxOrder> orderList = orderAdapterService.getChildOrders(composeOrder, appInfo.getTenantId()); | |||
| if(null != orderList && orderList.size() > 0) { | |||
| 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)); | |||
| } | |||
| record.setChildOrderShare(JSON.toJSONString(childShares)); | |||
| @@ -50,19 +50,38 @@ public class OrderHelper { | |||
| return orderStatus; | |||
| } | |||
| //分账金额,扣掉商场设置的手续费率 | |||
| //分账金额,扣掉商场设置的手续费率,默认取最小整数,不四舍五入 | |||
| public static int getMallCharge(Integer payment,WxPayAccount payAccount) { | |||
| int iChargeFee = PayUtils.getPayRate(payment, payAccount.getRate(), false); | |||
| 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) { | |||
| 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; | |||
| } | |||
| @@ -12,6 +12,7 @@ import com.iformall.enums.EnumProfitSharingOrderType; | |||
| import com.iformall.enums.EnumProfitSharingReceiverType; | |||
| import com.iformall.exception.MallinkException; | |||
| 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.PayShareResult; | |||
| import com.iformall.service.pay.service.share.entity.ShareNotifyAdapterResult; | |||
| @@ -34,6 +35,11 @@ public interface PayShareAdapterService { | |||
| */ | |||
| public Integer getProfitSharingType(); | |||
| /** | |||
| * 计算商场分账金额和实际费率金额 | |||
| */ | |||
| public PayShareCalculateAmount calculateAmount(Integer payAmount,WxPayAccount payAccount); | |||
| /** | |||
| * 无分账接收方分账 ,钱直接分给小程序方 调用API分账 | |||
| * @param appInfo | |||
| @@ -11,7 +11,9 @@ import com.iformall.douyin.pay.preOrder.Settle; | |||
| import com.iformall.douyin.pay.preOrder.SettleResult; | |||
| import com.iformall.enums.*; | |||
| 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.entity.PayShareCalculateAmount; | |||
| 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.ShareAccountResult; | |||
| @@ -37,6 +39,13 @@ public class TtPayShareService extends PayShareBaseAdapterService{ | |||
| public Integer getProfitSharingType() { | |||
| 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 | |||
| public PayShareResult noReciverShare(WxAppinfo appInfo,WxPayAccount payAccount,WxProfitSharingOrder record,String transcationId,Integer amount) { | |||
| @@ -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; | |||
| } | |||
| } | |||
| @@ -39,9 +39,11 @@ import com.iformall.pay.WxProfitSharingFinishP; | |||
| import com.iformall.pay.WxProfitSharingP; | |||
| import com.iformall.pay.WxProfitSharingQueryP; | |||
| 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.PayShareBaseAdapterService; | |||
| 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.PayShareResult; | |||
| import com.iformall.service.pay.service.share.entity.ShareNotifyAdapterResult; | |||
| @@ -71,6 +73,13 @@ public class WxPayShareService extends PayShareBaseAdapterService{ | |||
| public Integer getProfitSharingType() { | |||
| 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 | |||
| public PayShareResult noReciverShare(WxAppinfo appInfo,WxPayAccount payAccount,WxProfitSharingOrder record,String transcationId,Integer amount) { | |||
| @@ -444,7 +453,7 @@ public class WxPayShareService extends PayShareBaseAdapterService{ | |||
| } | |||
| return null; | |||
| } | |||
| // public static void main(String[] args) { | |||
| // System.out.println(queryOrderShareAmount("1511925291","4200001516202205010431149938","XHZfpVA0NzoXgLEjsujctUTcyj8Zur2C")); | |||
| // //System.out.println(test("1511925291", "1604439800", "wxed2f44705544b892", "4200001455202205127949391954", "XHZfpVA0NzoXgLEjsujctUTcyj8Zur2C", "684670745960046592", "D:\\apiclient_cert.p12")); | |||
| @@ -23,8 +23,7 @@ public class PayUtils { | |||
| Double dPayRate = 1.0D * payAmount * rate / 10000; | |||
| long dChargeFee = Math.round(dPayRate); | |||
| return Long.valueOf(dChargeFee).intValue(); | |||
| } | |||
| else if(payAmount > dBaseAmount.intValue()) { | |||
| }else if(payAmount > dBaseAmount.intValue()) { | |||
| // 大于基础分,不小于他的最小整数 | |||
| Double dChargeFee = Math.ceil(payAmount * 1.0D * rate / 10000); | |||
| return dChargeFee.intValue(); | |||
| @@ -35,6 +34,10 @@ public class PayUtils { | |||
| return Long.valueOf(dChargeFee).intValue(); | |||
| } | |||
| } | |||
| public static void main(String[] args) { | |||
| System.out.println(getPayRate(990, 7001, true)); | |||
| } | |||
| /* | |||
| public static void main(String[] args) { | |||