|
|
|
@@ -157,20 +157,6 @@ public class WxProfitSharingOrderServiceImpl implements WxProfitSharingOrderServ |
|
|
|
return null; |
|
|
|
} |
|
|
|
|
|
|
|
private int getMallSumRate(TenantEntity tenantEntity,Long orderId){ |
|
|
|
WxOrder o = wxOrderMapper.selectById(orderId, tenantEntity.getTenantId()); |
|
|
|
if(!EnumOrderType.COUPON.getCode().equals(o.getType())){ |
|
|
|
return 0; |
|
|
|
} |
|
|
|
Long couponId = wxCouponChannelMapper.findCouponIdById(o.getCouponChannelId(), o.getTenantId()); |
|
|
|
TtPoiTakeRate ttPoiTakeRate = ttPoiTakeRateMapper.selectByCoupon(tenantEntity.getTenantId(), couponId, EnumCpsPlanType.ALL.getCode()); |
|
|
|
if(ttPoiTakeRate != null){ |
|
|
|
return ttPoiTakeRate.getTakeRate(); |
|
|
|
}else{ |
|
|
|
return 0; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
// @Transactional(isolation=Isolation.SERIALIZABLE, propagation = Propagation.REQUIRED, rollbackFor = {Exception.class}) |
|
|
|
public ResultData redoSharingOrder(WxProfitSharingOrder sharingOrder,WxPayOrder payOrder) { |
|
|
|
@@ -178,8 +164,7 @@ public class WxProfitSharingOrderServiceImpl implements WxProfitSharingOrderServ |
|
|
|
if(!EnumProfitSharingOrderStatus.shareStatus().contains(sharingOrder.getSharingStatus())){ |
|
|
|
return new ResultData(ErrorCode.PROFIT_SHARING_REQUEST_FAILED.getCode(),"分账状态不允许"); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//核销商户 |
|
|
|
WxMerchant merchant = wxMerchantService.selectById(sharingOrder.getMerchantId()); |
|
|
|
|
|
|
|
Date currentDate = new Date(); |
|
|
|
@@ -188,19 +173,6 @@ public class WxProfitSharingOrderServiceImpl implements WxProfitSharingOrderServ |
|
|
|
|
|
|
|
PayShareResult shareResult = null; |
|
|
|
|
|
|
|
//获取达人佣金 |
|
|
|
int cpsCommission = payShareAdapterService.getCPSCommission(sharingOrder,sharingOrder.getSingleOrderId()); |
|
|
|
if(cpsCommission < 0){ |
|
|
|
WxProfitSharingOrder updSharingOrder = new WxProfitSharingOrder(); |
|
|
|
updSharingOrder.updateTenantInfo(sharingOrder); |
|
|
|
updSharingOrder.setId(sharingOrder.getId()); |
|
|
|
updSharingOrder.setSharingStatus(EnumProfitSharingOrderStatus.PROFIT_SHARING_APPLY_FAILED.getCode()); |
|
|
|
updSharingOrder.setErrorMsg("未获取到达人佣金"); |
|
|
|
updSharingOrder.setUpdateTime(currentDate); |
|
|
|
wxProfitSharingOrderMapper.updateById(updSharingOrder); |
|
|
|
return new ResultData(ErrorCode.PROFIT_SHARING_REQUEST_FAILED.getCode(),"未获取到达人佣金");//等待重试 |
|
|
|
} |
|
|
|
|
|
|
|
JSONArray receivers = new JSONArray();//分账参数json |
|
|
|
EnumPayWay enumPayWay = EnumPayWay.getEnum(payOrder.getPayVendor()); |
|
|
|
EnumAppPlat enumPlat = enumPayWay.getPlat(); |
|
|
|
@@ -216,113 +188,85 @@ public class WxProfitSharingOrderServiceImpl implements WxProfitSharingOrderServ |
|
|
|
}else{ |
|
|
|
wxComposeChildOrderShare = payOrder.getSingleChildOrderShare(); |
|
|
|
} |
|
|
|
wxComposeChildOrderShare.setCpsCommission(cpsCommission); |
|
|
|
|
|
|
|
//官方手续费---千6 |
|
|
|
int realRate = serviceFeeService.getRealRate(payAccount); |
|
|
|
int realRateAmount = PayUtils.getPayRate(wxComposeChildOrderShare.getRealPayMent(), realRate, true); |
|
|
|
wxComposeChildOrderShare.setRealRateAmount(realRateAmount); |
|
|
|
|
|
|
|
//官方平台抽佣 |
|
|
|
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()) |
|
|
|
&& EnumYesOrNo.YES.getCode().equals(payAccount.getIsCommission())){ |
|
|
|
//销售抽点+系统抽点 |
|
|
|
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(), sellCommission, false); |
|
|
|
wxComposeChildOrderShare.setSellerAmount(sellerAmount); |
|
|
|
boolean isSeller = false; |
|
|
|
if(sellerAmount > 0){ |
|
|
|
WxProfitSharingReceiver receiver = getByMerchantAdmin(sharingOrder,payShareAdapterService,wxComposeChildOrderShare.getMerchantId(),EnumMerchantAdmin.PRIVATE_SELL,payOrder.getTtPayWay(), payOrder.getMchType()); |
|
|
|
if(receiver != null){ |
|
|
|
try{ |
|
|
|
//处理所有的佣金 |
|
|
|
boolean flag = serviceFeeService.handleShareServiceAmount(cAppInfo, payAccount, payOrder,wxComposeChildOrderShare); |
|
|
|
if(!flag){ |
|
|
|
throw new MallinkException(ErrorCode.PROFIT_SHARING_REQUEST_FAILED.getCode(),"未获取到服务费"); |
|
|
|
} |
|
|
|
//微信缺少流程(分账帐号绑定) 无法抽成 |
|
|
|
if(EnumYesOrNo.YES.getCode().equals(payAccount.getIsCommission())){ |
|
|
|
//系统 |
|
|
|
if(wxComposeChildOrderShare.getSystemAmount() > 0){ |
|
|
|
WxProfitSharingReceiver receiver = getByMerchantAdmin(sharingOrder,payShareAdapterService,wxComposeChildOrderShare.getMerchantId(),EnumMerchantAdmin.PRIVATE_SYSTEM,payOrder.getTtPayWay(), payOrder.getMchType()); |
|
|
|
if(receiver == null){ |
|
|
|
throw new MallinkException(ErrorCode.PROFIT_SHARING_REQUEST_FAILED.getCode(),"未获取到系统帐号2"); |
|
|
|
} |
|
|
|
JSONObject jo = new JSONObject(); |
|
|
|
jo.put("type",EnumProfitPaymentReceiverType.getEnum(receiver.getReceiverType()).getMessage()); |
|
|
|
jo.put("account",receiver.getReceiverAccount()); |
|
|
|
jo.put("amount", sellerAmount); |
|
|
|
jo.put("amount", wxComposeChildOrderShare.getSystemAmount()); |
|
|
|
jo.put("merchantId",receiver.getMerchantId()); |
|
|
|
jo.put("bTenantId",receiver.getTenantId()); |
|
|
|
jo.put("description",receiver.getId()); |
|
|
|
jo.put("isPrivate",EnumYesOrNo.YES.getCode()); |
|
|
|
receivers.add(jo); |
|
|
|
}else{ |
|
|
|
isSeller = true; |
|
|
|
} |
|
|
|
} |
|
|
|
//系统抽成 |
|
|
|
// int systemAmount = PayUtils.getPayRate(wxComposeChildOrderShare.getRealPayMent(), payAccount.getSystemRate(), false); |
|
|
|
int systemAmount = selSysAmount - sellerAmount; |
|
|
|
wxComposeChildOrderShare.setSystemAmount(systemAmount); |
|
|
|
if(isSeller){//未找到销售帐号时转入到系统帐号中 |
|
|
|
systemAmount += sellerAmount; |
|
|
|
} |
|
|
|
boolean isSystem = false; |
|
|
|
if(systemAmount > 0){ |
|
|
|
WxProfitSharingReceiver receiver = getByMerchantAdmin(sharingOrder,payShareAdapterService,wxComposeChildOrderShare.getMerchantId(),EnumMerchantAdmin.PRIVATE_SYSTEM,payOrder.getTtPayWay(), payOrder.getMchType()); |
|
|
|
if(receiver != null){ |
|
|
|
//销售 |
|
|
|
if(wxComposeChildOrderShare.getSellerAmount() > 0){ |
|
|
|
WxProfitSharingReceiver receiver = getByMerchantAdmin(sharingOrder,payShareAdapterService,wxComposeChildOrderShare.getMerchantId(),EnumMerchantAdmin.PRIVATE_SELL,payOrder.getTtPayWay(), payOrder.getMchType()); |
|
|
|
if(receiver == null){ |
|
|
|
throw new MallinkException(ErrorCode.PROFIT_SHARING_REQUEST_FAILED.getCode(),"未获取到系统帐号3"); |
|
|
|
} |
|
|
|
JSONObject jo = new JSONObject(); |
|
|
|
jo.put("type",EnumProfitPaymentReceiverType.getEnum(receiver.getReceiverType()).getMessage()); |
|
|
|
jo.put("account",receiver.getReceiverAccount()); |
|
|
|
jo.put("amount", systemAmount); |
|
|
|
jo.put("amount", wxComposeChildOrderShare.getSellerAmount()); |
|
|
|
jo.put("merchantId",receiver.getMerchantId()); |
|
|
|
jo.put("bTenantId",receiver.getTenantId()); |
|
|
|
jo.put("description",receiver.getId()); |
|
|
|
jo.put("isPrivate",EnumYesOrNo.YES.getCode()); |
|
|
|
receivers.add(jo); |
|
|
|
}else{ |
|
|
|
isSystem = true; |
|
|
|
} |
|
|
|
} |
|
|
|
//总分佣 |
|
|
|
int mallRate = getMallSumRate(payOrder,wxComposeChildOrderShare.getOrderId()); |
|
|
|
int serviceAmount = PayUtils.getPayRate(wxComposeChildOrderShare.getRealPayMent(), mallRate, true); |
|
|
|
wxComposeChildOrderShare.setServiceAmount(serviceAmount); |
|
|
|
//商场分成 |
|
|
|
int mallAmount = wxComposeChildOrderShare.getRateAmount(); |
|
|
|
if(isSystem){//未找到系统帐号时转入商管商户中 |
|
|
|
mallAmount += systemAmount; |
|
|
|
} |
|
|
|
boolean isMall = false; |
|
|
|
if(mallAmount > 0){ |
|
|
|
WxProfitSharingReceiver receiver = getByMerchantAdmin(sharingOrder,payShareAdapterService,wxComposeChildOrderShare.getMerchantId(),EnumMerchantAdmin.PUBLIC_ADMIN,payOrder.getTtPayWay(), payOrder.getMchType()); |
|
|
|
if(receiver != null){ |
|
|
|
//商管 |
|
|
|
if(wxComposeChildOrderShare.getRateAmount() > 0){ |
|
|
|
WxProfitSharingReceiver receiver = getByMerchantAdmin(sharingOrder,payShareAdapterService,wxComposeChildOrderShare.getMerchantId(),EnumMerchantAdmin.PUBLIC_ADMIN,payOrder.getTtPayWay(), payOrder.getMchType()); |
|
|
|
if(receiver == null){ |
|
|
|
throw new MallinkException(ErrorCode.PROFIT_SHARING_REQUEST_FAILED.getCode(),"未获取到商管帐号"); |
|
|
|
} |
|
|
|
JSONObject jo = new JSONObject(); |
|
|
|
jo.put("type",EnumProfitPaymentReceiverType.getEnum(receiver.getReceiverType()).getMessage()); |
|
|
|
jo.put("account",receiver.getReceiverAccount()); |
|
|
|
jo.put("amount", mallAmount); |
|
|
|
jo.put("amount", wxComposeChildOrderShare.getRateAmount()); |
|
|
|
jo.put("merchantId",receiver.getMerchantId()); |
|
|
|
jo.put("bTenantId",receiver.getTenantId()); |
|
|
|
jo.put("description",receiver.getId()); |
|
|
|
jo.put("isPrivate",EnumYesOrNo.YES.getCode()); |
|
|
|
receivers.add(jo); |
|
|
|
}else{ |
|
|
|
isMall = true; |
|
|
|
} |
|
|
|
} |
|
|
|
if(isMall){ |
|
|
|
surplus += mallAmount; |
|
|
|
} |
|
|
|
}else{ |
|
|
|
wxComposeChildOrderShare.setServiceAmount(null); |
|
|
|
|
|
|
|
}catch(Exception e){ |
|
|
|
WxProfitSharingOrder updSharingOrder = new WxProfitSharingOrder(); |
|
|
|
updSharingOrder.updateTenantInfo(sharingOrder); |
|
|
|
updSharingOrder.setId(sharingOrder.getId()); |
|
|
|
updSharingOrder.setSharingStatus(EnumProfitSharingOrderStatus.PROFIT_SHARING_APPLY_FAILED.getCode()); |
|
|
|
updSharingOrder.setErrorMsg(e.getMessage()); |
|
|
|
updSharingOrder.setUpdateTime(currentDate); |
|
|
|
wxProfitSharingOrderMapper.updateById(updSharingOrder); |
|
|
|
return new ResultData(ErrorCode.PROFIT_SHARING_REQUEST_FAILED.getCode(),e.getMessage()); |
|
|
|
} |
|
|
|
|
|
|
|
//商户所得 |
|
|
|
int shareAmount = wxComposeChildOrderShare.getShareAmount(); |
|
|
|
|
|
|
|
boolean isCallSharing = false;//是否调用分账 |
|
|
|
boolean isCreateSubsidy = false;//是否需要记账 |
|
|
|
boolean isSharingResult = false;//是否需要记录Result |
|
|
|
boolean isSharingResult = false;//是否需要记录Result 解冻给收款方 |
|
|
|
if(EnumPayWay.PAY_WAY_WECHAT.getCode().equals(payOrder.getPayVendor()) |
|
|
|
&& DateUtils.daysBetween(payOrder.getCreateTime(),currentDate) > 30){ |
|
|
|
isCallSharing = false; |
|
|
|
if(EnumPayShare.YES.getCode().equals(payOrder.getShare())){ |
|
|
|
if(!sharingOrder.getMerchantId().equals(wxComposeChildOrderShare.getMerchantId())){ |
|
|
|
isCreateSubsidy = true; |
|
|
|
} |
|
|
|
isSharingResult = true; |
|
|
|
@@ -356,9 +300,11 @@ public class WxProfitSharingOrderServiceImpl implements WxProfitSharingOrderServ |
|
|
|
receivers.add(jo); |
|
|
|
}else if(EnumPayMchType.DIRECT.getCode().equals(payOrder.getMchType()) |
|
|
|
&& !sharingOrder.getMerchantId().equals(wxComposeChildOrderShare.getMerchantId())){ |
|
|
|
//微信 直连 多商户 分不了账 记账 |
|
|
|
isCreateSubsidy = true; |
|
|
|
isSharingResult = true; |
|
|
|
}else{ |
|
|
|
//总分不分账 已经记过账了 |
|
|
|
isSharingResult = true; |
|
|
|
} |
|
|
|
} |
|
|
|
@@ -413,7 +359,6 @@ public class WxProfitSharingOrderServiceImpl implements WxProfitSharingOrderServ |
|
|
|
|
|
|
|
if(isCreateSubsidy){ |
|
|
|
try { |
|
|
|
// 微信超过30天无法分账的, |
|
|
|
WxOrder order = wxOrderMapper.selectById(sharingOrder.getSingleOrderId(), sharingOrder.getTenantId()); |
|
|
|
wxCouponOrderService.recordAfterVerified(order, merchant); |
|
|
|
} catch (Exception e) { |
|
|
|
@@ -422,13 +367,12 @@ 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", sharingSubsidyAmount); |
|
|
|
jo.put("amount", shareAmount); |
|
|
|
jo.put("merchantId",0); |
|
|
|
jo.put("bTenantId",payOrder.getTenantId()); |
|
|
|
jo.put("description",0); |
|
|
|
@@ -440,13 +384,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", sharingSubsidyAmount); |
|
|
|
jo.put("amount", shareAmount); |
|
|
|
jo.put("merchantId",receiver.getMerchantId()); |
|
|
|
jo.put("bTenantId",receiver.getTenantId()); |
|
|
|
jo.put("description",receiver.getId()); |
|
|
|
}else{ |
|
|
|
jo.put("account",wxComposeChildOrderShare.getMerchantUid()); |
|
|
|
jo.put("amount", sharingSubsidyAmount); |
|
|
|
jo.put("amount", shareAmount); |
|
|
|
jo.put("merchantId",wxComposeChildOrderShare.getMerchantId()); |
|
|
|
jo.put("bTenantId",payOrder.getTenantId()); |
|
|
|
jo.put("description",0); |
|
|
|
|