From 57aad21c0eed9c1dad467ae2f1862756e623f913 Mon Sep 17 00:00:00 2001 From: xhxu Date: Thu, 23 Feb 2023 16:47:45 +0800 Subject: [PATCH] //sharing rate --- .../V2023022300001__add_goodsC_permission.sql | 2 + .../com/iformall/domain/po/WxPayAccount.java | 3 + .../service/TtGoodsCategoryService.java | 2 + .../service/TtMallGoodsCategoryService.java | 2 + .../com/iformall/service/WxCouponService.java | 8 +- .../impl/TtCouponGoodsServiceImpl.java | 117 ++++++++-------- .../impl/TtGoodsCategoryServiceImpl.java | 9 ++ .../impl/TtMallGoodsCategoryServiceImpl.java | 17 +++ .../service/impl/WxCouponServiceImpl.java | 5 + .../impl/WxProfitSharingOrderServiceImpl.java | 31 +++-- .../entity/WxComposeChildOrderShare.java | 16 +-- .../service/pay/PayServiceFactory.java | 26 ++++ .../service/fee/ServiceFeeAdapterService.java | 61 +++++++++ .../pay/service/fee/TtServiceFeeService.java | 127 ++++++++++++++++++ .../pay/service/fee/WxServiceFeeService.java | 98 ++++++++++++++ .../service/share/PayShareAdapterService.java | 8 -- .../share/douyin/TtPayShareService.java | 30 +---- .../share/wx/sft/WxPayShareSFTService.java | 5 - .../share/wx/v2/WxPayShareService.java | 5 - .../share/wx/v3/WxPayShareV3Service.java | 5 - .../java/com/iformall/utils/PayUtils.java | 3 + 21 files changed, 448 insertions(+), 132 deletions(-) create mode 100644 mallinkAdmin/src/main/resources/db/migration/V2023022300001__add_goodsC_permission.sql create mode 100644 mallinkService/src/main/java/com/iformall/service/pay/service/fee/ServiceFeeAdapterService.java create mode 100644 mallinkService/src/main/java/com/iformall/service/pay/service/fee/TtServiceFeeService.java create mode 100644 mallinkService/src/main/java/com/iformall/service/pay/service/fee/WxServiceFeeService.java diff --git a/mallinkAdmin/src/main/resources/db/migration/V2023022300001__add_goodsC_permission.sql b/mallinkAdmin/src/main/resources/db/migration/V2023022300001__add_goodsC_permission.sql new file mode 100644 index 000000000..0b65190be --- /dev/null +++ b/mallinkAdmin/src/main/resources/db/migration/V2023022300001__add_goodsC_permission.sql @@ -0,0 +1,2 @@ +INSERT INTO `mallink`.`mall_permission`(`id`, `name`, `parent_id`, `available`, `permission`, `resource_type`, `module_color`, `module_color_num`, `url`, `icon`, `version_type`, `sort`) VALUES (1103, '抖音类目佣金设置', 100, 'Y', NULL, 1, NULL, NULL, 'goodsCategory', 'icon-shenpiguanli', 0, 1103); + diff --git a/mallinkService/src/main/java/com/iformall/domain/po/WxPayAccount.java b/mallinkService/src/main/java/com/iformall/domain/po/WxPayAccount.java index 58a50fa3b..15cb83764 100644 --- a/mallinkService/src/main/java/com/iformall/domain/po/WxPayAccount.java +++ b/mallinkService/src/main/java/com/iformall/domain/po/WxPayAccount.java @@ -72,6 +72,9 @@ public class WxPayAccount extends TenantEntity { @io.swagger.annotations.ApiModelProperty(value="是否抽成",name="isCommission") private Integer isCommission; + /** + * 微信适用。抖音通过类别获取 + */ @io.swagger.annotations.ApiModelProperty(value="系统提点",name="systemRate") private Integer systemRate; @io.swagger.annotations.ApiModelProperty(value="销售提点",name="sellRate") diff --git a/mallinkService/src/main/java/com/iformall/service/TtGoodsCategoryService.java b/mallinkService/src/main/java/com/iformall/service/TtGoodsCategoryService.java index 460426d44..77607eb8d 100644 --- a/mallinkService/src/main/java/com/iformall/service/TtGoodsCategoryService.java +++ b/mallinkService/src/main/java/com/iformall/service/TtGoodsCategoryService.java @@ -49,4 +49,6 @@ public interface TtGoodsCategoryService { void updateFee(TtGoodsCategory record); + int getTtServiceFee(Integer categoryId); + } diff --git a/mallinkService/src/main/java/com/iformall/service/TtMallGoodsCategoryService.java b/mallinkService/src/main/java/com/iformall/service/TtMallGoodsCategoryService.java index fe3a0d712..3da831f73 100644 --- a/mallinkService/src/main/java/com/iformall/service/TtMallGoodsCategoryService.java +++ b/mallinkService/src/main/java/com/iformall/service/TtMallGoodsCategoryService.java @@ -14,4 +14,6 @@ public interface TtMallGoodsCategoryService { void updateFee(TtMallGoodsCategoryVo record); + int getMallSoftwareFee(TenantEntity tenantEntity,Integer categoryId); + } diff --git a/mallinkService/src/main/java/com/iformall/service/WxCouponService.java b/mallinkService/src/main/java/com/iformall/service/WxCouponService.java index 54c3aa80c..fdd0a0192 100644 --- a/mallinkService/src/main/java/com/iformall/service/WxCouponService.java +++ b/mallinkService/src/main/java/com/iformall/service/WxCouponService.java @@ -7,11 +7,7 @@ import javax.servlet.http.HttpServletResponse; import com.github.pagehelper.PageInfo; import com.iformall.common.ResultData; -import com.iformall.domain.po.TtCouponChannelPoi; -import com.iformall.domain.po.WxAppinfo; -import com.iformall.domain.po.WxCoupon; -import com.iformall.domain.po.WxMall; -import com.iformall.domain.po.WxMerchant; +import com.iformall.domain.po.*; import com.iformall.domain.po.base.TenantEntity; import com.iformall.domain.vo.TtCouponVo; import com.iformall.domain.vo.WxCouponCVo; @@ -303,4 +299,6 @@ public interface WxCouponService { * @return */ boolean isCouponMerchantValid(Long couponId,Integer couponType,TenantEntity couponTenantEntity); + + Integer getCategoryId(TenantEntity tenantEntity, Long couponId); } diff --git a/mallinkService/src/main/java/com/iformall/service/impl/TtCouponGoodsServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/TtCouponGoodsServiceImpl.java index 26ed1acad..f14965636 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/TtCouponGoodsServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/TtCouponGoodsServiceImpl.java @@ -19,6 +19,8 @@ import com.iformall.enums.*; import com.iformall.exception.MallinkException; import com.iformall.mapper.*; import com.iformall.service.*; +import com.iformall.service.pay.PayServiceFactory; +import com.iformall.service.pay.service.fee.ServiceFeeAdapterService; import com.iformall.utils.Constant; import com.iformall.utils.DateUtils; import me.chanjar.weixin.common.error.WxErrorException; @@ -81,7 +83,7 @@ public class TtCouponGoodsServiceImpl implements TtCouponGoodsService { TtPoiTakeRateMapper ttPoiTakeRateMapper; @Autowired - TtGoodsCategoryMapper ttGoodsCategoryMapper; + TtGoodsCategoryService ttGoodsCategoryService; @Lazy @Autowired @@ -91,6 +93,9 @@ public class TtCouponGoodsServiceImpl implements TtCouponGoodsService { @Autowired WxMerchantService wxMerchantService; + @Autowired + PayServiceFactory payServiceFactory; + // @Override // public ResultData couponList(TtCouponVo ttCouponVo, Integer pageNum, Integer pageSize) { // PageInfo pageInfo = PageHelper.startPage(pageNum, pageSize).doSelectPageInfo(() -> wxCouponMapper.ttCouponList(ttCouponVo)); @@ -940,13 +945,13 @@ public class TtCouponGoodsServiceImpl implements TtCouponGoodsService { } } - /** - * 删除定向计划里的达人,并处理达人数据 - * 只能一个个删除,有可能删除失败 - * @param ttWebService - * @param takeRate - * @return - */ +// /** +// * 删除定向计划里的达人,并处理达人数据 +// * 只能一个个删除,有可能删除失败 +// * @param ttWebService +// * @param takeRate +// * @return +// */ // private void poiOrientedPlanDeleteTalent(TtWebService ttWebService,TtPoiTakeRate takeRate){ // if(takeRate == null || takeRate.getId() == null // || takeRate.getDouyinIdList() == null || takeRate.getDouyinIdList().isEmpty()){ @@ -1090,9 +1095,11 @@ public class TtCouponGoodsServiceImpl implements TtCouponGoodsService { TtPoiTakeRate ttPoiTakeRate = ttPoiTakeRateMapper.selectByCoupon(tenantInfo.getTenantId(), couponId,EnumCpsPlanType.ALL.getCode()); Map map = new HashMap<>(); - if(ttPoiTakeRate != null){ - map.put("mallRate",ttPoiTakeRate.getTakeRate()); + int mallRate = 0; + if(ttPoiTakeRate != null && ttPoiTakeRate.getTakeRate() != null){ + mallRate = ttPoiTakeRate.getTakeRate(); } + map.put("mallRate",mallRate); WxAppinfo couponAppInfo = wxAppinfoService.getCouponAppInfo(wxCoupon); if(couponAppInfo == null || couponAppInfo.getPayId() == null){ @@ -1103,27 +1110,19 @@ public class TtCouponGoodsServiceImpl implements TtCouponGoodsService { return new ResultData(ErrorCode.API_KEY_NOT_FOUND); } - map.put("realRate",payAccount.getRealRate()); - int rate = 0; - if(EnumYesOrNo.YES.getCode().equals(payAccount.getIsCommission())){ - map.put("systemRate",payAccount.getSystemRate()+payAccount.getSellRate()); - rate = payAccount.getRealRate()+payAccount.getSystemRate()+payAccount.getSellRate(); - }else{ - rate = payAccount.getRealRate(); - } - - if(EnumAppPlat.TOUTIAO.getCode().equals(couponAppInfo.getPlat())){ - if(wxCoupon.getCategoryId() == null){ - return new ResultData(ErrorCode.COUPON_ORDER_TYPE_NOT_SUPPORTED.getCode(),"卡券信息错误"); - } - TtGoodsCategory ttGoodsCategory = ttGoodsCategoryMapper.selectById(wxCoupon.getCategoryId()); - map.put("serviceFeeRate",ttGoodsCategory.getServiceFee()-payAccount.getRealRate()); - rate = rate-payAccount.getRealRate()+ttGoodsCategory.getServiceFee(); - Integer maxTakeRate = ttPoiTakeRateMapper.getMaxTakeRate(wxCoupon.getTenantId(), wxCoupon.getId()); - if(maxTakeRate != null){ - rate += maxTakeRate; - } + ServiceFeeAdapterService serviceFeeService = payServiceFactory.getServiceFeeAdapterService(couponAppInfo.getPlat()); + int realRate = serviceFeeService.getRealRate(payAccount); + map.put("realRate",realRate); + int systemCommission = serviceFeeService.getSystemCommission(wxCoupon.getCategoryId(),payAccount); + int sellCommission = serviceFeeService.getSellCommission(payAccount); + map.put("systemRate",systemCommission + sellCommission); + int officialCommission = serviceFeeService.getOfficialCommission(wxCoupon.getCategoryId(), payAccount); + map.put("serviceFeeRate",officialCommission); + Integer maxTakeRate = ttPoiTakeRateMapper.getMaxTakeRate(wxCoupon.getTenantId(), wxCoupon.getId()); + if(maxTakeRate == null){ + maxTakeRate = 0; } + int rate = realRate + systemCommission + sellCommission + officialCommission + maxTakeRate; map.put("mallMax",getAllMax()); map.put("mallMin",rate); @@ -1158,8 +1157,8 @@ public class TtCouponGoodsServiceImpl implements TtCouponGoodsService { throw new MallinkException(ErrorCode.COUPON_ORDER_TYPE_NOT_SUPPORTED); } TtPoiTakeRate ttPoiTakeRate = ttPoiTakeRateMapper.selectByCoupon(wxCoupon.getTenantId(), wxCoupon.getId(),EnumCpsPlanType.ALL.getCode()); - Integer takeRate = null; - if(ttPoiTakeRate != null){ + int takeRate = 0; + if(ttPoiTakeRate != null && ttPoiTakeRate.getTakeRate() != null){ takeRate = ttPoiTakeRate.getTakeRate(); }else{ return getAllMax(); @@ -1173,20 +1172,14 @@ public class TtCouponGoodsServiceImpl implements TtCouponGoodsService { if(payAccount == null){ throw new MallinkException(ErrorCode.API_KEY_NOT_FOUND); } - int rate = 0; - rate = payAccount.getRealRate()+payAccount.getSystemRate()+payAccount.getSellRate(); - if(EnumAppPlat.TOUTIAO.getCode().equals(couponAppInfo.getPlat())){ - if(wxCoupon.getCategoryId() == null){ - throw new MallinkException(ErrorCode.COUPON_ORDER_TYPE_NOT_SUPPORTED.getCode(),"卡券信息错误"); - } - TtGoodsCategory ttGoodsCategory = ttGoodsCategoryMapper.selectById(wxCoupon.getCategoryId()); - rate = rate-payAccount.getRealRate()+ttGoodsCategory.getServiceFee(); - } + + int rate = getOtherAllFee(couponAppInfo,payAccount,wxCoupon.getCategoryId()); + if(takeRate > rate){ rate = takeRate - rate; return rate; }else{ - throw new MallinkException(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"分佣率异常"); + throw new MallinkException(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"分佣率设置异常"); } } //达人分佣率最小值 @@ -1216,23 +1209,31 @@ public class TtCouponGoodsServiceImpl implements TtCouponGoodsService { if(payAccount == null){ throw new MallinkException(ErrorCode.API_KEY_NOT_FOUND); } - int rate = 0; - if(EnumYesOrNo.YES.getCode().equals(payAccount.getIsCommission())){ - rate = payAccount.getRealRate()+payAccount.getSystemRate()+payAccount.getSellRate(); - }else{ - rate = payAccount.getRealRate(); - } - if(EnumAppPlat.TOUTIAO.getCode().equals(couponAppInfo.getPlat())){ - if(wxCoupon.getCategoryId() == null){ - throw new MallinkException(ErrorCode.COUPON_ORDER_TYPE_NOT_SUPPORTED.getCode(),"卡券信息错误"); - } - TtGoodsCategory ttGoodsCategory = ttGoodsCategoryMapper.selectById(wxCoupon.getCategoryId()); - rate = rate-payAccount.getRealRate()+ttGoodsCategory.getServiceFee(); - Integer maxTakeRate = ttPoiTakeRateMapper.getMaxTakeRate(wxCoupon.getTenantId(), wxCoupon.getId()); - if(maxTakeRate != null){ - rate += maxTakeRate; - } + + int rate = getOtherAllFee(couponAppInfo,payAccount,wxCoupon.getCategoryId()); + Integer maxTakeRate = ttPoiTakeRateMapper.getMaxTakeRate(wxCoupon.getTenantId(), wxCoupon.getId()); + if(maxTakeRate == null){ + maxTakeRate = 0; } + + return rate + maxTakeRate; + } + + /** + * 获取支付渠道费+系统服务费+销售抽成+平台服务费 + * @param appinfo + * @param payAccount + * @param categoryId + * @return + */ + private int getOtherAllFee(WxAppinfo appinfo,WxPayAccount payAccount,Integer categoryId){ + ServiceFeeAdapterService serviceFeeService = payServiceFactory.getServiceFeeAdapterService(appinfo.getPlat()); + int realRate = serviceFeeService.getRealRate(payAccount); + int systemCommission = serviceFeeService.getSystemCommission(categoryId,payAccount); + int sellCommission = serviceFeeService.getSellCommission(payAccount); + int officialCommission = serviceFeeService.getOfficialCommission(categoryId, payAccount); + + int rate = realRate + systemCommission + sellCommission + officialCommission; return rate; } diff --git a/mallinkService/src/main/java/com/iformall/service/impl/TtGoodsCategoryServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/TtGoodsCategoryServiceImpl.java index 4ff940a7f..d47a460a7 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/TtGoodsCategoryServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/TtGoodsCategoryServiceImpl.java @@ -552,6 +552,15 @@ public class TtGoodsCategoryServiceImpl implements TtGoodsCategoryService { } } + @Override + public int getTtServiceFee(Integer categoryId) { + TtGoodsCategory goodsCategory = ttGoodsCategoryMapper.selectById(categoryId); + if(goodsCategory != null){ + return goodsCategory.getServiceFee(); + } + return 0; + } + /** * 循环同步类目 * @param ttWebService diff --git a/mallinkService/src/main/java/com/iformall/service/impl/TtMallGoodsCategoryServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/TtMallGoodsCategoryServiceImpl.java index 3067769ce..28e739f47 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/TtMallGoodsCategoryServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/TtMallGoodsCategoryServiceImpl.java @@ -85,6 +85,23 @@ public class TtMallGoodsCategoryServiceImpl implements TtMallGoodsCategoryServic updateFeeByIds(record,record.getCategoryId(),record.getMallSoftwareFee(),new Date()); } + @Override + public int getMallSoftwareFee(TenantEntity tenantEntity, Integer categoryId) { + TtMallGoodsCategory mallGoodsCategory = new TtMallGoodsCategory(); + mallGoodsCategory.setGoodsCategoryId(categoryId); + mallGoodsCategory.updateTenantInfo(tenantEntity); + mallGoodsCategory = ttMallGoodsCategoryMapper.selectByTenantAndCategoryId(mallGoodsCategory); + if(mallGoodsCategory != null){ + return mallGoodsCategory.getSoftwareFee(); + }else{ + TtGoodsCategory goodsCategory = ttGoodsCategoryMapper.selectById(categoryId); + if(goodsCategory != null){ + return goodsCategory.getSoftwareFee(); + } + } + return 0; + } + /** * 循环修改费率 */ diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxCouponServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxCouponServiceImpl.java index 80ac9f12c..11eba696f 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxCouponServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxCouponServiceImpl.java @@ -1967,5 +1967,10 @@ public class WxCouponServiceImpl implements WxCouponService { return false; } + @Override + public Integer getCategoryId(TenantEntity tenantEntity, Long couponId) { + return wxCouponMapper.findCategoryIdById(couponId,tenantEntity.getTenantId()); + } + } diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxProfitSharingOrderServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxProfitSharingOrderServiceImpl.java index f3ff83c5a..2d2c86ecd 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxProfitSharingOrderServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxProfitSharingOrderServiceImpl.java @@ -25,6 +25,7 @@ import com.iformall.service.*; import com.iformall.service.order.entity.WxComposeChildOrderShare; import com.iformall.service.order.util.OrderHelper; import com.iformall.service.pay.PayServiceFactory; +import com.iformall.service.pay.service.fee.ServiceFeeAdapterService; import com.iformall.service.pay.service.pay.douyin.v1.miniApp.EnumTtPayChannel; import com.iformall.service.pay.service.share.PayShareAdapterService; import com.iformall.service.pay.service.share.entity.PayShareCalculateAmount; @@ -217,6 +218,8 @@ public class WxProfitSharingOrderServiceImpl implements WxProfitSharingOrderServ WxAppinfo cAppInfo = wxAppinfoService.getCAppInfo(sharingOrder, enumPlat); WxPayAccount payAccount = wxPayAccountMapper.selectById(cAppInfo.getPayId()); + ServiceFeeAdapterService serviceFeeService = payServiceFactory.getServiceFeeAdapterService(enumPlat.getCode()); + WxComposeChildOrderShare wxComposeChildOrderShare = null; if(sharingOrder.getSingleOrderId() != null){ wxComposeChildOrderShare = payOrder.getChildOrderShare(sharingOrder.getSingleOrderId()); @@ -225,24 +228,27 @@ public class WxProfitSharingOrderServiceImpl implements WxProfitSharingOrderServ } wxComposeChildOrderShare.setCpsCommission(cpsCommission); - //官方手续费千6 - int realRateAmount = PayUtils.getPayRate(wxComposeChildOrderShare.getRealPayMent(), payAccount.getRealRate(), true); + //官方手续费---千6 + int realRate = serviceFeeService.getRealRate(payAccount); + int realRateAmount = PayUtils.getPayRate(wxComposeChildOrderShare.getRealPayMent(), realRate, true); wxComposeChildOrderShare.setRealRateAmount(realRateAmount); //官方平台抽佣 - int rate = payShareAdapterService.getOfficialCommission(wxComposeChildOrderShare.getOrderId(),payAccount); + int rate = serviceFeeService.getOfficialCommissionByOrder(wxComposeChildOrderShare.getOrderId(),payAccount); int commissionAmount = PayUtils.getPayRate(wxComposeChildOrderShare.getRealPayMent(), rate, true); wxComposeChildOrderShare.setCommissionAmount(commissionAmount); int surplus = 0;//当广场抽成帐号与收款帐号相等,无法添加分账方,计入商管商户中 - //只有抖音直连才有分账 + //只有抖音才有抽成 + //微信缺少流程(分账帐号绑定) 无法抽成 if(EnumPayWay.PAY_WAY_TT.getCode().equals(payOrder.getPayVendor()) - && EnumPayMchType.DIRECT.getCode().equals(payOrder.getMchType()) && EnumYesOrNo.YES.getCode().equals(payAccount.getIsCommission())){ //销售抽点+系统抽点 - int selSysAmount = PayUtils.getPayRate(wxComposeChildOrderShare.getRealPayMent(), payAccount.getSellRate()+payAccount.getSystemRate(), false); + int systemCommission = serviceFeeService.getSystemCommissionByOrder(wxComposeChildOrderShare.getOrderId(), payAccount); + int sellCommission = serviceFeeService.getSellCommission(payAccount); + int selSysAmount = PayUtils.getPayRate(wxComposeChildOrderShare.getRealPayMent(), systemCommission+sellCommission, false); //销售抽点 - int sellerAmount = PayUtils.getPayRate(wxComposeChildOrderShare.getRealPayMent(), payAccount.getSellRate(), false); + int sellerAmount = PayUtils.getPayRate(wxComposeChildOrderShare.getRealPayMent(), sellCommission, false); wxComposeChildOrderShare.setSellerAmount(sellerAmount); boolean isSeller = false; if(sellerAmount > 0){ @@ -318,7 +324,7 @@ public class WxProfitSharingOrderServiceImpl implements WxProfitSharingOrderServ wxComposeChildOrderShare.setServiceAmount(null); } //商户所得 - int shareAmount = wxComposeChildOrderShare.getShareAmount() + surplus; + int shareAmount = wxComposeChildOrderShare.getShareAmount(); boolean isCallSharing = false;//是否调用分账 boolean isCreateSubsidy = false;//是否需要记账 @@ -424,12 +430,13 @@ public class WxProfitSharingOrderServiceImpl implements WxProfitSharingOrderServ } if(isSharingResult){ + int sharingSubsidyAmount = shareAmount+surplus; if(EnumPayMchType.TOTAL.getCode().equals(payOrder.getMchType())){ - //解冻给收款方(广场) + //解冻给收款方(广场) +抽成没抽过去的。surplus JSONObject jo = new JSONObject(); // jo.put("type",EnumProfitPaymentReceiverType.wx_special_merchant_number.getMessage()); jo.put("account",payAccount.getSubMchId()); - jo.put("amount", shareAmount); + jo.put("amount", sharingSubsidyAmount); jo.put("merchantId",0); jo.put("bTenantId",payOrder.getTenantId()); jo.put("description",0); @@ -441,13 +448,13 @@ public class WxProfitSharingOrderServiceImpl implements WxProfitSharingOrderServ if(receiver != null && receiver.getReceiverAccount().equals(wxComposeChildOrderShare.getMerchantUid())){ jo.put("type",EnumProfitPaymentReceiverType.getEnum(receiver.getReceiverType()).getMessage()); jo.put("account",receiver.getReceiverAccount()); - jo.put("amount", shareAmount); + jo.put("amount", sharingSubsidyAmount); jo.put("merchantId",receiver.getMerchantId()); jo.put("bTenantId",receiver.getTenantId()); jo.put("description",receiver.getId()); }else{ jo.put("account",wxComposeChildOrderShare.getMerchantUid()); - jo.put("amount", shareAmount); + jo.put("amount", sharingSubsidyAmount); jo.put("merchantId",wxComposeChildOrderShare.getMerchantId()); jo.put("bTenantId",payOrder.getTenantId()); jo.put("description",0); diff --git a/mallinkService/src/main/java/com/iformall/service/order/entity/WxComposeChildOrderShare.java b/mallinkService/src/main/java/com/iformall/service/order/entity/WxComposeChildOrderShare.java index 1bbe9d231..260aa6bb5 100644 --- a/mallinkService/src/main/java/com/iformall/service/order/entity/WxComposeChildOrderShare.java +++ b/mallinkService/src/main/java/com/iformall/service/order/entity/WxComposeChildOrderShare.java @@ -75,27 +75,27 @@ public class WxComposeChildOrderShare { if(this.realRateAmount == null){ return; } - int sumAmount = this.realRateAmount.intValue(); + int sumAmount = this.realRateAmount.intValue();//支付通道费 if(this.commissionAmount != null){ - sumAmount += this.commissionAmount.intValue(); + sumAmount += this.commissionAmount.intValue();//平台服务费 } if(this.cpsCommission != null){ - sumAmount += this.cpsCommission.intValue(); + sumAmount += this.cpsCommission.intValue();//达人佣金 } if(this.systemAmount != null){ - sumAmount += this.systemAmount; + sumAmount += this.systemAmount;//系统扣点 } if(this.sellerAmount != null){ - sumAmount += this.sellerAmount; + sumAmount += this.sellerAmount;//销售扣点 } if(serviceAmount == null || serviceAmount.intValue() < sumAmount){ this.serviceAmount = sumAmount; }else{ - this.serviceAmount = serviceAmount; + this.serviceAmount = serviceAmount;//一笔订单总扣除手续费 } - this.rateAmount = this.serviceAmount.intValue() - sumAmount; - this.shareAmount = this.realPayMent.intValue() - this.serviceAmount.intValue(); + this.rateAmount = this.serviceAmount.intValue() - sumAmount;//剩下的就是给商场的 + this.shareAmount = this.realPayMent.intValue() - this.serviceAmount.intValue();//这就是给商户的 } } diff --git a/mallinkService/src/main/java/com/iformall/service/pay/PayServiceFactory.java b/mallinkService/src/main/java/com/iformall/service/pay/PayServiceFactory.java index 8ef7408d0..cc7f41000 100644 --- a/mallinkService/src/main/java/com/iformall/service/pay/PayServiceFactory.java +++ b/mallinkService/src/main/java/com/iformall/service/pay/PayServiceFactory.java @@ -4,6 +4,9 @@ import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import com.iformall.enums.EnumAppPlat; import com.iformall.enums.EnumPayVersion; +import com.iformall.service.pay.service.fee.ServiceFeeAdapterService; +import com.iformall.service.pay.service.fee.TtServiceFeeService; +import com.iformall.service.pay.service.fee.WxServiceFeeService; import com.iformall.service.pay.service.refund.douyin.TtRefundAdapterService; import com.iformall.service.pay.service.refund.wx.v2.WxRefundAdapterService; import com.iformall.service.pay.service.refund.wx.v3.WxRefundV3AdapterService; @@ -45,6 +48,7 @@ public class PayServiceFactory { private Map shareMap = null; private Map refundMap = null; private Map cashoutMap = null; + private Map serviceFeeMap = null; @Autowired WxMiniAppPayAdapterService wxMiniAppPayService; @@ -86,6 +90,11 @@ public class PayServiceFactory { WxCashOutQYFKAdapterService wxCashOutService; @Autowired WxCashOutSFTAdapterService wxCashOutSFTAdapterService; + + @Autowired + TtServiceFeeService ttServiceFeeService; + @Autowired + WxServiceFeeService wxServiceFeeService; @@ -193,6 +202,15 @@ public class PayServiceFactory { } return cashoutMap; } + + private Map getServiceFeeMap() { + if (null == serviceFeeMap ) { + serviceFeeMap = new ConcurrentHashMap(); + serviceFeeMap.put(EnumAppPlat.WX.getCode()+"_", wxServiceFeeService); + serviceFeeMap.put(EnumAppPlat.TOUTIAO.getCode()+"_", ttServiceFeeService); + } + return serviceFeeMap; + } public PayAdapterService getPayAdapterService(Integer type,Integer payVersion) throws MallinkException{ PayAdapterService service = getServiceMap().get(type+"_"+payVersion); @@ -257,4 +275,12 @@ public class PayServiceFactory { } return cashOutService; } + + public ServiceFeeAdapterService getServiceFeeAdapterService(Integer plat)throws MallinkException { + ServiceFeeAdapterService serviceFeeService = getServiceFeeMap().get(plat+"_"); + if (null == serviceFeeService) { + throw new MallinkException(ErrorCode.SYS_SERVER_ERROR.getCode(),"payWay["+plat+"] 费率service未找到"); + } + return serviceFeeService; + } } diff --git a/mallinkService/src/main/java/com/iformall/service/pay/service/fee/ServiceFeeAdapterService.java b/mallinkService/src/main/java/com/iformall/service/pay/service/fee/ServiceFeeAdapterService.java new file mode 100644 index 000000000..2abb5de49 --- /dev/null +++ b/mallinkService/src/main/java/com/iformall/service/pay/service/fee/ServiceFeeAdapterService.java @@ -0,0 +1,61 @@ +package com.iformall.service.pay.service.fee; + +import com.iformall.domain.po.WxAppinfo; +import com.iformall.domain.po.WxCashOut; +import com.iformall.domain.po.WxPayAccount; +import com.iformall.domain.po.base.TenantEntity; +import com.iformall.service.pay.service.cashout.entity.CashOutAdapterResult; + +/** + * 费率接口 + * @author + */ +public interface ServiceFeeAdapterService { + + /** + * 获取实际支付通道费率 + * @param payAccount + * @return + */ + public int getRealRate(WxPayAccount payAccount); + + /** + * 获取平台(微信,抖音等)抽佣手续费率(不包含支付通道费率) + * @return + */ + public int getOfficialCommission(Integer categoryId, WxPayAccount payAccount); + public int getOfficialCommissionByOrder(Long orderId, WxPayAccount payAccount); + + /** + * 获取系统(富茂)抽佣手续费率 + * @return + */ + public int getSystemCommission(Integer categoryId, WxPayAccount payAccount); + public int getSystemCommissionByOrder(Long orderId, WxPayAccount payAccount); + + /** + * 获取第三方(销售)抽佣 + */ + public int getSellCommission(WxPayAccount payAccount); + + /** + * 获取达人佣金费率 + * 多条数据 无法获取 + * @return + */ +// public int getCPSCommission(TenantEntity tenantEntity, Long couponId); + + /** + * 获取所有的总抽佣费率 + * 如过设置了就返回,没设置返回0 + */ + public int getAllCommission(Long couponId, WxPayAccount payAccount); + + /** + * 获取商场抽佣费率 + * 无法获取准确的达人拥挤费率, 无法计算 + */ +// public int getMallCommission(Long couponId, WxPayAccount payAccount); + + +} diff --git a/mallinkService/src/main/java/com/iformall/service/pay/service/fee/TtServiceFeeService.java b/mallinkService/src/main/java/com/iformall/service/pay/service/fee/TtServiceFeeService.java new file mode 100644 index 000000000..613bf15ae --- /dev/null +++ b/mallinkService/src/main/java/com/iformall/service/pay/service/fee/TtServiceFeeService.java @@ -0,0 +1,127 @@ +package com.iformall.service.pay.service.fee; + +import com.iformall.domain.po.TtPoiTakeRate; +import com.iformall.domain.po.WxOrder; +import com.iformall.domain.po.WxPayAccount; +import com.iformall.domain.po.base.TenantEntity; +import com.iformall.enums.EnumCpsPlanType; +import com.iformall.enums.EnumOrderType; +import com.iformall.enums.EnumYesOrNo; +import com.iformall.mapper.TtPoiTakeRateMapper; +import com.iformall.mapper.WxCouponMapper; +import com.iformall.mapper.WxOrderMapper; +import com.iformall.service.TtGoodsCategoryService; +import com.iformall.service.TtMallGoodsCategoryService; +import com.iformall.service.WxCouponService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +@Slf4j +@Service +public class TtServiceFeeService implements ServiceFeeAdapterService{ + + @Autowired + WxOrderMapper wxOrderMapper; + + @Autowired + TtPoiTakeRateMapper ttPoiTakeRateMapper; + + @Autowired + WxCouponService wxCouponService; + + @Autowired + TtGoodsCategoryService ttGoodsCategoryService; + + @Autowired + TtMallGoodsCategoryService ttMallGoodsCategoryService; + + + @Override + public int getRealRate(WxPayAccount payAccount) { + Integer realRate = payAccount.getRealRate(); + if(realRate == null){ + realRate = 60; + } + return realRate; + } + + @Override + public int getOfficialCommission(Integer categoryId, WxPayAccount payAccount) { + if(categoryId != null){ + int ttServiceFee = ttGoodsCategoryService.getTtServiceFee(categoryId); + int realRate = this.getRealRate(payAccount); + if(ttServiceFee > realRate){ + return ttServiceFee - realRate; + } + } + return 0; + } + + @Override + public int getOfficialCommissionByOrder(Long orderId, WxPayAccount payAccount) { + return getOfficialCommission(getCategoryIdByOrder(orderId,payAccount),payAccount); + } + + @Override + public int getSystemCommission(Integer categoryId, WxPayAccount payAccount) { + if(categoryId != null){ + if(EnumYesOrNo.YES.getCode().equals(payAccount.getIsCommission())){ + int mallSoftwareFee = ttMallGoodsCategoryService.getMallSoftwareFee(payAccount, categoryId); + return mallSoftwareFee; + } + } + return 0; + } + + @Override + public int getSystemCommissionByOrder(Long orderId, WxPayAccount payAccount) { + return getSystemCommission(getCategoryIdByOrder(orderId,payAccount),payAccount); + } + + @Override + public int getSellCommission(WxPayAccount payAccount) { + if(EnumYesOrNo.YES.getCode().equals(payAccount.getIsCommission())){ + Integer sellRate = payAccount.getSellRate(); + if(sellRate != null){ + return sellRate; + } + } + return 0; + } + +// @Override +// public int getCPSCommission(TenantEntity tenantEntity, Long couponId) { +// return 0; +// } + + @Override + public int getAllCommission(Long couponId, WxPayAccount payAccount) { + int allRate = 0; + if(EnumYesOrNo.YES.getCode().equals(payAccount.getIsCommission())){ + TtPoiTakeRate ttPoiTakeRate = ttPoiTakeRateMapper.selectByCoupon(payAccount.getTenantId(), couponId, EnumCpsPlanType.ALL.getCode()); + if(ttPoiTakeRate != null && ttPoiTakeRate.getTakeRate() != null){ + allRate = ttPoiTakeRate.getTakeRate().intValue(); + } + } + + return allRate; + } + +// @Override +// public int getMallCommission(Long couponId, WxPayAccount payAccount) { +// return 0; +// } + + + + private Integer getCategoryIdByOrder(Long orderId,TenantEntity tenantEntity){ + WxOrder o = wxOrderMapper.selectById(orderId, tenantEntity.getTenantId()); + if(!EnumOrderType.COUPON.getCode().equals(o.getType())){ + return null; + } + Integer categoryId = wxCouponService.getCategoryId(tenantEntity,o.getProductId()); + return categoryId; + } + +} diff --git a/mallinkService/src/main/java/com/iformall/service/pay/service/fee/WxServiceFeeService.java b/mallinkService/src/main/java/com/iformall/service/pay/service/fee/WxServiceFeeService.java new file mode 100644 index 000000000..baeb1ecf8 --- /dev/null +++ b/mallinkService/src/main/java/com/iformall/service/pay/service/fee/WxServiceFeeService.java @@ -0,0 +1,98 @@ +package com.iformall.service.pay.service.fee; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import com.iformall.common.ErrorCode; +import com.iformall.domain.po.*; +import com.iformall.domain.po.base.TenantEntity; +import com.iformall.enums.*; +import com.iformall.exception.MallinkException; +import com.iformall.mapper.WxAppinfoMapper; +import com.iformall.mapper.WxPayAccountMapper; +import com.iformall.mapper.WxPayOrderMapper; +import com.iformall.pay.*; +import com.iformall.service.WxProfitPaymentReceiverService; +import com.iformall.service.WxProfitSharingReceiverService; +import com.iformall.service.pay.service.share.PayShareBaseAdapterService; +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; +import com.iformall.service.pay.service.share.entity.ShareNotifyAdapterResult; +import com.iformall.utils.BeanUtils; +import com.iformall.utils.Utility; +import com.iformall.utils.XmlUtil; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.text.ParseException; +import java.util.*; + +@Slf4j +@Service +public class WxServiceFeeService implements ServiceFeeAdapterService{ + + + @Override + public int getRealRate(WxPayAccount payAccount) { + Integer realRate = payAccount.getRealRate(); + if(realRate == null){ + realRate = 60; + } + return realRate; + } + + @Override + public int getOfficialCommission(Integer categoryId, WxPayAccount payAccount) { + return 0; + } + + @Override + public int getOfficialCommissionByOrder(Long orderId, WxPayAccount payAccount) { + return 0; + } + + @Override + public int getSystemCommission(Integer categoryId, WxPayAccount payAccount) { + if(EnumYesOrNo.YES.getCode().equals(payAccount.getIsCommission())){ + Integer systemRate = payAccount.getSystemRate(); + if(systemRate != null){ + return systemRate; + } + } + return 0; + } + + @Override + public int getSystemCommissionByOrder(Long orderId, WxPayAccount payAccount) { + return getSystemCommission(null,payAccount); + } + + @Override + public int getSellCommission(WxPayAccount payAccount) { + if(EnumYesOrNo.YES.getCode().equals(payAccount.getIsCommission())){ + Integer sellRate = payAccount.getSellRate(); + if(sellRate != null){ + return sellRate; + } + } + return 0; + } + +// @Override +// public int getCPSCommission(TenantEntity tenantEntity, Long couponId) { +// return 0; +// } + + @Override + public int getAllCommission(Long couponId, WxPayAccount payAccount) { + return 0; + } + +// @Override +// public int getMallCommission(Long couponId, WxPayAccount payAccount) { +// return 0; +// } +} diff --git a/mallinkService/src/main/java/com/iformall/service/pay/service/share/PayShareAdapterService.java b/mallinkService/src/main/java/com/iformall/service/pay/service/share/PayShareAdapterService.java index 7cae2a9e8..8527ae0eb 100644 --- a/mallinkService/src/main/java/com/iformall/service/pay/service/share/PayShareAdapterService.java +++ b/mallinkService/src/main/java/com/iformall/service/pay/service/share/PayShareAdapterService.java @@ -120,12 +120,4 @@ public interface PayShareAdapterService { */ int getCPSCommission(TenantEntity tenantEntity, Long orderId); - /** - * 获取官方佣金率 - * @param o - * @param payAccount - * @return - */ - int getOfficialCommission(Long orderId, WxPayAccount payAccount); - } diff --git a/mallinkService/src/main/java/com/iformall/service/pay/service/share/douyin/TtPayShareService.java b/mallinkService/src/main/java/com/iformall/service/pay/service/share/douyin/TtPayShareService.java index 9a53d34a1..1be34fefa 100644 --- a/mallinkService/src/main/java/com/iformall/service/pay/service/share/douyin/TtPayShareService.java +++ b/mallinkService/src/main/java/com/iformall/service/pay/service/share/douyin/TtPayShareService.java @@ -22,6 +22,7 @@ import com.iformall.douyin.payv2.result.ProfitSharingResult; import com.iformall.enums.*; import com.iformall.exception.MallinkException; import com.iformall.mapper.*; +import com.iformall.service.TtGoodsCategoryService; import com.iformall.service.WxProfitPaymentReceiverService; import com.iformall.service.WxProfitSharingReceiverService; import com.iformall.service.order.entity.WxComposeChildOrderShare; @@ -70,10 +71,10 @@ public class TtPayShareService extends PayShareBaseAdapterService{ WxProfitSharingOrderMapper wxProfitSharingOrderMapper; @Autowired - TtGoodsCategoryMapper ttGoodsCategoryMapper; + OrderCpsMapper orderCpsMapper; @Autowired - OrderCpsMapper orderCpsMapper; + TtGoodsCategoryService ttGoodsCategoryService; @Lazy @Autowired @@ -85,7 +86,7 @@ public class TtPayShareService extends PayShareBaseAdapterService{ /** * 做为分账的扩展数据 - * @param payOrder + * @param * @return */ protected String getCpExtra(WxProfitSharingOrder record) { @@ -290,29 +291,6 @@ public class TtPayShareService extends PayShareBaseAdapterService{ } } - @Override - public int getOfficialCommission(Long orderId, WxPayAccount payAccount) { - WxOrder o = wxOrderMapper.selectById(orderId, payAccount.getTenantId()); - if(!EnumOrderType.COUPON.getCode().equals(o.getType())){ - return 0; - } - Integer categoryId = wxCouponMapper.findCategoryIdById(o.getProductId(),o.getTenantId()); - if(categoryId != null){ - TtGoodsCategory ttGoodsCategory = ttGoodsCategoryMapper.selectById(categoryId); - if(ttGoodsCategory != null && ttGoodsCategory.getServiceFee() != null){ - if(ttGoodsCategory.getServiceFee().intValue() == 0){ - return 0; - } - Integer realRate = payAccount.getRealRate(); - if(realRate==null){ - realRate = 60; - } - return ttGoodsCategory.getServiceFee().intValue() - realRate; - } - } - return 0; - } - @Override public WxProfitSharingReceiver getSharingReceiver(TenantEntity tenantEntity, Long merchantId, Integer ttPayWay,Integer mchType) { if(merchantId == null || merchantId.equals(0L)){ diff --git a/mallinkService/src/main/java/com/iformall/service/pay/service/share/wx/sft/WxPayShareSFTService.java b/mallinkService/src/main/java/com/iformall/service/pay/service/share/wx/sft/WxPayShareSFTService.java index 33b754a00..8091b8ee0 100644 --- a/mallinkService/src/main/java/com/iformall/service/pay/service/share/wx/sft/WxPayShareSFTService.java +++ b/mallinkService/src/main/java/com/iformall/service/pay/service/share/wx/sft/WxPayShareSFTService.java @@ -150,11 +150,6 @@ public class WxPayShareSFTService extends PayShareBaseAdapterService{ return 0; } - @Override - public int getOfficialCommission(Long orderId, WxPayAccount payAccount) { - return 0; - } - @Override public WxProfitSharingReceiver getSharingReceiver(TenantEntity tenantEntity, Long merchantId, Integer ttPayWay,Integer mchType) { return null; diff --git a/mallinkService/src/main/java/com/iformall/service/pay/service/share/wx/v2/WxPayShareService.java b/mallinkService/src/main/java/com/iformall/service/pay/service/share/wx/v2/WxPayShareService.java index 4c5954c24..e10cd7127 100644 --- a/mallinkService/src/main/java/com/iformall/service/pay/service/share/wx/v2/WxPayShareService.java +++ b/mallinkService/src/main/java/com/iformall/service/pay/service/share/wx/v2/WxPayShareService.java @@ -355,11 +355,6 @@ public class WxPayShareService extends PayShareBaseAdapterService{ return 0; } - @Override - public int getOfficialCommission(Long orderId, WxPayAccount payAccount) { - return 0; - } - @Override public WxProfitSharingReceiver getSharingReceiver(TenantEntity tenantEntity, Long merchantId, Integer ttPayWay,Integer mchType) { if(merchantId == null || merchantId.equals(0L)){ diff --git a/mallinkService/src/main/java/com/iformall/service/pay/service/share/wx/v3/WxPayShareV3Service.java b/mallinkService/src/main/java/com/iformall/service/pay/service/share/wx/v3/WxPayShareV3Service.java index b5dc44b1d..c11d171fb 100644 --- a/mallinkService/src/main/java/com/iformall/service/pay/service/share/wx/v3/WxPayShareV3Service.java +++ b/mallinkService/src/main/java/com/iformall/service/pay/service/share/wx/v3/WxPayShareV3Service.java @@ -326,11 +326,6 @@ public class WxPayShareV3Service extends PayShareBaseAdapterService{ public int getCPSCommission(TenantEntity tenantEntity, Long orderId) { return 0; } - - @Override - public int getOfficialCommission(Long orderId, WxPayAccount payAccount) { - return 0; - } } diff --git a/mallinkService/src/main/java/com/iformall/utils/PayUtils.java b/mallinkService/src/main/java/com/iformall/utils/PayUtils.java index 225aabb1b..52f3ce977 100755 --- a/mallinkService/src/main/java/com/iformall/utils/PayUtils.java +++ b/mallinkService/src/main/java/com/iformall/utils/PayUtils.java @@ -16,6 +16,9 @@ public class PayUtils { * @return */ public static int getPayRate(int payAmount, int rate, boolean isReal) { + if(rate <= 0){ + return 0; + } Double dBaseAmount = 5.0D * 1000 / rate; // 基础分 千分之6 83分 if (isReal) {