修改退款去除分润逻辑

This commit is contained in:
韩鹏辉
2023-08-30 09:44:02 +08:00
parent 12eb6f7b5b
commit 2edec79f83
2 changed files with 92 additions and 35 deletions

View File

@@ -9,6 +9,7 @@ import cn.pluss.platform.merchantProfit.MerchantProfitService;
import cn.pluss.platform.notice.NoticeService; import cn.pluss.platform.notice.NoticeService;
import cn.pluss.platform.realFans.RealFansService; import cn.pluss.platform.realFans.RealFansService;
import cn.pluss.platform.user.impl.GeneralPushUtil; import cn.pluss.platform.user.impl.GeneralPushUtil;
import cn.pluss.platform.userAccount.impl.UserAccountServiceImpl;
import cn.pluss.platform.userApp.UserAppService; import cn.pluss.platform.userApp.UserAppService;
import cn.pluss.platform.userIntegral.UserIntegralService; import cn.pluss.platform.userIntegral.UserIntegralService;
import cn.pluss.platform.util.*; import cn.pluss.platform.util.*;
@@ -44,6 +45,9 @@ public class RealFansServiceImpl extends ServiceImpl<RealFansMapper, RealFans> i
@Autowired @Autowired
private GeneralPushUtil generalPushUtil; private GeneralPushUtil generalPushUtil;
@Autowired
UserAccountServiceImpl userAccountService;
@Override @Override
public void removeProfit(MerchantOrder order) { public void removeProfit(MerchantOrder order) {
if(ObjectUtil.isEmpty(order)){ if(ObjectUtil.isEmpty(order)){
@@ -59,6 +63,8 @@ public class RealFansServiceImpl extends ServiceImpl<RealFansMapper, RealFans> i
private void cancelUserProfitV2(MerchantOrder order) { private void cancelUserProfitV2(MerchantOrder order) {
Vector<MerchantProfit> profitList = new Vector<MerchantProfit>(); Vector<MerchantProfit> profitList = new Vector<MerchantProfit>();
Vector<UserAccount> userAccounts=new Vector<>();
Vector<UserAccountFlow> accountFlows=new Vector<>();
UserPromotion userPromotion= userPromotionMapper.selectByUserId(order.getUserId().toString()); UserPromotion userPromotion= userPromotionMapper.selectByUserId(order.getUserId().toString());
if(ObjectUtil.isEmpty(userPromotion)){ if(ObjectUtil.isEmpty(userPromotion)){
@@ -71,7 +77,7 @@ public class RealFansServiceImpl extends ServiceImpl<RealFansMapper, RealFans> i
return; return;
} }
createUserV3Profit(order,userPromotion.getParentUserId(),profitList,order.getRate().divide(BigDecimal.valueOf(100))); createUserV3Profit(order,userPromotion.getParentUserId(),profitList,userAccounts,accountFlows,order.getRate().divide(BigDecimal.valueOf(100)));
if (!profitList.isEmpty()) { if (!profitList.isEmpty()) {
log.info("【去除分润计算完成】开始批量插入分润数据,生成分润的订单编号:{},分润条数:{}", order.getOrderNumber(), profitList.size()); log.info("【去除分润计算完成】开始批量插入分润数据,生成分润的订单编号:{},分润条数:{}", order.getOrderNumber(), profitList.size());
@@ -95,46 +101,68 @@ public class RealFansServiceImpl extends ServiceImpl<RealFansMapper, RealFans> i
@Autowired @Autowired
UserPromotionMapper userPromotionMapper; UserPromotionMapper userPromotionMapper;
private void createUserV3Profit(MerchantOrder order,String userId,Vector<MerchantProfit> profits,BigDecimal nowRate){ private void createUserV3Profit(MerchantOrder order,String userId,Vector<MerchantProfit> profits,Vector<UserAccount> userAccounts,Vector<UserAccountFlow> flows,BigDecimal nowRate){
UserPromotion userPromotion= userPromotionMapper.selectByUserId(userId); UserPromotion userPromotion= userPromotionMapper.selectByUserId(userId);
if(ObjectUtil.isEmpty(userPromotion)){ if(ObjectUtil.isEmpty(userPromotion)){
log.error("订单号:{},分润结束,获取分润数为:{}",order.getOrderNumber(),profits.size()); log.error("订单号:{},分润结束,获取分润数为:{}",order.getOrderNumber(),profits.size());
return; return;
} }
// if("0".equals(userPromotion.getParentUserId())){ if(ObjectUtil.isEmpty(order.getRefundAmt())||N.egt(BigDecimal.ZERO,order.getRefundAmt())){
// log.error("订单号:{} 父级为:{},父级类型:{},分润结束,获取分润数为:{},",order.getOrderNumber(),userPromotion.getParentUserId(),userPromotion.getTypeCode(),profits.size()); log.error("退款金额为0 {},{}",order.getOrderNumber(),order.getRefundAmt());
// return; return;
// } }
if("MC".equals(userPromotion.getTypeCode())){ if("MC".equals(userPromotion.getTypeCode())){
createUserV3Profit(order,userPromotion.getParentUserId(),profits,new BigDecimal(userPromotion.getCurrentFee())); if("1".equals(userPromotion.getIsExtend())){
// if("1".equals(userPromotion.getIsExtend())||"2".equals(userPromotion.getIsExtend())){ userPromotion= getUserPromotion(Long.valueOf(userPromotion.getParentUserId()));
// BigDecimal profitRate = BigDecimal.ZERO;
// BigDecimal profitRate = BigDecimal.ZERO;
// if (nowRate.compareTo(new BigDecimal(userPromotion.getCurrentFee())) >= 0) {
// profitRate = nowRate.subtract(new BigDecimal(userPromotion.getCurrentFee())); if (nowRate.compareTo(new BigDecimal(userPromotion.getCurrentFee())) >= 0) {
// nowRate = new BigDecimal(userPromotion.getCurrentFee()); profitRate = nowRate.subtract(new BigDecimal(userPromotion.getCurrentFee()));
// }else { nowRate = new BigDecimal(userPromotion.getCurrentFee());
// return; }else {
// } return;
// }
// UserApp nowUserApp = userAppMapper.selectByUserId(userId);
// if(ObjectUtil.isEmpty(nowUserApp)){ UserApp nowUserApp = userAppMapper.selectByUserId(userPromotion.getUserId());
// log.error("订单号:{},分润结束,获取分润数为:{}",order.getOrderNumber(),profits.size()); if(ObjectUtil.isEmpty(nowUserApp)){
// return; log.error("订单号:{},分润结束,获取分润数为:{}",order.getOrderNumber(),profits.size());
// } return;
// }
// log.info("userId:{},rate:{},amount:{}",nowUserApp.getUserId(),profitRate,order.getConsumeFee());
// BigDecimal profitAmt = profitRate.divide(BigDecimal.valueOf(100)).multiply(BigDecimal.valueOf(order.getConsumeFee())).setScale(4, BigDecimal.ROUND_DOWN); log.info("userId:{},rate:{},amount:{}",nowUserApp.getUserId(),profitRate,order.getConsumeFee());
// MerchantProfit profit = new MerchantProfit(nowUserApp, nowUserApp, order, profitAmt, profitRate, "5", "1");
// profits.add(profit);
//// sendProfitMessage(nowUserApp, profitAmt, order.getOrderNumber());
// createUserV3Profit(order,userPromotion.getParentUserId(),profits,new BigDecimal(userPromotion.getCurrentFee())); BigDecimal profitAmt = profitRate.divide(BigDecimal.valueOf(100)).multiply(order.getRefundAmt()).setScale(4, BigDecimal.ROUND_DOWN);
//
// }else {
// createUserV3Profit(order,userPromotion.getParentUserId(),profits,new BigDecimal(userPromotion.getCurrentFee())); UserAccount userAccount= userAccountService.initUserAccount(nowUserApp.getUserId().intValue());
// } userAccount.setBalance(userAccount.getBalance().subtract(profitAmt));
userAccount.setUpdateTime(new Date());
UserAccountFlow flow=new UserAccountFlow();
flow.setUserId(nowUserApp.getUserId().intValue());
flow.setBizCode("103");
flow.setBizName("退款扣除收益");
flow.setAmount(profitAmt);
flow.setBalance(userAccount.getBalance());
flow.setCreateTime(new Date());
userAccounts.add(userAccount);
flows.add(flow);
MerchantProfit profit = new MerchantProfit(nowUserApp, nowUserApp, order, profitAmt.negate(), profitRate, "5", "1");
profits.add(profit);
// sendProfitMessage(nowUserApp, profitAmt, order.getOrderNumber());
createUserV3Profit(order,userPromotion.getParentUserId(),profits,userAccounts,flows,new BigDecimal(userPromotion.getCurrentFee()));
}else {
createUserV3Profit(order,userPromotion.getParentUserId(),profits,userAccounts,flows,new BigDecimal(userPromotion.getCurrentFee()));
}
}else { }else {
BigDecimal profitRate = BigDecimal.ZERO; BigDecimal profitRate = BigDecimal.ZERO;
@@ -154,16 +182,45 @@ public class RealFansServiceImpl extends ServiceImpl<RealFansMapper, RealFans> i
} }
log.info("userId:{},rate:{},amount:{}",nowUserApp.getUserId(),profitRate,order.getConsumeFee()); log.info("userId:{},rate:{},amount:{}",nowUserApp.getUserId(),profitRate,order.getConsumeFee());
BigDecimal profitAmt = profitRate.divide(BigDecimal.valueOf(100)).multiply(order.getRefundAmt()).setScale(4, BigDecimal.ROUND_DOWN); BigDecimal profitAmt = profitRate.divide(BigDecimal.valueOf(100)).multiply(order.getRefundAmt()).setScale(4, BigDecimal.ROUND_DOWN);
UserAccount userAccount= userAccountService.initUserAccount(nowUserApp.getUserId().intValue());
userAccount.setBalance(userAccount.getBalance().subtract(profitAmt));
userAccount.setUpdateTime(new Date());
UserAccountFlow flow=new UserAccountFlow();
flow.setUserId(nowUserApp.getUserId().intValue());
flow.setBizCode("103");
flow.setBizName("退款扣除收益");
flow.setAmount(profitAmt);
flow.setBalance(userAccount.getBalance());
flow.setCreateTime(new Date());
userAccounts.add(userAccount);
flows.add(flow);
MerchantProfit profit = new MerchantProfit(nowUserApp,nowUserApp , order, profitAmt.abs().negate(), profitRate, "5", "1"); MerchantProfit profit = new MerchantProfit(nowUserApp,nowUserApp , order, profitAmt.abs().negate(), profitRate, "5", "1");
profits.add(profit); profits.add(profit);
// sendProfitMessage(nowUserApp, profitAmt, order.getOrderNumber()); // sendProfitMessage(nowUserApp, profitAmt, order.getOrderNumber());
createUserV3Profit(order,userPromotion.getParentUserId(),profits,new BigDecimal(userPromotion.getCurrentFee())); createUserV3Profit(order,userPromotion.getParentUserId(),profits,userAccounts,flows,order.getRefundAmt());
} }
} }
private UserPromotion getUserPromotion(Long userId){
UserPromotion userPromotion= userPromotionMapper.selectByPrimaryKey(userId);
if(ObjectUtil.isNotEmpty(userPromotion)&&"MC".equals(userPromotion.getTypeCode())){
getUserPromotion(Long.valueOf(userPromotion.getParentUserId()));
}
return userPromotion;
}
@Override @Override
public void removeProfit(MerchantOrder order, BigDecimal refundAmt,BigDecimal useRefundAmt) { public void removeProfit(MerchantOrder order, BigDecimal refundAmt,BigDecimal useRefundAmt) {
BigDecimal consumeFee = BigDecimal.valueOf(order.getConsumeFee()); BigDecimal consumeFee = BigDecimal.valueOf(order.getConsumeFee());

View File

@@ -472,7 +472,7 @@ public class SxfPayServiceImpl implements SxfPayService {
e.printStackTrace(); e.printStackTrace();
} }
if (!flag) { if (!flag) {
log.error("==============>【随行付】退款订单查询签名校验失败{}<=================="); log.error("==============>【随行付】bb{}<==================");
result.put("code", ResultCode.FAIL.code()); result.put("code", ResultCode.FAIL.code());
result.put("msg", "签名校验失败"); result.put("msg", "签名校验失败");
return result; return result;