|
@@ -24,6 +24,8 @@ import javax.annotation.Resource;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.math.RoundingMode;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
@@ -149,25 +151,41 @@ public class OrderCalcServiceImpl implements OrderCalcService {
|
|
|
PtProfitDO ptProfitDO = ptProfitService.getPtProfit();
|
|
|
tradeOrderDO.forEach(k -> {
|
|
|
|
|
|
+ BigDecimal price = new BigDecimal(String.valueOf(k.getPrice()));
|
|
|
+ BigDecimal costPrice = new BigDecimal(String.valueOf(k.getCostPrice()));
|
|
|
+ BigDecimal productCount = new BigDecimal(String.valueOf(k.getProductCount()));
|
|
|
+
|
|
|
// 计算
|
|
|
// 计算利润: (价格 - 成本价格) * 产品数量
|
|
|
- Integer profit = (k.getPrice() - k.getCostPrice()) * k.getProductCount();
|
|
|
+// Integer profit = (k.getPrice() - k.getCostPrice()) * k.getProductCount();
|
|
|
+
|
|
|
+ BigDecimal profit = price.subtract(costPrice).multiply(productCount);
|
|
|
+
|
|
|
// 计算毛利: 利润 * 0.38
|
|
|
- Integer grossProfit = profit * orderPercentageDO.getGrossProfitPerc();
|
|
|
+ BigDecimal grossProfit = profit.multiply(new BigDecimal(String.valueOf(orderPercentageDO.getGrossProfitPerc()))).setScale(4, RoundingMode.DOWN);
|
|
|
+
|
|
|
// 计算推荐人额度: 毛利 * 0.35
|
|
|
- Integer ancestorQuota = grossProfit * orderPercentageDO.getGrossProfitUserQuotaPerc();
|
|
|
+ BigDecimal ancestorQuota = grossProfit.multiply(new BigDecimal(orderPercentageDO.getGrossProfitUserQuotaPerc())).setScale(4, RoundingMode.DOWN);
|
|
|
+
|
|
|
// 计算直推人额度: 毛利 * 0.35
|
|
|
- Integer descendantQuota = grossProfit * orderPercentageDO.getGrossProfitAncestorQuotaPerc();
|
|
|
+ BigDecimal descendantQuota = grossProfit.multiply(new BigDecimal(orderPercentageDO.getGrossProfitAncestorQuotaPerc())).setScale(4, RoundingMode.DOWN);
|
|
|
+
|
|
|
// 计算合赢奖: 毛利 * 0.08
|
|
|
- Integer bonusQuota = grossProfit * orderPercentageDO.getGrossProfitBonusQuotaPerc();
|
|
|
+ BigDecimal bonusQuota = grossProfit.multiply(new BigDecimal(orderPercentageDO.getGrossProfitBonusQuotaPerc())).setScale(4, RoundingMode.DOWN);
|
|
|
+
|
|
|
// 计算平台收益: 毛利 * 0.22
|
|
|
- Integer platformQuota = grossProfit * orderPercentageDO.getGrossProfitPlatformQuotaPerc();
|
|
|
+ BigDecimal platformQuota = grossProfit.multiply(new BigDecimal(orderPercentageDO.getGrossProfitPlatformQuotaPerc())).setScale(4, RoundingMode.DOWN);
|
|
|
|
|
|
// 计算当前下单人的毛利的三倍
|
|
|
- Integer highQuota = grossProfit * THREE;
|
|
|
-
|
|
|
-
|
|
|
+ BigDecimal highQuota = grossProfit.multiply(new BigDecimal("3")).setScale(4, RoundingMode.DOWN);
|
|
|
|
|
|
+ // 乘以 10000 并转换为整数
|
|
|
+ int grossProfitInt = grossProfit.multiply(new BigDecimal("10000")).setScale(0, RoundingMode.DOWN).intValueExact();
|
|
|
+ int ancestorQuotaInt = ancestorQuota.multiply(new BigDecimal("10000")).setScale(0, RoundingMode.DOWN).intValueExact();
|
|
|
+ int descendantQuotaInt = descendantQuota.multiply(new BigDecimal("10000")).setScale(0, RoundingMode.DOWN).intValueExact();
|
|
|
+ int bonusQuotaInt = bonusQuota.multiply(new BigDecimal("10000")).setScale(0, RoundingMode.DOWN).intValueExact();
|
|
|
+ int platformQuotaInt = platformQuota.multiply(new BigDecimal("10000")).setScale(0, RoundingMode.DOWN).intValueExact();
|
|
|
+ int highQuotaInt = highQuota.multiply(new BigDecimal("10000")).setScale(0, RoundingMode.DOWN).intValueExact();
|
|
|
|
|
|
|
|
|
// 获取当前下单人关系
|
|
@@ -177,81 +195,53 @@ public class OrderCalcServiceImpl implements OrderCalcService {
|
|
|
IntegralDO integralDO = integralService.selectByUser(sharePath.getDescendant());
|
|
|
|
|
|
// ========== 汇总计算 =================
|
|
|
- addCaclDo(percentTemplate, saveList, k, grossProfit, ancestorQuota, descendantQuota, bonusQuota, platformQuota);
|
|
|
+ addCaclDo(percentTemplate, saveList, k, grossProfitInt, ancestorQuotaInt, descendantQuotaInt, bonusQuotaInt, platformQuotaInt);
|
|
|
// ========== 修改用户钱包 =================
|
|
|
- changeUserWallet(integralSaveReqVOS, integralDO, integralDOAncestor, ancestorQuota, descendantQuota, highQuota);
|
|
|
+ changeUserWallet(integralSaveReqVOS, integralDO, integralDOAncestor, ancestorQuotaInt, descendantQuotaInt, highQuotaInt);
|
|
|
// ========== 修改平台信息 =================
|
|
|
// 每个订单计算的过程
|
|
|
// 增加平台收益
|
|
|
// 平台服务费
|
|
|
- Integer ptGrossAdd = ptProfitDO.getPtGrossAdd() + platformQuota;
|
|
|
- // 平台收益
|
|
|
- Integer ptAdd = ptProfitDO.getPtAdd() + grossProfit * (10000 - orderPercentageDO.getGrossProfitBonusQuotaPerc());
|
|
|
- // 平台总收益
|
|
|
- Integer ptTotal = ptProfitDO.getPtTotalAdd() + ptGrossAdd + ptAdd;
|
|
|
-
|
|
|
- PtProfitSaveReqVO ptProfitSaveReqVO = PtProfitSaveReqVO.builder()
|
|
|
- .ptAdd(ptAdd)
|
|
|
- .ptGrossAdd(ptGrossAdd)
|
|
|
- .ptTotalAdd(ptTotal).build();
|
|
|
+
|
|
|
+ BigDecimal ptGrossAdd = new BigDecimal(ptProfitDO.getPtGrossAdd());
|
|
|
+ BigDecimal ptAdd = new BigDecimal(ptProfitDO.getPtAdd());
|
|
|
+ BigDecimal ptTotalAdd = new BigDecimal(ptProfitDO.getPtTotalAdd());
|
|
|
+ BigDecimal bonusQuotaPerc = new BigDecimal(orderPercentageDO.getGrossProfitPerc());
|
|
|
+
|
|
|
+ // 计算平台收益:毛利润减去合赢奖百分比后的金额
|
|
|
+ BigDecimal one = BigDecimal.ONE;
|
|
|
+ BigDecimal grossProfitAfterBonus = grossProfit.multiply(one.subtract(bonusQuotaPerc));
|
|
|
+ BigDecimal newPtAdd = ptAdd.add(grossProfitAfterBonus);
|
|
|
+ BigDecimal newPtGrossAdd = ptGrossAdd.add(platformQuota);
|
|
|
+
|
|
|
+ // 计算平台总收益
|
|
|
+ BigDecimal newPtTotal = ptTotalAdd.add(newPtGrossAdd).add(newPtAdd);
|
|
|
+
|
|
|
+ // 换成整数
|
|
|
+ int ptGrossAddInt = newPtGrossAdd.intValue();
|
|
|
+ int ptAddInt = newPtAdd.intValue();
|
|
|
+ int ptTotalInt = newPtTotal.intValue();
|
|
|
+
|
|
|
+ PtProfitSaveReqVO ptProfitSaveReqVO = PtProfitSaveReqVO.builder().ptAdd(ptAddInt).ptGrossAdd(ptGrossAddInt).ptTotalAdd(ptTotalInt).build();
|
|
|
ptProfitSaveReqVOS.add(ptProfitSaveReqVO);
|
|
|
// ========== 增加日志记录 =================
|
|
|
|
|
|
// 平台记录
|
|
|
- PtProfitLogSaveReqVO ptGrossAddLog = PtProfitLogSaveReqVO.builder()
|
|
|
- .orderId(k.getOrderId())
|
|
|
- .profitStatus(CaclEnum.PLATFORM_SERVICE_FEE.getType())
|
|
|
- .orderNo(k.getNo())
|
|
|
- .amount(platformQuota)
|
|
|
- .afterAmount(ptProfitSaveReqVO.getPtGrossAdd())
|
|
|
- .percentTemplate(percentTemplate).build();
|
|
|
-
|
|
|
- PtProfitLogSaveReqVO ptAddLog = PtProfitLogSaveReqVO.builder()
|
|
|
- .orderId(k.getOrderId())
|
|
|
- .profitStatus(CaclEnum.PLATFORM_REVENUE.getType())
|
|
|
- .orderNo(k.getNo())
|
|
|
- .amount(grossProfit * (PERCENT - orderPercentageDO.getGrossProfitBonusQuotaPerc()))
|
|
|
- .afterAmount(ptProfitSaveReqVO.getPtAdd())
|
|
|
- .percentTemplate(percentTemplate).build();
|
|
|
+ PtProfitLogSaveReqVO ptGrossAddLog = PtProfitLogSaveReqVO.builder().orderId(k.getOrderId()).profitStatus(CaclEnum.PLATFORM_SERVICE_FEE.getType()).orderNo(k.getNo()).amount(platformQuotaInt).afterAmount(ptProfitSaveReqVO.getPtGrossAdd()).percentTemplate(percentTemplate).build();
|
|
|
+
|
|
|
+ PtProfitLogSaveReqVO ptAddLog = PtProfitLogSaveReqVO.builder().orderId(k.getOrderId()).profitStatus(CaclEnum.PLATFORM_REVENUE.getType()).orderNo(k.getNo()).amount(grossProfitAfterBonus.intValue()).afterAmount(ptProfitSaveReqVO.getPtAdd()).percentTemplate(percentTemplate).build();
|
|
|
|
|
|
|
|
|
// 推荐人记录
|
|
|
- PtProfitLogSaveReqVO tjrLog = PtProfitLogSaveReqVO.builder()
|
|
|
- .orderId(k.getOrderId())
|
|
|
- .profitStatus(CaclEnum.RECOMMENDED_PERSON_QUOTA.getType())
|
|
|
- .orderNo(k.getNo())
|
|
|
- .userId(sharePath.getAncestor())
|
|
|
- .amount(ancestorQuota)
|
|
|
- .afterAmount(integralDOAncestor.getCurrentQuota() + ancestorQuota)
|
|
|
- .percentTemplate(percentTemplate).build();
|
|
|
+ PtProfitLogSaveReqVO tjrLog = PtProfitLogSaveReqVO.builder().orderId(k.getOrderId()).profitStatus(CaclEnum.RECOMMENDED_PERSON_QUOTA.getType()).orderNo(k.getNo()).userId(sharePath.getAncestor()).amount(ancestorQuotaInt).afterAmount(integralDOAncestor.getCurrentQuota() + ancestorQuotaInt).percentTemplate(percentTemplate).build();
|
|
|
|
|
|
|
|
|
// 直推人记录
|
|
|
- PtProfitLogSaveReqVO ztrLog = PtProfitLogSaveReqVO.builder()
|
|
|
- .orderId(k.getOrderId())
|
|
|
- .profitStatus(CaclEnum.DIRECT_REFERRAL_QUOTA.getType())
|
|
|
- .orderNo(k.getNo())
|
|
|
- .userId(sharePath.getDescendant())
|
|
|
- .amount(descendantQuota)
|
|
|
- .afterAmount(integralDO.getCurrentQuota() + descendantQuota)
|
|
|
- .percentTemplate(percentTemplate).build();
|
|
|
- PtProfitLogSaveReqVO highQuotaLog = PtProfitLogSaveReqVO.builder()
|
|
|
- .orderId(k.getOrderId())
|
|
|
- .profitStatus(CaclEnum.HIGH_QUOTA.getType())
|
|
|
- .orderNo(k.getNo())
|
|
|
- .userId(sharePath.getDescendant())
|
|
|
- .amount(highQuota)
|
|
|
- .afterAmount(integralDO.getHighQuota() + highQuota)
|
|
|
- .percentTemplate(percentTemplate).build();
|
|
|
+ PtProfitLogSaveReqVO ztrLog = PtProfitLogSaveReqVO.builder().orderId(k.getOrderId()).profitStatus(CaclEnum.DIRECT_REFERRAL_QUOTA.getType()).orderNo(k.getNo()).userId(sharePath.getDescendant()).amount(descendantQuotaInt).afterAmount(integralDO.getCurrentQuota() + descendantQuotaInt).percentTemplate(percentTemplate).build();
|
|
|
+ PtProfitLogSaveReqVO highQuotaLog = PtProfitLogSaveReqVO.builder().orderId(k.getOrderId()).profitStatus(CaclEnum.HIGH_QUOTA.getType()).orderNo(k.getNo()).userId(sharePath.getDescendant()).amount(highQuotaInt).afterAmount(integralDO.getHighQuota() + highQuotaInt).percentTemplate(percentTemplate).build();
|
|
|
|
|
|
// 合赢奖记录
|
|
|
- PtProfitLogSaveReqVO hyjLog = PtProfitLogSaveReqVO.builder()
|
|
|
- .orderId(k.getOrderId())
|
|
|
- .profitStatus(CaclEnum.TOGETHER_AWARD.getType())
|
|
|
- .orderNo(k.getNo())
|
|
|
- .amount(bonusQuota)
|
|
|
- .afterAmount(0)
|
|
|
- .percentTemplate(percentTemplate).build();
|
|
|
+ PtProfitLogSaveReqVO hyjLog = PtProfitLogSaveReqVO.builder().orderId(k.getOrderId()).profitStatus(CaclEnum.TOGETHER_AWARD.getType()).orderNo(k.getNo()).amount(bonusQuotaInt).afterAmount(0).percentTemplate(percentTemplate).build();
|
|
|
|
|
|
|
|
|
ptProfitLogSaveReqVOS.add(ptGrossAddLog);
|
|
@@ -272,18 +262,7 @@ public class OrderCalcServiceImpl implements OrderCalcService {
|
|
|
}
|
|
|
|
|
|
private static void addCaclDo(String percentTemplate, List<OrderCalcSaveReqVO> saveList, DistriOrderMessage k, Integer grossProfit, Integer ancestorQuota, Integer descendantQuota, Integer bonusQuota, Integer platformQuota) {
|
|
|
- OrderCalcSaveReqVO orderCalcSaveReqVO = OrderCalcSaveReqVO.builder()
|
|
|
- .userId(k.getUserId())
|
|
|
- .orderNo(k.getNo())
|
|
|
- .cost(k.getCostPrice())
|
|
|
- .price(k.getPrice())
|
|
|
- .grossProfit(grossProfit)
|
|
|
- .grossProfitUserQuota(ancestorQuota)
|
|
|
- .grossProfitAncestorQuota(descendantQuota)
|
|
|
- .grossProfitBonusQuota(bonusQuota)
|
|
|
- .grossProfitPlatformQuota(platformQuota)
|
|
|
- .percentTemplate(percentTemplate)
|
|
|
- .build();
|
|
|
+ OrderCalcSaveReqVO orderCalcSaveReqVO = OrderCalcSaveReqVO.builder().userId(k.getUserId()).orderNo(k.getNo()).cost(k.getCostPrice()).price(k.getPrice()).grossProfit(grossProfit).grossProfitUserQuota(ancestorQuota).grossProfitAncestorQuota(descendantQuota).grossProfitBonusQuota(bonusQuota).grossProfitPlatformQuota(platformQuota).percentTemplate(percentTemplate).build();
|
|
|
saveList.add(orderCalcSaveReqVO);
|
|
|
}
|
|
|
|
|
@@ -301,74 +280,6 @@ public class OrderCalcServiceImpl implements OrderCalcService {
|
|
|
}
|
|
|
|
|
|
|
|
|
- private static void addLog(OrderPercentageDO orderPercentageDO, String percentTemplate, List<PtProfitLogSaveReqVO> ptProfitLogSaveReqVOS, DistriOrderMessage k, SharePathDO sharePath, IntegralDO integralDO, IntegralDO integralDOAncestor, Integer grossProfit, Integer ancestorQuota, Integer descendantQuota, Integer bonusQuota, Integer platformQuota, PtProfitSaveReqVO ptProfitSaveReqVO) {
|
|
|
-
|
|
|
- // 平台记录
|
|
|
- PtProfitLogSaveReqVO ptGrossAddLog = PtProfitLogSaveReqVO.builder()
|
|
|
- .orderId(k.getOrderId())
|
|
|
- .profitStatus(1)
|
|
|
- .orderNo(k.getNo())
|
|
|
- .amount(platformQuota)
|
|
|
- .afterAmount(ptProfitSaveReqVO.getPtGrossAdd())
|
|
|
- .percentTemplate(percentTemplate).build();
|
|
|
-
|
|
|
- PtProfitLogSaveReqVO ptAddLog = PtProfitLogSaveReqVO.builder()
|
|
|
- .orderId(k.getOrderId())
|
|
|
- .profitStatus(2)
|
|
|
- .orderNo(k.getNo())
|
|
|
- .amount(grossProfit * (PERCENT - orderPercentageDO.getGrossProfitBonusQuotaPerc()))
|
|
|
- .afterAmount(ptProfitSaveReqVO.getPtAdd())
|
|
|
- .percentTemplate(percentTemplate).build();
|
|
|
-
|
|
|
-
|
|
|
- // 推荐人记录
|
|
|
- PtProfitLogSaveReqVO tjrLog = PtProfitLogSaveReqVO.builder()
|
|
|
- .orderId(k.getOrderId())
|
|
|
- .profitStatus(2)
|
|
|
- .orderNo(k.getNo())
|
|
|
- .userId(sharePath.getAncestor())
|
|
|
- .amount(ancestorQuota)
|
|
|
- .afterAmount(integralDOAncestor.getCurrentQuota() + ancestorQuota)
|
|
|
- .percentTemplate(percentTemplate).build();
|
|
|
-
|
|
|
- PtProfitLogSaveReqVO highQuotaLog = PtProfitLogSaveReqVO.builder()
|
|
|
- .orderId(k.getOrderId())
|
|
|
- .profitStatus(6)
|
|
|
- .orderNo(k.getNo())
|
|
|
- .userId(sharePath.getAncestor())
|
|
|
- .amount(ancestorQuota)
|
|
|
- .afterAmount(integralDOAncestor.getCurrentQuota() + ancestorQuota)
|
|
|
- .percentTemplate(percentTemplate).build();
|
|
|
-
|
|
|
-
|
|
|
- // 直推人记录
|
|
|
- PtProfitLogSaveReqVO ztrLog = PtProfitLogSaveReqVO.builder()
|
|
|
- .orderId(k.getOrderId())
|
|
|
- .profitStatus(2)
|
|
|
- .orderNo(k.getNo())
|
|
|
- .userId(sharePath.getDescendant())
|
|
|
- .amount(descendantQuota)
|
|
|
- .afterAmount(integralDO.getCurrentQuota() + descendantQuota)
|
|
|
- .percentTemplate(percentTemplate).build();
|
|
|
-
|
|
|
-
|
|
|
- // 合赢奖记录
|
|
|
- PtProfitLogSaveReqVO hyjLog = PtProfitLogSaveReqVO.builder()
|
|
|
- .orderId(k.getOrderId())
|
|
|
- .profitStatus(2)
|
|
|
- .orderNo(k.getNo())
|
|
|
- .amount(bonusQuota)
|
|
|
- .afterAmount(0)
|
|
|
- .percentTemplate(percentTemplate).build();
|
|
|
-
|
|
|
-
|
|
|
- ptProfitLogSaveReqVOS.add(ptGrossAddLog);
|
|
|
- ptProfitLogSaveReqVOS.add(ptAddLog);
|
|
|
- ptProfitLogSaveReqVOS.add(tjrLog);
|
|
|
- ptProfitLogSaveReqVOS.add(ztrLog);
|
|
|
- ptProfitLogSaveReqVOS.add(hyjLog);
|
|
|
- ptProfitLogSaveReqVOS.add(highQuotaLog);
|
|
|
- }
|
|
|
|
|
|
|
|
|
// 获取当前订单的下单人的直推关系
|