|
@@ -17,11 +17,11 @@ import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
|
-import java.math.BigDecimal;
|
|
|
|
|
import java.util.Date;
|
|
import java.util.Date;
|
|
|
import java.util.HashMap;
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
|
|
|
+import java.util.Objects;
|
|
|
import java.util.Random;
|
|
import java.util.Random;
|
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
@@ -30,10 +30,6 @@ public class CommissionService {
|
|
|
|
|
|
|
|
private static final Logger log = LoggerFactory.getLogger(CommissionService.class);
|
|
private static final Logger log = LoggerFactory.getLogger(CommissionService.class);
|
|
|
|
|
|
|
|
- // 产品利润佣金提成比例(已废弃,改用 sys_config commission_product_profit_share)
|
|
|
|
|
- // 保留为静态备用值
|
|
|
|
|
- private static final BigDecimal PROFIT_COMMISSION_RATE = new BigDecimal("0.30");
|
|
|
|
|
-
|
|
|
|
|
@Resource
|
|
@Resource
|
|
|
private UserMapper userMapper;
|
|
private UserMapper userMapper;
|
|
|
|
|
|
|
@@ -52,21 +48,9 @@ public class CommissionService {
|
|
|
// ==================== 工具方法 ====================
|
|
// ==================== 工具方法 ====================
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * 从系统配置获取bps费率并转为BigDecimal
|
|
|
|
|
- * 如 2000bps = 0.20 (20%)
|
|
|
|
|
- */
|
|
|
|
|
- private BigDecimal getRateFromConfig(String key, int defaultBps) {
|
|
|
|
|
- String val = sysConfigService.getValue(key);
|
|
|
|
|
- if (val == null) {
|
|
|
|
|
- return BigDecimal.valueOf(defaultBps).divide(new BigDecimal("10000"));
|
|
|
|
|
- }
|
|
|
|
|
- return BigDecimal.valueOf(Long.parseLong(val)).divide(new BigDecimal("10000"));
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * 从系统配置获取bps整数值
|
|
|
|
|
|
|
+ * 从系统配置获取bps整数值(如 2000 = 20%)
|
|
|
*/
|
|
*/
|
|
|
- private int getIntConfig(String key, int defaultValue) {
|
|
|
|
|
|
|
+ private int getRateBps(String key, int defaultValue) {
|
|
|
String val = sysConfigService.getValue(key);
|
|
String val = sysConfigService.getValue(key);
|
|
|
if (val == null) {
|
|
if (val == null) {
|
|
|
return defaultValue;
|
|
return defaultValue;
|
|
@@ -145,10 +129,10 @@ public class CommissionService {
|
|
|
LambdaQueryWrapper<CommissionRecord> wrapper = new LambdaQueryWrapper<CommissionRecord>()
|
|
LambdaQueryWrapper<CommissionRecord> wrapper = new LambdaQueryWrapper<CommissionRecord>()
|
|
|
.eq(CommissionRecord::getReferrerId, userId)
|
|
.eq(CommissionRecord::getReferrerId, userId)
|
|
|
.eq(CommissionRecord::getStatus, "settled");
|
|
.eq(CommissionRecord::getStatus, "settled");
|
|
|
- BigDecimal total = commissionRecordMapper.selectList(wrapper).stream()
|
|
|
|
|
|
|
+ Integer total = commissionRecordMapper.selectList(wrapper).stream()
|
|
|
.map(CommissionRecord::getCommissionAmount)
|
|
.map(CommissionRecord::getCommissionAmount)
|
|
|
- .filter(a -> a != null)
|
|
|
|
|
- .reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
|
|
|
|
+ .filter(Objects::nonNull)
|
|
|
|
|
+ .reduce(0, Integer::sum);
|
|
|
dto.setTotalEarnings(total);
|
|
dto.setTotalEarnings(total);
|
|
|
return dto;
|
|
return dto;
|
|
|
}
|
|
}
|
|
@@ -160,7 +144,7 @@ public class CommissionService {
|
|
|
* 内部委托给settleTwoLevel实现L1+L2佣金
|
|
* 内部委托给settleTwoLevel实现L1+L2佣金
|
|
|
*/
|
|
*/
|
|
|
public void settle(Long orderId, String orderType, Long buyerId,
|
|
public void settle(Long orderId, String orderType, Long buyerId,
|
|
|
- BigDecimal orderAmount, Long productId) {
|
|
|
|
|
|
|
+ Integer orderAmount, Long productId) {
|
|
|
settleTwoLevel(orderId, orderType, buyerId, orderAmount, productId);
|
|
settleTwoLevel(orderId, orderType, buyerId, orderAmount, productId);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -168,13 +152,13 @@ public class CommissionService {
|
|
|
* 两级佣金结算(L1+L2)
|
|
* 两级佣金结算(L1+L2)
|
|
|
* - L1: 买家的直接推荐人获得佣金
|
|
* - L1: 买家的直接推荐人获得佣金
|
|
|
* - L2: 如果L1推荐人也有推荐人,且订单类型为membership,L2获得佣金
|
|
* - L2: 如果L1推荐人也有推荐人,且订单类型为membership,L2获得佣金
|
|
|
- * - 佣金费率从sys_config动态读取
|
|
|
|
|
|
|
+ * - 佣金费率从sys_config动态读取(bps)
|
|
|
* - 默认状态为pending,settledAt为7天后
|
|
* - 默认状态为pending,settledAt为7天后
|
|
|
*/
|
|
*/
|
|
|
public void settleTwoLevel(Long orderId, String orderType, Long buyerId,
|
|
public void settleTwoLevel(Long orderId, String orderType, Long buyerId,
|
|
|
- BigDecimal orderAmount, Long productId) {
|
|
|
|
|
|
|
+ Integer orderAmount, Long productId) {
|
|
|
try {
|
|
try {
|
|
|
- if (buyerId == null || orderAmount == null || orderAmount.compareTo(BigDecimal.ZERO) <= 0) {
|
|
|
|
|
|
|
+ if (buyerId == null || orderAmount == null || orderAmount <= 0) {
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -190,12 +174,12 @@ public class CommissionService {
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- BigDecimal l1Amount = BigDecimal.ZERO;
|
|
|
|
|
|
|
+ int l1Amount = 0;
|
|
|
String commissionType;
|
|
String commissionType;
|
|
|
|
|
|
|
|
if ("membership".equals(orderType)) {
|
|
if ("membership".equals(orderType)) {
|
|
|
- BigDecimal rate = getRateFromConfig("commission_member_l1_rate", 2000);
|
|
|
|
|
- l1Amount = orderAmount.multiply(rate);
|
|
|
|
|
|
|
+ int rateBps = getRateBps("commission_member_l1_rate", 2000);
|
|
|
|
|
+ l1Amount = orderAmount * rateBps / 10000;
|
|
|
commissionType = "member";
|
|
commissionType = "member";
|
|
|
} else {
|
|
} else {
|
|
|
// 非会员订单:只有FAMILY用户的推荐人能获得产品利润佣金
|
|
// 非会员订单:只有FAMILY用户的推荐人能获得产品利润佣金
|
|
@@ -204,54 +188,52 @@ public class CommissionService {
|
|
|
if (productId != null) {
|
|
if (productId != null) {
|
|
|
Product product = productMapper.selectById(productId);
|
|
Product product = productMapper.selectById(productId);
|
|
|
if (product != null && product.getProfitRate() != null) {
|
|
if (product != null && product.getProfitRate() != null) {
|
|
|
- BigDecimal profitRate = product.getProfitRate();
|
|
|
|
|
|
|
+ int profitRate = product.getProfitRate();
|
|
|
if (isFamily) {
|
|
if (isFamily) {
|
|
|
// FAMILY推荐人获取利润佣金
|
|
// FAMILY推荐人获取利润佣金
|
|
|
- BigDecimal profitShare = getRateFromConfig("commission_product_profit_share", 1000);
|
|
|
|
|
- l1Amount = orderAmount.multiply(profitRate)
|
|
|
|
|
- .divide(new BigDecimal("100"))
|
|
|
|
|
- .multiply(profitShare);
|
|
|
|
|
|
|
+ int profitShareBps = getRateBps("commission_product_profit_share", 1000);
|
|
|
|
|
+ l1Amount = orderAmount * profitRate / 100 * profitShareBps / 10000;
|
|
|
commissionType = "profit";
|
|
commissionType = "profit";
|
|
|
} else {
|
|
} else {
|
|
|
// FREE推荐人只获得member类型佣金(不计利润分成)
|
|
// FREE推荐人只获得member类型佣金(不计利润分成)
|
|
|
- l1Amount = BigDecimal.ZERO;
|
|
|
|
|
|
|
+ l1Amount = 0;
|
|
|
commissionType = "member";
|
|
commissionType = "member";
|
|
|
}
|
|
}
|
|
|
} else {
|
|
} else {
|
|
|
// 没有利润率的产品,只给FAMILY推荐人基础服务佣金
|
|
// 没有利润率的产品,只给FAMILY推荐人基础服务佣金
|
|
|
if (isFamily) {
|
|
if (isFamily) {
|
|
|
- BigDecimal serviceRate = getRateFromConfig("commission_service_rate", 1000);
|
|
|
|
|
- l1Amount = orderAmount.multiply(serviceRate);
|
|
|
|
|
|
|
+ int serviceRateBps = getRateBps("commission_service_rate", 1000);
|
|
|
|
|
+ l1Amount = orderAmount * serviceRateBps / 10000;
|
|
|
commissionType = "service";
|
|
commissionType = "service";
|
|
|
} else {
|
|
} else {
|
|
|
- l1Amount = BigDecimal.ZERO;
|
|
|
|
|
|
|
+ l1Amount = 0;
|
|
|
commissionType = "member";
|
|
commissionType = "member";
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
} else {
|
|
} else {
|
|
|
// 没有productId的非会员订单(如评估、套餐)
|
|
// 没有productId的非会员订单(如评估、套餐)
|
|
|
if (isFamily) {
|
|
if (isFamily) {
|
|
|
- BigDecimal serviceRate = getRateFromConfig("commission_service_rate", 1000);
|
|
|
|
|
- l1Amount = orderAmount.multiply(serviceRate);
|
|
|
|
|
|
|
+ int serviceRateBps = getRateBps("commission_service_rate", 1000);
|
|
|
|
|
+ l1Amount = orderAmount * serviceRateBps / 10000;
|
|
|
commissionType = "service";
|
|
commissionType = "service";
|
|
|
} else {
|
|
} else {
|
|
|
- l1Amount = BigDecimal.ZERO;
|
|
|
|
|
|
|
+ l1Amount = 0;
|
|
|
commissionType = "member";
|
|
commissionType = "member";
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 创建L1佣金记录(金额>0才创建)
|
|
// 创建L1佣金记录(金额>0才创建)
|
|
|
- if (l1Amount.compareTo(BigDecimal.ZERO) > 0) {
|
|
|
|
|
|
|
+ if (l1Amount > 0) {
|
|
|
createCommissionRecord(orderId, orderType, l1ReferrerId, buyerId,
|
|
createCommissionRecord(orderId, orderType, l1ReferrerId, buyerId,
|
|
|
- commissionType, orderAmount, BigDecimal.ZERO, l1Amount,
|
|
|
|
|
|
|
+ commissionType, orderAmount, 0, l1Amount,
|
|
|
1, "settled", new Date());
|
|
1, "settled", new Date());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 更新推荐人的累计佣金
|
|
// 更新推荐人的累计佣金
|
|
|
l1Referrer.setTotalCommissionEarned(
|
|
l1Referrer.setTotalCommissionEarned(
|
|
|
(l1Referrer.getTotalCommissionEarned() != null ? l1Referrer.getTotalCommissionEarned() : 0L)
|
|
(l1Referrer.getTotalCommissionEarned() != null ? l1Referrer.getTotalCommissionEarned() : 0L)
|
|
|
- + l1Amount.longValue());
|
|
|
|
|
|
|
+ + l1Amount);
|
|
|
userMapper.updateById(l1Referrer);
|
|
userMapper.updateById(l1Referrer);
|
|
|
|
|
|
|
|
log.info("L1佣金结算成功: orderId={}, referrerId={}, amount={}, level=1",
|
|
log.info("L1佣金结算成功: orderId={}, referrerId={}, amount={}, level=1",
|
|
@@ -262,17 +244,17 @@ public class CommissionService {
|
|
|
Long l2ReferrerId = l1Referrer.getReferrerId();
|
|
Long l2ReferrerId = l1Referrer.getReferrerId();
|
|
|
User l2Referrer = userMapper.selectById(l2ReferrerId);
|
|
User l2Referrer = userMapper.selectById(l2ReferrerId);
|
|
|
if (l2Referrer != null) {
|
|
if (l2Referrer != null) {
|
|
|
- BigDecimal l2Rate = getRateFromConfig("commission_member_l2_rate", 500);
|
|
|
|
|
- BigDecimal l2Amount = orderAmount.multiply(l2Rate);
|
|
|
|
|
|
|
+ int l2RateBps = getRateBps("commission_member_l2_rate", 500);
|
|
|
|
|
+ int l2Amount = orderAmount * l2RateBps / 10000;
|
|
|
|
|
|
|
|
- if (l2Amount.compareTo(BigDecimal.ZERO) > 0) {
|
|
|
|
|
|
|
+ if (l2Amount > 0) {
|
|
|
createCommissionRecord(orderId, orderType, l2ReferrerId, buyerId,
|
|
createCommissionRecord(orderId, orderType, l2ReferrerId, buyerId,
|
|
|
- "member", orderAmount, BigDecimal.ZERO, l2Amount,
|
|
|
|
|
|
|
+ "member", orderAmount, 0, l2Amount,
|
|
|
2, "settled", new Date());
|
|
2, "settled", new Date());
|
|
|
|
|
|
|
|
l2Referrer.setTotalCommissionEarned(
|
|
l2Referrer.setTotalCommissionEarned(
|
|
|
(l2Referrer.getTotalCommissionEarned() != null ? l2Referrer.getTotalCommissionEarned() : 0L)
|
|
(l2Referrer.getTotalCommissionEarned() != null ? l2Referrer.getTotalCommissionEarned() : 0L)
|
|
|
- + l2Amount.longValue());
|
|
|
|
|
|
|
+ + l2Amount);
|
|
|
userMapper.updateById(l2Referrer);
|
|
userMapper.updateById(l2Referrer);
|
|
|
|
|
|
|
|
// 更新L1推荐人的间接推荐人数
|
|
// 更新L1推荐人的间接推荐人数
|
|
@@ -295,8 +277,8 @@ public class CommissionService {
|
|
|
* 创建佣金记录
|
|
* 创建佣金记录
|
|
|
*/
|
|
*/
|
|
|
private void createCommissionRecord(Long orderId, String orderType, Long referrerId,
|
|
private void createCommissionRecord(Long orderId, String orderType, Long referrerId,
|
|
|
- Long buyerId, String commissionType, BigDecimal orderAmount,
|
|
|
|
|
- BigDecimal profitRate, BigDecimal commissionAmount,
|
|
|
|
|
|
|
+ Long buyerId, String commissionType, Integer orderAmount,
|
|
|
|
|
+ Integer profitRate, Integer commissionAmount,
|
|
|
Integer level, String status, Date settledAt) {
|
|
Integer level, String status, Date settledAt) {
|
|
|
CommissionRecord record = new CommissionRecord();
|
|
CommissionRecord record = new CommissionRecord();
|
|
|
record.setOrderId(orderId);
|
|
record.setOrderId(orderId);
|
|
@@ -323,27 +305,27 @@ public class CommissionService {
|
|
|
LambdaQueryWrapper<CommissionRecord> allWrapper = new LambdaQueryWrapper<CommissionRecord>()
|
|
LambdaQueryWrapper<CommissionRecord> allWrapper = new LambdaQueryWrapper<CommissionRecord>()
|
|
|
.eq(CommissionRecord::getReferrerId, userId)
|
|
.eq(CommissionRecord::getReferrerId, userId)
|
|
|
.ne(CommissionRecord::getStatus, "cancelled");
|
|
.ne(CommissionRecord::getStatus, "cancelled");
|
|
|
- BigDecimal totalCommission = commissionRecordMapper.selectList(allWrapper).stream()
|
|
|
|
|
- .map(r -> r.getCommissionAmount() != null ? r.getCommissionAmount() : BigDecimal.ZERO)
|
|
|
|
|
- .reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
|
|
|
|
+ Integer totalCommission = commissionRecordMapper.selectList(allWrapper).stream()
|
|
|
|
|
+ .mapToInt(r -> r.getCommissionAmount() != null ? r.getCommissionAmount() : 0)
|
|
|
|
|
+ .sum();
|
|
|
dto.setTotalCommission(totalCommission);
|
|
dto.setTotalCommission(totalCommission);
|
|
|
|
|
|
|
|
// 已结算(settled)
|
|
// 已结算(settled)
|
|
|
LambdaQueryWrapper<CommissionRecord> settledWrapper = new LambdaQueryWrapper<CommissionRecord>()
|
|
LambdaQueryWrapper<CommissionRecord> settledWrapper = new LambdaQueryWrapper<CommissionRecord>()
|
|
|
.eq(CommissionRecord::getReferrerId, userId)
|
|
.eq(CommissionRecord::getReferrerId, userId)
|
|
|
.eq(CommissionRecord::getStatus, "settled");
|
|
.eq(CommissionRecord::getStatus, "settled");
|
|
|
- BigDecimal settledAmount = commissionRecordMapper.selectList(settledWrapper).stream()
|
|
|
|
|
- .map(r -> r.getCommissionAmount() != null ? r.getCommissionAmount() : BigDecimal.ZERO)
|
|
|
|
|
- .reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
|
|
|
|
+ Integer settledAmount = commissionRecordMapper.selectList(settledWrapper).stream()
|
|
|
|
|
+ .mapToInt(r -> r.getCommissionAmount() != null ? r.getCommissionAmount() : 0)
|
|
|
|
|
+ .sum();
|
|
|
dto.setSettledAmount(settledAmount);
|
|
dto.setSettledAmount(settledAmount);
|
|
|
|
|
|
|
|
// 待结算(pending)
|
|
// 待结算(pending)
|
|
|
LambdaQueryWrapper<CommissionRecord> pendingWrapper = new LambdaQueryWrapper<CommissionRecord>()
|
|
LambdaQueryWrapper<CommissionRecord> pendingWrapper = new LambdaQueryWrapper<CommissionRecord>()
|
|
|
.eq(CommissionRecord::getReferrerId, userId)
|
|
.eq(CommissionRecord::getReferrerId, userId)
|
|
|
.eq(CommissionRecord::getStatus, "pending");
|
|
.eq(CommissionRecord::getStatus, "pending");
|
|
|
- BigDecimal pendingAmount = commissionRecordMapper.selectList(pendingWrapper).stream()
|
|
|
|
|
- .map(r -> r.getCommissionAmount() != null ? r.getCommissionAmount() : BigDecimal.ZERO)
|
|
|
|
|
- .reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
|
|
|
|
+ Integer pendingAmount = commissionRecordMapper.selectList(pendingWrapper).stream()
|
|
|
|
|
+ .mapToInt(r -> r.getCommissionAmount() != null ? r.getCommissionAmount() : 0)
|
|
|
|
|
+ .sum();
|
|
|
dto.setPendingAmount(pendingAmount);
|
|
dto.setPendingAmount(pendingAmount);
|
|
|
|
|
|
|
|
dto.setAvailableAmount(getAvailableAmount(userId));
|
|
dto.setAvailableAmount(getAvailableAmount(userId));
|
|
@@ -363,7 +345,7 @@ public class CommissionService {
|
|
|
/**
|
|
/**
|
|
|
* 获取可提现金额(已结算 - 已提现,排除cancelled)
|
|
* 获取可提现金额(已结算 - 已提现,排除cancelled)
|
|
|
*/
|
|
*/
|
|
|
- public BigDecimal getAvailableAmount(Long userId) {
|
|
|
|
|
|
|
+ public Integer getAvailableAmount(Long userId) {
|
|
|
// 已结算(settled + pending中已过settledAt的)
|
|
// 已结算(settled + pending中已过settledAt的)
|
|
|
LambdaQueryWrapper<CommissionRecord> availableWrapper = new LambdaQueryWrapper<CommissionRecord>()
|
|
LambdaQueryWrapper<CommissionRecord> availableWrapper = new LambdaQueryWrapper<CommissionRecord>()
|
|
|
.eq(CommissionRecord::getReferrerId, userId)
|
|
.eq(CommissionRecord::getReferrerId, userId)
|
|
@@ -373,13 +355,13 @@ public class CommissionService {
|
|
|
.or(i -> i.eq(CommissionRecord::getStatus, "pending")
|
|
.or(i -> i.eq(CommissionRecord::getStatus, "pending")
|
|
|
.isNotNull(CommissionRecord::getSettledAt)
|
|
.isNotNull(CommissionRecord::getSettledAt)
|
|
|
.le(CommissionRecord::getSettledAt, new Date())));
|
|
.le(CommissionRecord::getSettledAt, new Date())));
|
|
|
- BigDecimal available = commissionRecordMapper.selectList(availableWrapper).stream()
|
|
|
|
|
- .map(r -> r.getCommissionAmount() != null ? r.getCommissionAmount() : BigDecimal.ZERO)
|
|
|
|
|
- .reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
|
|
|
|
+ int available = commissionRecordMapper.selectList(availableWrapper).stream()
|
|
|
|
|
+ .mapToInt(r -> r.getCommissionAmount() != null ? r.getCommissionAmount() : 0)
|
|
|
|
|
+ .sum();
|
|
|
|
|
|
|
|
- BigDecimal withdrawn = getWithdrawnAmount(userId);
|
|
|
|
|
|
|
+ int withdrawn = getWithdrawnAmount(userId);
|
|
|
|
|
|
|
|
- return available.subtract(withdrawn).max(BigDecimal.ZERO);
|
|
|
|
|
|
|
+ return Math.max(available - withdrawn, 0);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -408,9 +390,9 @@ public class CommissionService {
|
|
|
LambdaQueryWrapper<CommissionRecord> teamWrapper = new LambdaQueryWrapper<CommissionRecord>()
|
|
LambdaQueryWrapper<CommissionRecord> teamWrapper = new LambdaQueryWrapper<CommissionRecord>()
|
|
|
.eq(CommissionRecord::getReferrerId, userId)
|
|
.eq(CommissionRecord::getReferrerId, userId)
|
|
|
.ne(CommissionRecord::getStatus, "cancelled");
|
|
.ne(CommissionRecord::getStatus, "cancelled");
|
|
|
- BigDecimal totalTeamCommission = commissionRecordMapper.selectList(teamWrapper).stream()
|
|
|
|
|
- .map(r -> r.getCommissionAmount() != null ? r.getCommissionAmount() : BigDecimal.ZERO)
|
|
|
|
|
- .reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
|
|
|
|
+ int totalTeamCommission = commissionRecordMapper.selectList(teamWrapper).stream()
|
|
|
|
|
+ .mapToInt(r -> r.getCommissionAmount() != null ? r.getCommissionAmount() : 0)
|
|
|
|
|
+ .sum();
|
|
|
stats.put("totalCommission", totalTeamCommission);
|
|
stats.put("totalCommission", totalTeamCommission);
|
|
|
|
|
|
|
|
return stats;
|
|
return stats;
|
|
@@ -430,9 +412,9 @@ public class CommissionService {
|
|
|
.ne(CommissionRecord::getStatus, "cancelled")
|
|
.ne(CommissionRecord::getStatus, "cancelled")
|
|
|
.ge(CommissionRecord::getCreatedAt, getStartOfDay(now))
|
|
.ge(CommissionRecord::getCreatedAt, getStartOfDay(now))
|
|
|
.le(CommissionRecord::getCreatedAt, now);
|
|
.le(CommissionRecord::getCreatedAt, now);
|
|
|
- BigDecimal todayCommission = commissionRecordMapper.selectList(todayWrapper).stream()
|
|
|
|
|
- .map(r -> r.getCommissionAmount() != null ? r.getCommissionAmount() : BigDecimal.ZERO)
|
|
|
|
|
- .reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
|
|
|
|
+ int todayCommission = commissionRecordMapper.selectList(todayWrapper).stream()
|
|
|
|
|
+ .mapToInt(r -> r.getCommissionAmount() != null ? r.getCommissionAmount() : 0)
|
|
|
|
|
+ .sum();
|
|
|
stats.put("todayCommission", todayCommission);
|
|
stats.put("todayCommission", todayCommission);
|
|
|
|
|
|
|
|
// 本月佣金
|
|
// 本月佣金
|
|
@@ -441,9 +423,9 @@ public class CommissionService {
|
|
|
.ne(CommissionRecord::getStatus, "cancelled")
|
|
.ne(CommissionRecord::getStatus, "cancelled")
|
|
|
.ge(CommissionRecord::getCreatedAt, getStartOfMonth(now))
|
|
.ge(CommissionRecord::getCreatedAt, getStartOfMonth(now))
|
|
|
.le(CommissionRecord::getCreatedAt, now);
|
|
.le(CommissionRecord::getCreatedAt, now);
|
|
|
- BigDecimal monthCommission = commissionRecordMapper.selectList(monthWrapper).stream()
|
|
|
|
|
- .map(r -> r.getCommissionAmount() != null ? r.getCommissionAmount() : BigDecimal.ZERO)
|
|
|
|
|
- .reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
|
|
|
|
+ int monthCommission = commissionRecordMapper.selectList(monthWrapper).stream()
|
|
|
|
|
+ .mapToInt(r -> r.getCommissionAmount() != null ? r.getCommissionAmount() : 0)
|
|
|
|
|
+ .sum();
|
|
|
stats.put("monthCommission", monthCommission);
|
|
stats.put("monthCommission", monthCommission);
|
|
|
|
|
|
|
|
// 累计佣金
|
|
// 累计佣金
|
|
@@ -458,14 +440,14 @@ public class CommissionService {
|
|
|
return stats;
|
|
return stats;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- private BigDecimal getWithdrawnAmount(Long userId) {
|
|
|
|
|
|
|
+ private Integer getWithdrawnAmount(Long userId) {
|
|
|
LambdaQueryWrapper<WithdrawalRequest> wrapper =
|
|
LambdaQueryWrapper<WithdrawalRequest> wrapper =
|
|
|
new LambdaQueryWrapper<WithdrawalRequest>()
|
|
new LambdaQueryWrapper<WithdrawalRequest>()
|
|
|
.eq(WithdrawalRequest::getUserId, userId)
|
|
.eq(WithdrawalRequest::getUserId, userId)
|
|
|
.eq(WithdrawalRequest::getStatus, "approved");
|
|
.eq(WithdrawalRequest::getStatus, "approved");
|
|
|
return withdrawalRequestMapper.selectList(wrapper).stream()
|
|
return withdrawalRequestMapper.selectList(wrapper).stream()
|
|
|
- .map(r -> r.getAmount() != null ? r.getAmount() : BigDecimal.ZERO)
|
|
|
|
|
- .reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
|
|
|
|
+ .mapToInt(r -> r.getAmount() != null ? r.getAmount() : 0)
|
|
|
|
|
+ .sum();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private Date getStartOfDay(Date date) {
|
|
private Date getStartOfDay(Date date) {
|