|
@@ -173,14 +173,12 @@ public class OrderCalcServiceImpl implements OrderCalcService {
|
|
|
// 当前计算百分比模板
|
|
|
String percentTemplate = JsonUtils.toJsonString(orderPercentageDO);
|
|
|
|
|
|
- // 订单完成的七天后计算,分配权益,现在是即算即得所以注释了,后续变动可以打开
|
|
|
-// calc(tradeOrderDO, orderPercentageDO, percentTemplate);
|
|
|
-
|
|
|
/*
|
|
|
- 计算合赢奖三部曲:
|
|
|
+ 计算团队奖三部曲:
|
|
|
1:计算每日订单
|
|
|
2:计算每日合赢奖的收益(冻结的)
|
|
|
3:将冻结的合赢将转换成可用的
|
|
|
+ 4:计算幸运奖
|
|
|
*/
|
|
|
//计算每日订单收益
|
|
|
// 1
|
|
@@ -190,21 +188,24 @@ public class OrderCalcServiceImpl implements OrderCalcService {
|
|
|
} finally {
|
|
|
// todo 计算当天用户的碰撞
|
|
|
// 计算兄弟分区, 以及后代分区
|
|
|
- // 2
|
|
|
+ // 2 计算每日团队奖的收益(冻结的)
|
|
|
List<Long> userId2 = bonusQuotaOrderDO.stream().map(OrderCalcMessage::getUserId).collect(Collectors.toList());
|
|
|
partitionCrashService.calcCrash(userId2);
|
|
|
|
|
|
- // 3
|
|
|
+ // 3 将冻结的团队奖转换成可用的
|
|
|
dailyAwardRecordsService.transitionBonus();
|
|
|
|
|
|
+ // 4 计算幸运奖
|
|
|
+ dailyAwardRecordsService.calcLucky();
|
|
|
+
|
|
|
// 计算每家店铺每日订单
|
|
|
dailyBillService.caleDailyBill();
|
|
|
|
|
|
// 结算订单,签收七天的订单
|
|
|
- shopSettlementService.settlementOrder();
|
|
|
+// shopSettlementService.settlementOrder();
|
|
|
|
|
|
// 每日消费分校对预警
|
|
|
- consumptionErrorLogService.calcEveryDayConsumptionPointsErrorLog();
|
|
|
+// consumptionErrorLogService.calcEveryDayConsumptionPointsErrorLog();
|
|
|
|
|
|
System.out.println("=================计算程序结束====================");
|
|
|
}
|
|
@@ -243,8 +244,6 @@ public class OrderCalcServiceImpl implements OrderCalcService {
|
|
|
List<OrderCalcSaveReqVO> saveList = new ArrayList<>();
|
|
|
|
|
|
bonusQuotaOrderDO.forEach(k -> {
|
|
|
- // 添加平台利润记录详情
|
|
|
- List<PtProfitLogDetailsSaveReqVO> ptProfitLogDetailsSaveReqVOS = new ArrayList<>();
|
|
|
// 计算单个订单的总单价
|
|
|
long priceStream = k.getOrderItemMessages().stream().mapToLong(OrderItemMessage::getPrice).sum();
|
|
|
// 计算单个订单的总成本
|
|
@@ -262,35 +261,22 @@ public class OrderCalcServiceImpl implements OrderCalcService {
|
|
|
BigDecimal productCount = new BigDecimal(j.getCount());
|
|
|
BigDecimal oneGrossProfit = onePrice.subtract(oneCostPrice).multiply(productCount);
|
|
|
profit[0] = profit[0].add(oneGrossProfit); // 注意这里的改动
|
|
|
- profit[1] = profit[1].add(new BigDecimal(j.getIncreaseIntegral())); //自得积分
|
|
|
- profit[2] = profit[2].add(new BigDecimal(j.getAncestorIncreaseIntegral())); //直推奖积分
|
|
|
+ profit[1] = profit[1].add(new BigDecimal(j.getAncestorIncreaseIntegral())); //直推奖积分
|
|
|
|
|
|
// 参与过订单计算后就标记为已分配权益
|
|
|
updateOrderItemTransitionTime(j.getOrderItemId());
|
|
|
- // 添加日志表的二级表
|
|
|
- PtProfitLogDetailsSaveReqVO ptProfitLogDetailsSaveReqVO = PtProfitLogDetailsSaveReqVO.builder()
|
|
|
- .orderItemId(j.getOrderItemId())
|
|
|
- .build();
|
|
|
- ptProfitLogDetailsSaveReqVOS.add(ptProfitLogDetailsSaveReqVO);
|
|
|
});
|
|
|
|
|
|
// 计算毛利: 利润 * 1
|
|
|
BigDecimal grossProfit = profit[0].multiply(new BigDecimal(orderPercentageDO.getGrossProfitPerc())).setScale(4, RoundingMode.DOWN);
|
|
|
- // 合赢将: 毛利 * 0.12
|
|
|
- BigDecimal bonusQuota = grossProfit.multiply(new BigDecimal(orderPercentageDO.getGrossProfitBonusQuotaPerc())).setScale(4, RoundingMode.DOWN);
|
|
|
-
|
|
|
- // 用户所得: 毛利 * 0.35
|
|
|
- BigDecimal descendantQuota = profit[1];
|
|
|
|
|
|
// 直推奖: 毛利 * 0.3 (上一级)
|
|
|
- BigDecimal ancestorQuota = profit[2];
|
|
|
+ BigDecimal ancestorQuota = profit[1];
|
|
|
|
|
|
Long grossProfitInt = grossProfit.multiply(new BigDecimal("10000")).setScale(0, RoundingMode.DOWN).longValue();
|
|
|
- Long bonusQuotaInt = bonusQuota.multiply(new BigDecimal("10000")).setScale(0, RoundingMode.DOWN).longValue();
|
|
|
BigDecimal platformQuota = grossProfit.multiply(new BigDecimal(orderPercentageDO.getGrossProfitPlatformQuotaPerc())).setScale(4, RoundingMode.DOWN);
|
|
|
|
|
|
Long ancestorQuotaInt = ancestorQuota.longValue();
|
|
|
- Long descendantQuotaInt = descendantQuota.longValue();
|
|
|
Long platformQuotaInt = platformQuota.multiply(new BigDecimal("10000")).setScale(0, RoundingMode.DOWN).longValue();
|
|
|
|
|
|
// ========== 汇总计算 =================
|
|
@@ -301,30 +287,12 @@ public class OrderCalcServiceImpl implements OrderCalcService {
|
|
|
.cost(costPrice.longValue())
|
|
|
.price(price.longValue())
|
|
|
.productCount(k.getProductCount())
|
|
|
- .nickName(k.getNickName())
|
|
|
- .name(k.getName())
|
|
|
+ .userName(k.getName())
|
|
|
.grossProfit(grossProfitInt)
|
|
|
- .grossProfitUserQuota(descendantQuotaInt)
|
|
|
.grossProfitPlatformQuota(platformQuotaInt)
|
|
|
.grossProfitAncestorQuota(ancestorQuotaInt)
|
|
|
.percentTemplate(percentTemplate).build();
|
|
|
saveList.add(orderCalcSaveReqVO);
|
|
|
-
|
|
|
- // 合赢奖记录
|
|
|
- PtProfitLogSaveReqVO hyjLog = PtProfitLogSaveReqVO.builder()
|
|
|
- .orderId(k.getOrderId())
|
|
|
- .profitStatus(CaclEnum.TOGETHER_AWARD.getType())
|
|
|
- .orderNo(k.getNo())
|
|
|
- .amount(bonusQuotaInt)
|
|
|
- .afterAmount(0L)
|
|
|
- .generateUserId(k.getUserId())
|
|
|
- .percentTemplate(percentTemplate).build();
|
|
|
- // 添加获得合赢奖的记录
|
|
|
- hyjLog.setId(ptProfitLogService.createPtProfitLog(hyjLog));
|
|
|
- for (PtProfitLogDetailsSaveReqVO ptProfitLogDetailsSaveReqVO : ptProfitLogDetailsSaveReqVOS) {
|
|
|
- ptProfitLogDetailsSaveReqVO.setDistriPtProfitLogId(hyjLog.getId());
|
|
|
- }
|
|
|
- ptProfitLogDetailsService.saveBatch(ptProfitLogDetailsSaveReqVOS);
|
|
|
});
|
|
|
|
|
|
// 将信息存储到数据库中
|
|
@@ -366,7 +334,7 @@ public class OrderCalcServiceImpl implements OrderCalcService {
|
|
|
|
|
|
|
|
|
// 计算,毛利中100 之外的百分比
|
|
|
- BigDecimal otherOneHundred = oneHundred.subtract(new BigDecimal(orderPercentageDO.getGrossProfitUserQuotaPerc()))
|
|
|
+ BigDecimal otherOneHundred = oneHundred
|
|
|
.subtract(new BigDecimal(orderPercentageDO.getGrossProfitAncestorQuotaPerc()))
|
|
|
.subtract(new BigDecimal(orderPercentageDO.getGrossProfitPlatformQuotaPerc()));
|
|
|
|
|
@@ -386,9 +354,8 @@ public class OrderCalcServiceImpl implements OrderCalcService {
|
|
|
BigDecimal productCount = new BigDecimal(j.getCount());
|
|
|
BigDecimal oneGrossProfit = onePrice.subtract(oneCostPrice).multiply(productCount);
|
|
|
profit[0] = profit[0].add(oneGrossProfit); // 注意这里的改动
|
|
|
- profit[1] = profit[1].add(new BigDecimal(j.getIncreaseIntegral())); //自得积分
|
|
|
- profit[2] = profit[2].add(new BigDecimal(j.getAncestorIncreaseIntegral())); //直推奖
|
|
|
- profit[3] = profit[3].add(new BigDecimal(j.getFreezeHighQuota())); //用户获得冻结最大可用额度
|
|
|
+ profit[1] = profit[1].add(new BigDecimal(j.getAncestorIncreaseIntegral())); //直推奖
|
|
|
+ profit[2] = profit[2].add(new BigDecimal(j.getFreezeHighQuota())); //用户获得冻结最大可用额度
|
|
|
|
|
|
// 遍历订单项拿到订单项编号
|
|
|
//将当前订单项设置为已分配权益
|
|
@@ -406,11 +373,8 @@ public class OrderCalcServiceImpl implements OrderCalcService {
|
|
|
grossProfitAfterBonus = grossProfitAfterBonus.add(grossProfit.multiply(otherOneHundred).setScale(4, RoundingMode.DOWN));
|
|
|
}
|
|
|
|
|
|
- // 用户所得: 毛利 * 0.35
|
|
|
- BigDecimal descendantQuota = profit[1];
|
|
|
-
|
|
|
// 直推奖: 毛利 * 0.3 (上一级)
|
|
|
- BigDecimal ancestorQuota = profit[2];
|
|
|
+ BigDecimal ancestorQuota = profit[1];
|
|
|
|
|
|
// 平台服务费: 毛利 * 0.05
|
|
|
BigDecimal platformQuota = grossProfit.multiply(new BigDecimal(orderPercentageDO.getGrossProfitPlatformQuotaPerc())).setScale(4, RoundingMode.DOWN);
|
|
@@ -418,11 +382,10 @@ public class OrderCalcServiceImpl implements OrderCalcService {
|
|
|
|
|
|
// 计算当前下单人的毛利的十倍
|
|
|
// BigDecimal highQuota = grossProfit.multiply(new BigDecimal("10")).setScale(4, RoundingMode.DOWN);
|
|
|
- BigDecimal highQuota = profit[3];
|
|
|
+ BigDecimal highQuota = profit[2];
|
|
|
|
|
|
// 乘以 10000 并转换为整数
|
|
|
Long ancestorQuotaInt = ancestorQuota.longValue();
|
|
|
- Long descendantQuotaInt = descendantQuota.longValue();
|
|
|
Long highQuotaInt = highQuota.longValue();
|
|
|
Long grossProfitAfterBonusInt = grossProfitAfterBonus.multiply(new BigDecimal("10000")).setScale(0, RoundingMode.DOWN).longValue();
|
|
|
Long platformQuotaInt = platformQuota.multiply(new BigDecimal("10000")).setScale(0, RoundingMode.DOWN).longValue();
|
|
@@ -431,8 +394,8 @@ public class OrderCalcServiceImpl implements OrderCalcService {
|
|
|
// 获取当前下单人关系
|
|
|
SharePathDO sharePath = getSharePath(k.getUserId());
|
|
|
// 如果sharePath为空, 则说明没有直推人关系
|
|
|
- IntegralDO integralDOAncestor = integralService.selectByUser(sharePath.getAncestor()); //父级
|
|
|
- IntegralDO integralDO = integralService.selectByUser(sharePath.getDescendant()); //自己
|
|
|
+ IntegralDO integralDOAncestor = integralService.selectByUser(sharePath.getReferrerId()); //父级
|
|
|
+ IntegralDO integralDO = integralService.selectByUser(sharePath.getUserId()); //自己
|
|
|
IntegralDO ptIntegral = integralService.selectByUser(1L); //pt
|
|
|
|
|
|
|
|
@@ -475,8 +438,7 @@ public class OrderCalcServiceImpl implements OrderCalcService {
|
|
|
ptReplenish = ancestorQuotaInt - ancestorHighQuota;
|
|
|
}
|
|
|
}
|
|
|
- changeUserWallet(integralDO, integralDOAncestor, ptIntegral, amount,
|
|
|
- descendantQuotaInt, highQuotaInt, grossProfitAfterBonusInt, platformQuotaInt, ptReplenish);
|
|
|
+ changeUserWallet(integralDO, integralDOAncestor, ptIntegral, amount, highQuotaInt, grossProfitAfterBonusInt, platformQuotaInt, ptReplenish);
|
|
|
|
|
|
// ========== 修改平台信息 =================
|
|
|
// 每个订单计算的过程
|
|
@@ -538,42 +500,29 @@ public class OrderCalcServiceImpl implements OrderCalcService {
|
|
|
.orderId(k.getOrderId())
|
|
|
.profitStatus(CaclEnum.RECOMMENDED_PERSON_QUOTA.getType())
|
|
|
.orderNo(k.getNo())
|
|
|
- .userId(sharePath.getAncestor())
|
|
|
.amount(amount)
|
|
|
- .afterAmount(integralDOAncestor.getCurrentQuota())
|
|
|
- .freezeAmount(-amount)
|
|
|
- .afterFreezeAmount(integralDOAncestor.getFreezeQuota())
|
|
|
- .ancestorQuotaAmount(ptReplenish)
|
|
|
- .maxAvailablePointsAmount(-amount)
|
|
|
- .afterMaxAvailablePointsAmount(ancestorHighQuota - amount)
|
|
|
+ .afterAmount(integralDOAncestor.getRedCurrentQuota())
|
|
|
.percentTemplate(percentTemplate)
|
|
|
.generateUserId(integralDO.getUserId())
|
|
|
.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())
|
|
|
- .freezeAmount(-descendantQuotaInt)
|
|
|
- .afterFreezeAmount(integralDO.getFreezeQuota())
|
|
|
- .maxAvailablePointsAmount(highQuotaInt)
|
|
|
- .afterMaxAvailablePointsAmount(integralDO.getHighQuota()+ new BigDecimal(orderPercentageDO.getBaseMaxQuota()).longValue())
|
|
|
- .freezeHighQuota(-highQuotaInt)
|
|
|
- .afterFreezeHighQuota(integralDO.getFreezeHighQuota())
|
|
|
- .percentTemplate(percentTemplate)
|
|
|
- .generateUserId(integralDO.getUserId())
|
|
|
- .build();
|
|
|
+// // 用户自得记录 + 户冻结积分转化成可用 + 扣减最高可用额度记录
|
|
|
+// PtProfitLogSaveReqVO ztrLog = PtProfitLogSaveReqVO.builder()
|
|
|
+// .orderId(k.getOrderId())
|
|
|
+// .profitStatus(CaclEnum.DIRECT_REFERRAL_QUOTA.getType())
|
|
|
+// .orderNo(k.getNo())
|
|
|
+// .amount(descendantQuotaInt)
|
|
|
+// .afterAmount(integralDO.getRedCurrentQuota())
|
|
|
+// .percentTemplate(percentTemplate)
|
|
|
+// .generateUserId(integralDO.getUserId())
|
|
|
+// .build();
|
|
|
|
|
|
ptProfitLogSaveReqVOS.add(ptTotal);
|
|
|
ptProfitLogSaveReqVOS.add(ptGrossAddLog);
|
|
|
ptProfitLogSaveReqVOS.add(ptAddLog);
|
|
|
ptProfitLogSaveReqVOS.add(tjrLog);
|
|
|
- ptProfitLogSaveReqVOS.add(ztrLog);
|
|
|
+// ptProfitLogSaveReqVOS.add(ztrLog);
|
|
|
|
|
|
|
|
|
PtProfitDO ptProfit = ptProfitService.getPtProfit();
|
|
@@ -653,14 +602,13 @@ public class OrderCalcServiceImpl implements OrderCalcService {
|
|
|
* @param integralDOAncestor 推荐人钱包
|
|
|
* @param pt pt钱包
|
|
|
* @param ancestorQuota 推荐人额度
|
|
|
- * @param descendantQuota 直推人额度
|
|
|
* @param highQuota 最大可用额度
|
|
|
* @param ptA pt收益
|
|
|
* @param ptB pt服务费
|
|
|
* @param ptReplenish 超出没有获取到的积分
|
|
|
*/
|
|
|
private void changeUserWallet(IntegralDO integralDO, IntegralDO integralDOAncestor, IntegralDO pt,
|
|
|
- Long ancestorQuota, Long descendantQuota, Long highQuota, Long ptA, Long ptB, Long ptReplenish) {
|
|
|
+ Long ancestorQuota, Long highQuota, Long ptA, Long ptB, Long ptReplenish) {
|
|
|
// 修改用户钱包
|
|
|
// 增加直推人额度
|
|
|
integralDO.setHighQuota(integralDO.getHighQuota() + highQuota);
|
|
@@ -669,10 +617,8 @@ public class OrderCalcServiceImpl implements OrderCalcService {
|
|
|
integralDO.setFreezeHighQuota(integralDO.getFreezeHighQuota() - highQuota);
|
|
|
// todo 增加累计额度
|
|
|
|
|
|
- integralDO.setCurrentQuota(integralDO.getCurrentQuota() + descendantQuota);
|
|
|
- integralDO.setFreezeQuota(integralDO.getFreezeQuota() - descendantQuota);
|
|
|
// 增加推荐人额度
|
|
|
- integralDOAncestor.setCurrentQuota(integralDOAncestor.getCurrentQuota() + ancestorQuota);
|
|
|
+ integralDOAncestor.setRedCurrentQuota(integralDOAncestor.getRedCurrentQuota() + ancestorQuota);
|
|
|
// 减少推荐人的可获取额度
|
|
|
integralDOAncestor.setHighQuota(integralDOAncestor.getHighQuota() - ancestorQuota);
|
|
|
integralDOAncestor.setAncestorQuota(integralDOAncestor.getAncestorQuota() + ancestorQuota);
|
|
@@ -680,7 +626,7 @@ public class OrderCalcServiceImpl implements OrderCalcService {
|
|
|
integralService.updateIntegral(BeanUtils.toBean(integralDOAncestor, IntegralSaveReqVO.class));
|
|
|
|
|
|
// 增加平台额度
|
|
|
- pt.setCurrentQuota(pt.getCurrentQuota() + ptA + ptB);
|
|
|
+ pt.setRedCurrentQuota(pt.getRedCurrentQuota() + ptA + ptB);
|
|
|
|
|
|
// integralSaveReqVOS.add(BeanUtils.toBean(integralDO, IntegralSaveReqVO.class));
|
|
|
// integralSaveReqVOS.add(BeanUtils.toBean(integralDOAncestor, IntegralSaveReqVO.class));
|