|
@@ -11,6 +11,7 @@ import cn.newfeifan.mall.module.distri.dal.dataobject.orderpercentage.OrderPerce
|
|
|
import cn.newfeifan.mall.module.distri.dal.dataobject.ptprofit.PtProfitDO;
|
|
|
import cn.newfeifan.mall.module.distri.dal.dataobject.sharepath.SharePathDO;
|
|
|
import cn.newfeifan.mall.module.distri.enums.CaclEnum;
|
|
|
+import cn.newfeifan.mall.module.distri.enums.SocialStatusEnum;
|
|
|
import cn.newfeifan.mall.module.distri.mq.message.order.DistriOrderMessage;
|
|
|
import cn.newfeifan.mall.module.distri.mq.message.order.OrderCalcMessage;
|
|
|
import cn.newfeifan.mall.module.distri.mq.message.order.OrderItemMessage;
|
|
@@ -19,7 +20,6 @@ import cn.newfeifan.mall.module.distri.service.integral.IntegralService;
|
|
|
import cn.newfeifan.mall.module.distri.service.orderpercentage.OrderPercentageService;
|
|
|
import cn.newfeifan.mall.module.distri.service.partitioncrash.PartitionCrashService;
|
|
|
import cn.newfeifan.mall.module.distri.service.ptprofit.PtProfitService;
|
|
|
-import cn.newfeifan.mall.module.distri.service.ptprofitdailystatisticslog.PtProfitDailyStatisticsLogService;
|
|
|
import cn.newfeifan.mall.module.distri.service.ptprofitlog.PtProfitLogService;
|
|
|
import cn.newfeifan.mall.module.distri.service.sharepath.SharePathService;
|
|
|
import org.springframework.context.annotation.Lazy;
|
|
@@ -83,9 +83,6 @@ public class OrderCalcServiceImpl implements OrderCalcService {
|
|
|
@Resource
|
|
|
private PartitionCrashService partitionCrashService;
|
|
|
|
|
|
- @Resource
|
|
|
- private PtProfitDailyStatisticsLogService ptProfitDailyStatisticsLogService;
|
|
|
-
|
|
|
@Override
|
|
|
public Long createOrderCalc(OrderCalcSaveReqVO createReqVO) {
|
|
|
// 插入
|
|
@@ -146,7 +143,7 @@ public class OrderCalcServiceImpl implements OrderCalcService {
|
|
|
String percentTemplate = JsonUtils.toJsonString(orderPercentageDO);
|
|
|
calc(tradeOrderDO, orderPercentageDO, percentTemplate);
|
|
|
} catch (Exception e) {
|
|
|
-
|
|
|
+ System.out.println(e.getMessage());
|
|
|
} finally {
|
|
|
// todo 计算当天用户的碰撞
|
|
|
// 计算兄弟分区, 以及后代分区
|
|
@@ -161,6 +158,11 @@ public class OrderCalcServiceImpl implements OrderCalcService {
|
|
|
.in(OrderCalcDO::getUserId, userList));
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public void updateOrderItem(Long orderItemId) {
|
|
|
+ orderCalcMapper.updateOrderItemById(orderItemId);
|
|
|
+ }
|
|
|
+
|
|
|
private void calc(List<OrderCalcMessage> tradeOrderDO, OrderPercentageDO orderPercentageDO, String percentTemplate) {
|
|
|
|
|
|
List<PtProfitSaveReqVO> savePFitMap = new ArrayList<>();
|
|
@@ -198,13 +200,16 @@ public class OrderCalcServiceImpl implements OrderCalcService {
|
|
|
|
|
|
// 计算
|
|
|
// 计算利润: (价格 - 成本价格) * 产品数量
|
|
|
- final BigDecimal[] profit = {new BigDecimal("0")};
|
|
|
+ final BigDecimal[] profit = {new BigDecimal("0"), new BigDecimal("0")}; //用户自得不用要计算,从orderItem里面获取
|
|
|
k.getOrderItemMessages().forEach(j -> {
|
|
|
BigDecimal onePrice = new BigDecimal(j.getPrice());
|
|
|
BigDecimal oneCostPrice = new BigDecimal(j.getCostPrice());
|
|
|
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())); //自得积分
|
|
|
+
|
|
|
+ updateOrderItem(j.getOrderItemId());
|
|
|
});
|
|
|
|
|
|
|
|
@@ -219,7 +224,7 @@ public class OrderCalcServiceImpl implements OrderCalcService {
|
|
|
}
|
|
|
|
|
|
// 用户所得: 毛利 * 0.35
|
|
|
- BigDecimal descendantQuota = grossProfit.multiply(new BigDecimal(orderPercentageDO.getGrossProfitUserQuotaPerc())).setScale(4, RoundingMode.DOWN);
|
|
|
+ BigDecimal descendantQuota = profit[1];
|
|
|
|
|
|
// 直推奖: 毛利 * 0.35 (上一级)
|
|
|
BigDecimal ancestorQuota = grossProfit.multiply(new BigDecimal(orderPercentageDO.getGrossProfitAncestorQuotaPerc())).setScale(4, RoundingMode.DOWN);
|
|
@@ -237,7 +242,7 @@ public class OrderCalcServiceImpl implements OrderCalcService {
|
|
|
// 乘以 10000 并转换为整数
|
|
|
Long grossProfitInt = grossProfit.multiply(new BigDecimal("10000")).setScale(0, RoundingMode.DOWN).longValue();
|
|
|
Long ancestorQuotaInt = ancestorQuota.multiply(new BigDecimal("10000")).setScale(0, RoundingMode.DOWN).longValue();
|
|
|
- Long descendantQuotaInt = descendantQuota.multiply(new BigDecimal("10000")).setScale(0, RoundingMode.DOWN).longValue();
|
|
|
+ Long descendantQuotaInt = descendantQuota.longValue();
|
|
|
Long bonusQuotaInt = bonusQuota.multiply(new BigDecimal("10000")).setScale(0, RoundingMode.DOWN).longValue();
|
|
|
Long highQuotaInt = highQuota.multiply(new BigDecimal("10000")).setScale(0, RoundingMode.DOWN).longValue();
|
|
|
Long grossProfitAfterBonusInt = grossProfitAfterBonus.multiply(new BigDecimal("10000")).setScale(0, RoundingMode.DOWN).longValue();
|
|
@@ -250,6 +255,20 @@ public class OrderCalcServiceImpl implements OrderCalcService {
|
|
|
IntegralDO integralDOAncestor = integralService.selectByUser(sharePath.getAncestor());
|
|
|
IntegralDO integralDO = integralService.selectByUser(sharePath.getDescendant());
|
|
|
IntegralDO ptIntegral = integralService.selectByUser(1L);
|
|
|
+
|
|
|
+
|
|
|
+ // ========== 身价计算 ==============
|
|
|
+ //推荐人身价计算
|
|
|
+ double orderAncestorSocialStatus = Double.parseDouble(orderPercentageDO.getOrderAncestorSocialStatus());
|
|
|
+ double ancestorSocial = k.getOrderItemMessages().get(0).getTotalPrice() * orderAncestorSocialStatus;
|
|
|
+ duserService.updateDuserSocial(integralDOAncestor.getUserId(), (long) ancestorSocial, SocialStatusEnum.SHOPPING_ANCESTOR_SOCIAL.getStatus());
|
|
|
+
|
|
|
+ //自得身价计算
|
|
|
+ double orderUserSocialStatus = Double.parseDouble(orderPercentageDO.getOrderUserSocialStatus());
|
|
|
+ double descendantSocial = k.getOrderItemMessages().get(0).getTotalPrice() * orderUserSocialStatus;
|
|
|
+ duserService.updateDuserSocial(integralDO.getUserId(), (long) descendantSocial, SocialStatusEnum.SHOPPING_SOCIAL.getStatus());
|
|
|
+
|
|
|
+
|
|
|
// ========== 汇总计算 =================
|
|
|
OrderCalcSaveReqVO orderCalcSaveReqVO = OrderCalcSaveReqVO.builder()
|
|
|
.userId(k.getUserId())
|
|
@@ -267,7 +286,15 @@ public class OrderCalcServiceImpl implements OrderCalcService {
|
|
|
.percentTemplate(percentTemplate).build();
|
|
|
saveList.add(orderCalcSaveReqVO);
|
|
|
// ========== 修改用户钱包 =================
|
|
|
- changeUserWallet(integralSaveReqVOS, integralDO, integralDOAncestor, ptIntegral, ancestorQuotaInt, descendantQuotaInt, highQuotaInt, grossProfitAfterBonusInt, platformQuotaInt);
|
|
|
+ //直推奖也要限制额度
|
|
|
+ Long ancestorHighQuota = integralDOAncestor.getHighQuota() + new BigDecimal(orderPercentageDO.getBaseMaxQuota()).longValue();//加上基础的最大额度值
|
|
|
+ if (ancestorHighQuota < ancestorQuotaInt) {
|
|
|
+ changeUserWallet(integralSaveReqVOS, integralDO, integralDOAncestor, ptIntegral, 0L,
|
|
|
+ descendantQuotaInt, highQuotaInt, grossProfitAfterBonusInt, platformQuotaInt);
|
|
|
+ } else {
|
|
|
+ changeUserWallet(integralSaveReqVOS, integralDO, integralDOAncestor, ptIntegral, ancestorQuotaInt,
|
|
|
+ descendantQuotaInt, highQuotaInt, grossProfitAfterBonusInt, platformQuotaInt);
|
|
|
+ }
|
|
|
// ========== 修改平台信息 =================
|
|
|
// 每个订单计算的过程
|
|
|
// 增加平台收益
|
|
@@ -277,6 +304,11 @@ public class OrderCalcServiceImpl implements OrderCalcService {
|
|
|
.ptAdd(platformQuotaInt)
|
|
|
.ptGrossAdd(grossProfitAfterBonusInt)
|
|
|
.ptTotalAdd(platformQuotaInt + grossProfitAfterBonusInt).build();
|
|
|
+
|
|
|
+ // 当直推人获取的积分额度不足时,平台收益要加回来,并生成log
|
|
|
+ calcIntegral(ptProfitSaveReqVOS, ptProfitSaveReqVO, ancestorHighQuota, ancestorQuotaInt,
|
|
|
+ k.getOrderId(), k.getNo(), integralDOAncestor.getUserId());
|
|
|
+
|
|
|
ptProfitSaveReqVOS.add(ptProfitSaveReqVO);
|
|
|
// ========== 增加日志记录 =================
|
|
|
|
|
@@ -303,6 +335,9 @@ public class OrderCalcServiceImpl implements OrderCalcService {
|
|
|
|
|
|
// 直推人记录
|
|
|
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 freezeLog = PtProfitLogSaveReqVO.builder().orderId(k.getOrderId()).profitStatus(CaclEnum.FREEZE_CHANGE_INTEGRAL.getType()).orderNo(k.getNo()).userId(sharePath.getDescendant()).freezeAmount(descendantQuotaInt).afterFreezeAmount(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();
|
|
|
|
|
|
// 合赢奖记录
|
|
@@ -314,6 +349,7 @@ public class OrderCalcServiceImpl implements OrderCalcService {
|
|
|
ptProfitLogSaveReqVOS.add(ptAddLog);
|
|
|
ptProfitLogSaveReqVOS.add(tjrLog);
|
|
|
ptProfitLogSaveReqVOS.add(ztrLog);
|
|
|
+ ptProfitLogSaveReqVOS.add(freezeLog);
|
|
|
ptProfitLogSaveReqVOS.add(hyjLog);
|
|
|
ptProfitLogSaveReqVOS.add(highQuotaLog);
|
|
|
|
|
@@ -346,6 +382,24 @@ public class OrderCalcServiceImpl implements OrderCalcService {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ private void calcIntegral(List<PtProfitSaveReqVO> ptProfitSaveReqVOS, PtProfitSaveReqVO ptProfitSaveReqVO,
|
|
|
+ Long highQuotaInt, Long ancestorQuotaInt, Long orderId, String orderNo, Long userId) {
|
|
|
+ if (highQuotaInt < ancestorQuotaInt) {
|
|
|
+ ptProfitSaveReqVO.setPtGrossAdd(ptProfitSaveReqVO.getPtGrossAdd() + ancestorQuotaInt);
|
|
|
+ ptProfitSaveReqVO.setPtTotalAdd(ptProfitSaveReqVO.getPtGrossAdd() + ptProfitSaveReqVO.getPtAdd());
|
|
|
+
|
|
|
+ PtProfitLogSaveReqVO ptProfitLog = PtProfitLogSaveReqVO.builder()
|
|
|
+ .orderId(orderId)
|
|
|
+ .profitStatus(CaclEnum.GROSS_PROFIT_ANCESTOR_QUOTA_PERC_EXCEED_MAXIMUM_LIMIT.getType())
|
|
|
+ .orderNo(orderNo)
|
|
|
+ .userId(userId)
|
|
|
+ .amount(ancestorQuotaInt)
|
|
|
+ .afterAmount(ptProfitSaveReqVOS.stream().mapToLong(PtProfitSaveReqVO::getPtGrossAdd).sum() + ancestorQuotaInt)
|
|
|
+ .build();
|
|
|
+ ptProfitLogService.createPtProfitLog(ptProfitLog);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
private PtProfitDO calcPtProfit(PtProfitDO ptProfitDO, List<PtProfitSaveReqVO> ptProfitSaveReqVOS) {
|
|
|
|
|
|
Long currentPtAdd = 0L;
|
|
@@ -386,10 +440,14 @@ public class OrderCalcServiceImpl implements OrderCalcService {
|
|
|
// todo 增加累计额度
|
|
|
|
|
|
integralDO.setCurrentQuota(integralDO.getCurrentQuota() + descendantQuota);
|
|
|
-
|
|
|
-
|
|
|
+ integralDO.setFreezeQuota(integralDO.getFreezeQuota() - descendantQuota);
|
|
|
// 增加推荐人额度
|
|
|
integralDOAncestor.setCurrentQuota(integralDOAncestor.getCurrentQuota() + ancestorQuota);
|
|
|
+ // 减少推荐人的可获取额度
|
|
|
+ integralDOAncestor.setHighQuota(integralDOAncestor.getHighQuota() - ancestorQuota);
|
|
|
+ integralDOAncestor.setAncestorQuota(integralDOAncestor.getAncestorQuota() + ancestorQuota);
|
|
|
+ integralService.updateIntegral(BeanUtils.toBean(integralDOAncestor, IntegralSaveReqVO.class));
|
|
|
+
|
|
|
// 增加平台额度
|
|
|
pt.setCurrentQuota(pt.getCurrentQuota() + ptA + ptB);
|
|
|
|
|
@@ -397,7 +455,6 @@ public class OrderCalcServiceImpl implements OrderCalcService {
|
|
|
// integralSaveReqVOS.add(BeanUtils.toBean(integralDOAncestor, IntegralSaveReqVO.class));
|
|
|
|
|
|
integralService.updateIntegral(BeanUtils.toBean(integralDO, IntegralSaveReqVO.class));
|
|
|
- integralService.updateIntegral(BeanUtils.toBean(integralDOAncestor, IntegralSaveReqVO.class));
|
|
|
integralService.updateIntegral(BeanUtils.toBean(pt, IntegralSaveReqVO.class));
|
|
|
|
|
|
}
|
|
@@ -409,4 +466,4 @@ public class OrderCalcServiceImpl implements OrderCalcService {
|
|
|
}
|
|
|
|
|
|
|
|
|
-}
|
|
|
+}
|