|
|
@@ -73,7 +73,8 @@ public class DelegationService {
|
|
|
Environment env,
|
|
|
TaskScheduler taskScheduler,
|
|
|
UserMoneyRecordRepo userMoneyRecordRepo,
|
|
|
- SaleBatchRepo saleBatchRepo) {
|
|
|
+ SaleBatchRepo saleBatchRepo,
|
|
|
+ UserBalanceService userBalanceService) {
|
|
|
this.delegationRepo = delegationRepo;
|
|
|
this.orderRepo = orderRepo;
|
|
|
this.sysConfigService = sysConfigService;
|
|
|
@@ -86,6 +87,7 @@ public class DelegationService {
|
|
|
this.taskScheduler = taskScheduler;
|
|
|
this.userMoneyRecordRepo = userMoneyRecordRepo;
|
|
|
this.saleBatchRepo = saleBatchRepo;
|
|
|
+ this.userBalanceService = userBalanceService;
|
|
|
}
|
|
|
|
|
|
public void payDelegationAlipay(Long userId, Long orderId, BigDecimal riseRate, String returnUrl, Model model) {
|
|
|
@@ -272,6 +274,8 @@ public class DelegationService {
|
|
|
if (finalPrice.compareTo(maxPrice) >= 0) {
|
|
|
BigDecimal splitProductPrice = finalPrice.subtract(splitPrice);
|
|
|
finalPrice = splitPrice;
|
|
|
+ BigDecimal capital1 = splitProductPrice.divide(riseRate.add(new BigDecimal(1)), 2, RoundingMode.HALF_UP);
|
|
|
+ BigDecimal premium1 = splitProductPrice.subtract(capital1);
|
|
|
|
|
|
Product product1 = productRepo.findFirstByUserIdNull()
|
|
|
.orElseThrow(new BusinessException("商品池库存不足,无法分裂"));
|
|
|
@@ -279,6 +283,8 @@ public class DelegationService {
|
|
|
product1.setReserve(false);
|
|
|
product1.setStatus(ProductStatus.SOLD_OUT);
|
|
|
product1.setCurrentPrice(splitProductPrice);
|
|
|
+ product1.setCapital(capital1);
|
|
|
+ product1.setPremium(premium1);
|
|
|
Order order = orderRepo.save(Order.builder()
|
|
|
.userId(userId)
|
|
|
.productId(product1.getId())
|
|
|
@@ -288,6 +294,7 @@ public class DelegationService {
|
|
|
.rated(false)
|
|
|
.paidTime(LocalDateTime.now())
|
|
|
.confirmTime(LocalDateTime.now())
|
|
|
+ .batchId(product.getBatchId())
|
|
|
.build());
|
|
|
Delegation delegation1 = delegationRepo.save(Delegation.builder()
|
|
|
.userId(userId)
|
|
|
@@ -295,16 +302,20 @@ public class DelegationService {
|
|
|
.sellerOrderId(order.getId())
|
|
|
.originalPrice(product1.getCurrentPrice())
|
|
|
.finalPrice(splitProductPrice)
|
|
|
+ .capital(capital1)
|
|
|
+ .premium(premium1)
|
|
|
.serviceCharge(BigDecimal.ZERO)
|
|
|
.riseRate(BigDecimal.ZERO)
|
|
|
.active(false)
|
|
|
.enabled(true)
|
|
|
+ .batchId(product.getBatchId())
|
|
|
.build());
|
|
|
product1.setDelegationId(delegation1.getId());
|
|
|
productRepo.save(product1);
|
|
|
activeDelegation(delegation1);
|
|
|
}
|
|
|
|
|
|
+ BigDecimal capital = finalPrice.divide(riseRate.add(new BigDecimal(1)), 2, RoundingMode.HALF_UP);
|
|
|
delegation = delegationRepo.save(Delegation.builder()
|
|
|
.sellerOrderId(orderId)
|
|
|
.productId(sellerOrder.getProductId())
|
|
|
@@ -312,9 +323,12 @@ public class DelegationService {
|
|
|
.serviceCharge(serviceCharge)
|
|
|
.originalPrice(sellerOrder.getTotalPrice())
|
|
|
.finalPrice(finalPrice)
|
|
|
+ .capital(capital)
|
|
|
+ .premium(finalPrice.subtract(capital))
|
|
|
.riseRate(riseRate)
|
|
|
.active(false)
|
|
|
.enabled(true)
|
|
|
+ .batchId(product.getBatchId())
|
|
|
.build());
|
|
|
product.setDelegationId(delegation.getId());
|
|
|
productRepo.save(product);
|
|
|
@@ -360,6 +374,8 @@ public class DelegationService {
|
|
|
orderRepo.save(order);
|
|
|
product.setOriginalPrice(product.getCurrentPrice());
|
|
|
product.setCurrentPrice(delegation.getFinalPrice());
|
|
|
+ product.setCapital(delegation.getCapital());
|
|
|
+ product.setPremium(delegation.getPremium());
|
|
|
product.setStatus(ProductStatus.IN_STOCK);
|
|
|
productRepo.save(product);
|
|
|
}
|