提成修改
This commit is contained in:
parent
d95e7e45fe
commit
125149cbfe
@ -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.model.pc.scenic.entity.ScenicConfigEntity;
|
||||||
import com.ycwl.basic.repository.OrderRepository;
|
import com.ycwl.basic.repository.OrderRepository;
|
||||||
import com.ycwl.basic.repository.ScenicRepository;
|
import com.ycwl.basic.repository.ScenicRepository;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
@ -19,9 +20,9 @@ import java.util.ArrayList;
|
|||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
@Component
|
@Component
|
||||||
public class BrokerBiz {
|
public class BrokerBiz {
|
||||||
@Autowired
|
@Autowired
|
||||||
@ -36,12 +37,15 @@ public class BrokerBiz {
|
|||||||
private StatisticsMapper statisticsMapper;
|
private StatisticsMapper statisticsMapper;
|
||||||
|
|
||||||
public void processOrder(Long orderId) {
|
public void processOrder(Long orderId) {
|
||||||
|
log.info("开始处理订单分佣,订单ID:{}", orderId);
|
||||||
OrderEntity order = orderRepository.getOrder(orderId);
|
OrderEntity order = orderRepository.getOrder(orderId);
|
||||||
if (order == null) {
|
if (order == null) {
|
||||||
|
log.info("订单不存在,订单ID:{}", orderId);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ScenicConfigEntity scenicConfig = scenicRepository.getScenicConfig(order.getScenicId());
|
ScenicConfigEntity scenicConfig = scenicRepository.getScenicConfig(order.getScenicId());
|
||||||
if (scenicConfig == null) {
|
if (scenicConfig == null) {
|
||||||
|
log.info("景区不存在,订单ID:{}", orderId);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
int expireDay = 3;
|
int expireDay = 3;
|
||||||
@ -49,6 +53,7 @@ public class BrokerBiz {
|
|||||||
expireDay = scenicConfig.getSampleStoreDay();
|
expireDay = scenicConfig.getSampleStoreDay();
|
||||||
}
|
}
|
||||||
List<Long> brokerIdList = statisticsMapper.getBrokerIdListForUser(order.getMemberId(), DateUtil.offsetDay(DateUtil.beginOfDay(order.getCreateAt()), -expireDay), order.getCreateAt());
|
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 -> {
|
List<BrokerRespVO> brokerInfoList = brokerIdList.stream().map(brokerId -> {
|
||||||
BrokerRespVO broker = brokerMapper.getById(brokerId);
|
BrokerRespVO broker = brokerMapper.getById(brokerId);
|
||||||
if (broker == null) {
|
if (broker == null) {
|
||||||
@ -62,7 +67,10 @@ public class BrokerBiz {
|
|||||||
}
|
}
|
||||||
return broker;
|
return broker;
|
||||||
}).filter(Objects::nonNull).collect(Collectors.toList());
|
}).filter(Objects::nonNull).collect(Collectors.toList());
|
||||||
|
boolean hasDirectBroker = brokerInfoList.stream().anyMatch(item -> directBrokerId.equals(item.getId()));
|
||||||
|
log.info("订单分佣,订单ID:{},佣金列表:{}", orderId, brokerInfoList);
|
||||||
if (brokerInfoList.isEmpty()) {
|
if (brokerInfoList.isEmpty()) {
|
||||||
|
log.info("佣金列表为空,订单ID:{}", orderId);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
List<BrokerRecord> brokerRecordList = new ArrayList<>();
|
List<BrokerRecord> brokerRecordList = new ArrayList<>();
|
||||||
@ -90,21 +98,21 @@ public class BrokerBiz {
|
|||||||
BrokerRespVO broker = brokerInfoList.get(0);
|
BrokerRespVO broker = brokerInfoList.get(0);
|
||||||
BigDecimal realRate = broker.getBrokerRate();
|
BigDecimal realRate = broker.getBrokerRate();
|
||||||
BigDecimal brokerPrice = order.getPayPrice().multiply(realRate).divide(BigDecimal.valueOf(100), 2, RoundingMode.DOWN);
|
BigDecimal brokerPrice = order.getPayPrice().multiply(realRate).divide(BigDecimal.valueOf(100), 2, RoundingMode.DOWN);
|
||||||
AtomicBoolean isFirst = new AtomicBoolean(true);
|
|
||||||
// todo 需要计算实际提成比例
|
// todo 需要计算实际提成比例
|
||||||
BigDecimal firstRate = scenicConfig.getBrokerDirectRate();
|
BigDecimal firstRate = scenicConfig.getBrokerDirectRate();
|
||||||
if (firstRate == null) {
|
if (firstRate == null) {
|
||||||
firstRate = BigDecimal.ZERO;
|
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) {
|
for (BrokerRespVO item : brokerInfoList) {
|
||||||
String reason = "多人提成:支付金额:" + order.getPayPrice() + "元,可提成比例:" + realRate + "%,可提成金额:" + brokerPrice + ":";
|
String reason = "多人提成:支付金额:" + order.getPayPrice() + "元,可提成比例:" + realRate + "%,可提成金额:" + brokerPrice + ":";
|
||||||
BrokerRecord brokerRecord = new BrokerRecord();
|
BrokerRecord brokerRecord = new BrokerRecord();
|
||||||
brokerRecord.setBrokerId(item.getId());
|
brokerRecord.setBrokerId(item.getId());
|
||||||
brokerRecord.setOrderId(orderId);
|
brokerRecord.setOrderId(orderId);
|
||||||
BigDecimal interBrokerRate;
|
BigDecimal interBrokerRate;
|
||||||
if (isFirst.get()) {
|
if (directBrokerId.equals(item.getId())) {
|
||||||
interBrokerRate = firstRate;
|
interBrokerRate = firstRate;
|
||||||
|
reason += "直接提成,";
|
||||||
brokerRecord.setDirectPrice(order.getPayPrice());
|
brokerRecord.setDirectPrice(order.getPayPrice());
|
||||||
} else {
|
} else {
|
||||||
interBrokerRate = secondRate;
|
interBrokerRate = secondRate;
|
||||||
@ -117,9 +125,21 @@ public class BrokerBiz {
|
|||||||
reason += "二次提成比例:" + interBrokerRate + "%,提成金额:" + interBrokerPrice + "元";
|
reason += "二次提成比例:" + interBrokerRate + "%,提成金额:" + interBrokerPrice + "元";
|
||||||
brokerRecord.setReason(reason);
|
brokerRecord.setReason(reason);
|
||||||
brokerRecordList.add(brokerRecord);
|
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);
|
revokeOrder(orderId);
|
||||||
brokerRecordList.forEach(brokerRecord -> {
|
brokerRecordList.forEach(brokerRecord -> {
|
||||||
brokerRecordMapper.add(brokerRecord);
|
brokerRecordMapper.add(brokerRecord);
|
||||||
|
@ -68,6 +68,8 @@ public class OrderBiz {
|
|||||||
private ProfitSharingBiz profitSharingBiz;
|
private ProfitSharingBiz profitSharingBiz;
|
||||||
@Autowired
|
@Autowired
|
||||||
private VideoTaskRepository videoTaskRepository;
|
private VideoTaskRepository videoTaskRepository;
|
||||||
|
@Autowired
|
||||||
|
private BrokerBiz brokerBiz;
|
||||||
|
|
||||||
public PriceObj queryPrice(Long scenicId, int goodsType, Long goodsId) {
|
public PriceObj queryPrice(Long scenicId, int goodsType, Long goodsId) {
|
||||||
PriceObj priceObj = new PriceObj();
|
PriceObj priceObj = new PriceObj();
|
||||||
@ -242,6 +244,7 @@ public class OrderBiz {
|
|||||||
statisticsRecordAddReq.setMorphId(orderId);
|
statisticsRecordAddReq.setMorphId(orderId);
|
||||||
statisticsMapper.addStatisticsRecord(statisticsRecordAddReq);
|
statisticsMapper.addStatisticsRecord(statisticsRecordAddReq);
|
||||||
profitSharingBiz.processProfitSharing(order.getScenicId(), orderId, order.getPayPrice());
|
profitSharingBiz.processProfitSharing(order.getScenicId(), orderId, order.getPayPrice());
|
||||||
|
brokerBiz.processOrder(orderId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void cancelOrder(Long orderId) {
|
public void cancelOrder(Long orderId) {
|
||||||
|
@ -26,6 +26,7 @@ public class ProfitSharingBiz {
|
|||||||
private ProfitSharingRecordMapper recordMapper;
|
private ProfitSharingRecordMapper recordMapper;
|
||||||
|
|
||||||
public void processProfitSharing(Long scenicId, Long orderId, BigDecimal amount) {
|
public void processProfitSharing(Long scenicId, Long orderId, BigDecimal amount) {
|
||||||
|
log.info("开始处理分账,当前景区{},订单{},金额{}", scenicId, orderId, amount);
|
||||||
ProfitSharingConfig config = repository.getScenicConfig(scenicId);
|
ProfitSharingConfig config = repository.getScenicConfig(scenicId);
|
||||||
if (config == null || config.getUsers() == null || config.getUsers().isEmpty()) {
|
if (config == null || config.getUsers() == null || config.getUsers().isEmpty()) {
|
||||||
return;
|
return;
|
||||||
|
@ -43,7 +43,7 @@
|
|||||||
WHERE DATE_ADD(#{startTime}, INTERVAL (units.i + tens.i * 10 + hundreds.i * 100) DAY) <= #{endTime}
|
WHERE DATE_ADD(#{startTime}, INTERVAL (units.i + tens.i * 10 + hundreds.i * 100) DAY) <= #{endTime}
|
||||||
) date_series
|
) date_series
|
||||||
LEFT JOIN broker_record br ON DATE(br.create_time) = date_series.date AND br.broker_id = #{brokerId}
|
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
|
GROUP BY date_series.date
|
||||||
ORDER BY date_series.date
|
ORDER BY date_series.date
|
||||||
</select>
|
</select>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user