提成修改

This commit is contained in:
Jerry Yan 2025-03-06 15:08:05 +08:00
parent d95e7e45fe
commit 125149cbfe
4 changed files with 30 additions and 6 deletions

View File

@ -10,6 +10,7 @@ import com.ycwl.basic.model.pc.order.entity.OrderEntity;
import com.ycwl.basic.model.pc.scenic.entity.ScenicConfigEntity;
import com.ycwl.basic.repository.OrderRepository;
import com.ycwl.basic.repository.ScenicRepository;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@ -19,9 +20,9 @@ import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.stream.Collectors;
@Slf4j
@Component
public class BrokerBiz {
@Autowired
@ -36,12 +37,15 @@ public class BrokerBiz {
private StatisticsMapper statisticsMapper;
public void processOrder(Long orderId) {
log.info("开始处理订单分佣订单ID{}", orderId);
OrderEntity order = orderRepository.getOrder(orderId);
if (order == null) {
log.info("订单不存在订单ID{}", orderId);
return;
}
ScenicConfigEntity scenicConfig = scenicRepository.getScenicConfig(order.getScenicId());
if (scenicConfig == null) {
log.info("景区不存在订单ID{}", orderId);
return;
}
int expireDay = 3;
@ -49,6 +53,7 @@ public class BrokerBiz {
expireDay = scenicConfig.getSampleStoreDay();
}
List<Long> brokerIdList = statisticsMapper.getBrokerIdListForUser(order.getMemberId(), DateUtil.offsetDay(DateUtil.beginOfDay(order.getCreateAt()), -expireDay), order.getCreateAt());
Long directBrokerId = brokerIdList.get(0);
List<BrokerRespVO> brokerInfoList = brokerIdList.stream().map(brokerId -> {
BrokerRespVO broker = brokerMapper.getById(brokerId);
if (broker == null) {
@ -62,7 +67,10 @@ public class BrokerBiz {
}
return broker;
}).filter(Objects::nonNull).collect(Collectors.toList());
boolean hasDirectBroker = brokerInfoList.stream().anyMatch(item -> directBrokerId.equals(item.getId()));
log.info("订单分佣订单ID{},佣金列表:{}", orderId, brokerInfoList);
if (brokerInfoList.isEmpty()) {
log.info("佣金列表为空订单ID{}", orderId);
return;
}
List<BrokerRecord> brokerRecordList = new ArrayList<>();
@ -90,21 +98,21 @@ public class BrokerBiz {
BrokerRespVO broker = brokerInfoList.get(0);
BigDecimal realRate = broker.getBrokerRate();
BigDecimal brokerPrice = order.getPayPrice().multiply(realRate).divide(BigDecimal.valueOf(100), 2, RoundingMode.DOWN);
AtomicBoolean isFirst = new AtomicBoolean(true);
// todo 需要计算实际提成比例
BigDecimal firstRate = scenicConfig.getBrokerDirectRate();
if (firstRate == null) {
firstRate = BigDecimal.ZERO;
}
BigDecimal secondRate = BigDecimal.valueOf(100).subtract(firstRate).divide(BigDecimal.valueOf(brokerInfoList.size() - 1), 2, RoundingMode.DOWN);
BigDecimal secondRate = BigDecimal.valueOf(100).subtract(firstRate).divide(BigDecimal.valueOf(hasDirectBroker ? (brokerInfoList.size() - 1) : brokerInfoList.size()), 2, RoundingMode.DOWN);
for (BrokerRespVO item : brokerInfoList) {
String reason = "多人提成:支付金额:" + order.getPayPrice() + "元,可提成比例:" + realRate + "%,可提成金额:" + brokerPrice + "";
BrokerRecord brokerRecord = new BrokerRecord();
brokerRecord.setBrokerId(item.getId());
brokerRecord.setOrderId(orderId);
BigDecimal interBrokerRate;
if (isFirst.get()) {
if (directBrokerId.equals(item.getId())) {
interBrokerRate = firstRate;
reason += "直接提成,";
brokerRecord.setDirectPrice(order.getPayPrice());
} else {
interBrokerRate = secondRate;
@ -117,9 +125,21 @@ public class BrokerBiz {
reason += "二次提成比例:" + interBrokerRate + "%,提成金额:" + interBrokerPrice + "";
brokerRecord.setReason(reason);
brokerRecordList.add(brokerRecord);
isFirst.set(false);
}
}
if (!hasDirectBroker) {
String reason = "提成:金额:" + order.getPayPrice() + "元:直接收益,但是不参与提成";
BrokerRespVO directBroker = brokerMapper.getById(directBrokerId);
BrokerRecord brokerRecord = new BrokerRecord();
brokerRecord.setBrokerId(directBroker.getId());
brokerRecord.setOrderId(orderId);
brokerRecord.setDirectPrice(order.getPayPrice());
brokerRecord.setOrderPrice(order.getPayPrice());
brokerRecord.setBrokerRate(BigDecimal.ZERO);
brokerRecord.setBrokerPrice(BigDecimal.ZERO);
brokerRecord.setReason(reason);
brokerRecordList.add(brokerRecord);
}
revokeOrder(orderId);
brokerRecordList.forEach(brokerRecord -> {
brokerRecordMapper.add(brokerRecord);

View File

@ -68,6 +68,8 @@ public class OrderBiz {
private ProfitSharingBiz profitSharingBiz;
@Autowired
private VideoTaskRepository videoTaskRepository;
@Autowired
private BrokerBiz brokerBiz;
public PriceObj queryPrice(Long scenicId, int goodsType, Long goodsId) {
PriceObj priceObj = new PriceObj();
@ -242,6 +244,7 @@ public class OrderBiz {
statisticsRecordAddReq.setMorphId(orderId);
statisticsMapper.addStatisticsRecord(statisticsRecordAddReq);
profitSharingBiz.processProfitSharing(order.getScenicId(), orderId, order.getPayPrice());
brokerBiz.processOrder(orderId);
}
public void cancelOrder(Long orderId) {

View File

@ -26,6 +26,7 @@ public class ProfitSharingBiz {
private ProfitSharingRecordMapper recordMapper;
public void processProfitSharing(Long scenicId, Long orderId, BigDecimal amount) {
log.info("开始处理分账,当前景区{},订单{},金额{}", scenicId, orderId, amount);
ProfitSharingConfig config = repository.getScenicConfig(scenicId);
if (config == null || config.getUsers() == null || config.getUsers().isEmpty()) {
return;

View File

@ -43,7 +43,7 @@
WHERE DATE_ADD(#{startTime}, INTERVAL (units.i + tens.i * 10 + hundreds.i * 100) DAY) &lt;= #{endTime}
) date_series
LEFT JOIN broker_record br ON DATE(br.create_time) = date_series.date AND br.broker_id = #{brokerId}
LEFT JOIN statistics s ON s.type = 20 and DATE(s.create_time) = date_series.date and s.morph_id = #{brokerId}
LEFT JOIN statistics s ON s.type = 20 and DATE(s.create_time) = br.create_time and s.morph_id = br.broker_id
GROUP BY date_series.date
ORDER BY date_series.date
</select>