修改分润逻辑

This commit is contained in:
韩鹏辉 2023-07-06 14:22:04 +08:00
parent dfa5c6670f
commit f0174ef087
1 changed files with 48 additions and 12 deletions

View File

@ -1,14 +1,12 @@
package cn.pluss.platform.merchantProfit.impl;
import cn.hutool.core.util.ObjectUtil;
import cn.pluss.platform.constants.Constant;
import cn.pluss.platform.entity.*;
import cn.pluss.platform.enums.BstLevelCode;
import cn.pluss.platform.enums.UserRoleEnum;
import cn.pluss.platform.exception.MsgException;
import cn.pluss.platform.mapper.LevelMapper;
import cn.pluss.platform.mapper.MerchantBaseInfoMapper;
import cn.pluss.platform.mapper.MerchantProfitMapper;
import cn.pluss.platform.mapper.UserAppMapper;
import cn.pluss.platform.mapper.*;
import cn.pluss.platform.merchant.MerchantRateNewService;
import cn.pluss.platform.merchantProfit.MerchantProfitService;
import cn.pluss.platform.notice.NoticeService;
@ -132,14 +130,17 @@ public class MerchantProfitServiceImpl extends ServiceImpl<MerchantProfitMapper,
private void calcUserProfitV2(UserApp userApp, MerchantOrder order, String orderType) {
//2.0
Vector<MerchantProfit> profitList = new Vector<MerchantProfit>();
if (UserRoleEnum.SV2.getCode().equals(userApp.getRoleCode())) {
createUserSV2Profit(userApp, order, null, userApp, profitList, 1, orderType);
} else if (UserRoleEnum.ZY_BST.getCode().equals(userApp.getRoleCode())) {
createUserBstProfit(userApp, userApp, order, profitList, 1, BigDecimal.ZERO, orderType);
} else {
log.info("【分润V2.0】交易用户类型位置 创建分润结束", order.getOrderNumber());
return;
}
// if (UserRoleEnum.SV2.getCode().equals(userApp.getRoleCode())) {
// createUserSV2Profit(userApp, order, null, userApp, profitList, 1, orderType);
// } else if (UserRoleEnum.ZY_BST.getCode().equals(userApp.getRoleCode())) {
// createUserBstProfit(userApp, userApp, order, profitList, 1, BigDecimal.ZERO, orderType);
// } else {
// log.info("【分润V2.0】交易用户类型位置 创建分润结束", order.getOrderNumber());
// return;
// }
createUserV3Profit(order,order.getUserId().toString(),profitList,order.getRate());
if (!profitList.isEmpty()) {
log.info("【分润计算完成】开始批量插入分润数据,生成分润的订单编号:{},分润条数:{}", order.getOrderNumber(), profitList.size());
try {
@ -159,6 +160,41 @@ public class MerchantProfitServiceImpl extends ServiceImpl<MerchantProfitMapper,
}
}
@Autowired
UserPromotionMapper userPromotionMapper;
private void createUserV3Profit(MerchantOrder order,String userId,Vector<MerchantProfit> profits,BigDecimal nowRate){
UserPromotion userPromotion= userPromotionMapper.selectByUserId(userId);
if(ObjectUtil.isEmpty(userPromotion)){
log.error("订单号:{},分润结束,获取分润数为:{}",order.getOrderNumber(),profits.size());
return;
}
if("0".equals(userPromotion.getParentUserId())){
log.error("订单号:{} 父级为:{},父级类型:{},分润结束,获取分润数为:{},",order.getOrderNumber(),userPromotion.getParentUserId(),userPromotion.getTypeCode(),profits.size());
return;
}
BigDecimal profitRate = BigDecimal.ZERO;
if (nowRate.compareTo(new BigDecimal(userPromotion.getCurrentFee())) >= 0) {
profitRate = nowRate.subtract(new BigDecimal(userPromotion.getCurrentFee()));
nowRate = new BigDecimal(userPromotion.getCurrentFee());
}
UserApp nowUserApp = userAppMapper.selectByUserId(userId);
QueryWrapper<UserApp> queryWrapper=new QueryWrapper<>();
queryWrapper.eq("parentId",userPromotion.getParentUserId());
UserApp pUserApp=userAppMapper.selectOne(queryWrapper);
BigDecimal profitAmt = profitRate.divide(BigDecimal.valueOf(10000)).multiply(BigDecimal.valueOf(order.getConsumeFee())).setScale(4, BigDecimal.ROUND_DOWN);
MerchantProfit profit = new MerchantProfit(nowUserApp, pUserApp, order, profitAmt, profitRate, "1", "1");
profits.add(profit);
sendProfitMessage(pUserApp, profitAmt, order.getOrderNumber());
createUserV3Profit(order,userPromotion.getParentUserId(),profits,nowRate);
}
/**
* 创建2.0分润
*