|
@@ -6,10 +6,12 @@ import cn.newfeifan.mall.module.distri.controller.admin.duser.vo.DuserSaveReqVO;
|
|
|
import cn.newfeifan.mall.module.distri.controller.admin.integral.vo.IntegralSaveReqVO;
|
|
|
import cn.newfeifan.mall.module.distri.controller.admin.ptprofit.vo.PtProfitSaveReqVO;
|
|
|
import cn.newfeifan.mall.module.distri.controller.admin.ptprofitlog.vo.PtProfitLogSaveReqVO;
|
|
|
+import cn.newfeifan.mall.module.distri.controller.admin.sharepath.vo.SharePathSaveReqVO;
|
|
|
import cn.newfeifan.mall.module.distri.dal.dataobject.integral.IntegralDO;
|
|
|
import cn.newfeifan.mall.module.distri.dal.dataobject.orderpercentage.OrderPercentageDO;
|
|
|
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.service.duser.DuserService;
|
|
|
import cn.newfeifan.mall.module.distri.service.integral.IntegralService;
|
|
|
import cn.newfeifan.mall.module.distri.service.orderpercentage.OrderPercentageService;
|
|
@@ -21,23 +23,20 @@ import org.springframework.stereotype.Service;
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
-import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
-import java.awt.print.PrinterGraphics;
|
|
|
-import java.math.BigDecimal;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
import cn.newfeifan.mall.module.distri.controller.admin.ordercalc.vo.*;
|
|
|
import cn.newfeifan.mall.module.distri.dal.dataobject.ordercalc.OrderCalcDO;
|
|
|
import cn.newfeifan.mall.framework.common.pojo.PageResult;
|
|
|
-import cn.newfeifan.mall.framework.common.pojo.PageParam;
|
|
|
import cn.newfeifan.mall.framework.common.util.object.BeanUtils;
|
|
|
|
|
|
import cn.newfeifan.mall.module.distri.dal.mysql.ordercalc.OrderCalcMapper;
|
|
|
|
|
|
import static cn.newfeifan.mall.framework.common.exception.util.ServiceExceptionUtil.exception;
|
|
|
import static cn.newfeifan.mall.module.distri.constant.DistriConstants.PERCENT;
|
|
|
+import static cn.newfeifan.mall.module.distri.constant.DistriConstants.THREE;
|
|
|
import static cn.newfeifan.mall.module.distri.enums.ErrorCodeConstants.*;
|
|
|
|
|
|
/**
|
|
@@ -113,7 +112,6 @@ public class OrderCalcServiceImpl implements OrderCalcService {
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
@Override
|
|
|
public void calc(List<DistriOrderMessage> tradeOrderDO) {
|
|
|
|
|
@@ -121,6 +119,8 @@ public class OrderCalcServiceImpl implements OrderCalcService {
|
|
|
List<Long> userId = tradeOrderDO.stream().map(DistriOrderMessage::getUserId).collect(Collectors.toList());
|
|
|
// 判断当前下单的人员是否有进入营销模块用户表, 如果没有的话, 需要初始化
|
|
|
duserService.hasUserAndCreat(userId);
|
|
|
+ // 判断当前下单人是否有有上级, 如果没有, 创建直推人关系
|
|
|
+ sharePathService.createSharePathByUserId(userId);
|
|
|
|
|
|
OrderPercentageDO orderPercentageDO = orderPercentageService.queryStatus();
|
|
|
// 当前计算百分比模板
|
|
@@ -130,7 +130,6 @@ public class OrderCalcServiceImpl implements OrderCalcService {
|
|
|
|
|
|
// todo 计算当天用户的碰撞
|
|
|
|
|
|
-
|
|
|
}
|
|
|
|
|
|
private void calc(List<DistriOrderMessage> tradeOrderDO, OrderPercentageDO orderPercentageDO, String percentTemplate) {
|
|
@@ -140,11 +139,9 @@ public class OrderCalcServiceImpl implements OrderCalcService {
|
|
|
List<PtProfitSaveReqVO> ptProfitSaveReqVOS = new ArrayList<>();
|
|
|
// 平台收益日志
|
|
|
List<PtProfitLogSaveReqVO> ptProfitLogSaveReqVOS = new ArrayList<>();
|
|
|
-
|
|
|
// 修改用户钱包
|
|
|
List<IntegralSaveReqVO> integralSaveReqVOS = new ArrayList<>();
|
|
|
|
|
|
-
|
|
|
// todo 修改用户身价 如何从订单中获取身价?
|
|
|
List<DuserSaveReqVO> duserSaveReqVOS = new ArrayList<>();
|
|
|
|
|
@@ -152,27 +149,31 @@ public class OrderCalcServiceImpl implements OrderCalcService {
|
|
|
tradeOrderDO.forEach(k -> {
|
|
|
// 获取当前下单人关系
|
|
|
SharePathDO sharePath = getSharePath(k.getUserId());
|
|
|
- // 获取下单人的钱包以及用户表
|
|
|
- IntegralDO integralDO = integralService.selectByUser(sharePath.getDescendant());
|
|
|
+ // 如果sharePath为空, 则说明没有直推人关系
|
|
|
IntegralDO integralDOAncestor = integralService.selectByUser(sharePath.getAncestor());
|
|
|
+ IntegralDO integralDO = integralService.selectByUser(sharePath.getDescendant());
|
|
|
|
|
|
// 计算利润: (价格 - 成本价格) * 产品数量
|
|
|
Integer profit = (k.getPrice() - k.getCostPrice()) * k.getProductCount();
|
|
|
// 计算毛利: 利润 * 0.38
|
|
|
Integer grossProfit = profit * orderPercentageDO.getGrossProfitPerc();
|
|
|
- // 计算推荐人额度: 利润 * 0.38
|
|
|
+ // 计算推荐人额度: 毛利 * 0.35
|
|
|
Integer ancestorQuota = grossProfit * orderPercentageDO.getGrossProfitUserQuotaPerc();
|
|
|
- // 计算直推人额度: 利润 * 0.38
|
|
|
+ // 计算直推人额度: 毛利 * 0.35
|
|
|
Integer descendantQuota = grossProfit * orderPercentageDO.getGrossProfitAncestorQuotaPerc();
|
|
|
- // 计算合赢奖: 利润 * 0.38
|
|
|
+ // 计算合赢奖: 毛利 * 0.08
|
|
|
Integer bonusQuota = grossProfit * orderPercentageDO.getGrossProfitBonusQuotaPerc();
|
|
|
- // 计算平台收益: 利润 * 0.38
|
|
|
+ // 计算平台收益: 毛利 * 0.22
|
|
|
Integer platformQuota = grossProfit * orderPercentageDO.getGrossProfitPlatformQuotaPerc();
|
|
|
|
|
|
+ // 计算当前下单人的毛利的三倍
|
|
|
+ Integer highQuota = grossProfit * THREE;
|
|
|
+
|
|
|
+
|
|
|
// ========== 汇总计算 =================
|
|
|
addCaclDo(percentTemplate, saveList, k, grossProfit, ancestorQuota, descendantQuota, bonusQuota, platformQuota);
|
|
|
// ========== 修改用户钱包 =================
|
|
|
- changeUserWallet(integralSaveReqVOS, integralDO, integralDOAncestor, ancestorQuota, descendantQuota);
|
|
|
+ changeUserWallet(integralSaveReqVOS, integralDO, integralDOAncestor, ancestorQuota, descendantQuota, highQuota);
|
|
|
// ========== 修改平台信息 =================
|
|
|
// 每个订单计算的过程
|
|
|
// 增加平台收益
|
|
@@ -189,7 +190,72 @@ public class OrderCalcServiceImpl implements OrderCalcService {
|
|
|
.ptTotalAdd(ptTotal).build();
|
|
|
ptProfitSaveReqVOS.add(ptProfitSaveReqVO);
|
|
|
// ========== 增加日志记录 =================
|
|
|
- addLog(orderPercentageDO, percentTemplate, ptProfitLogSaveReqVOS, k, sharePath, integralDO, integralDOAncestor, grossProfit, ancestorQuota, descendantQuota, bonusQuota, platformQuota, 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 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 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 hyjLog = PtProfitLogSaveReqVO.builder()
|
|
|
+ .orderId(k.getOrderId())
|
|
|
+ .profitStatus(CaclEnum.TOGETHER_AWARD.getType())
|
|
|
+ .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);
|
|
|
+
|
|
|
+
|
|
|
});
|
|
|
|
|
|
// 将信息存储到数据库中
|
|
@@ -215,9 +281,13 @@ public class OrderCalcServiceImpl implements OrderCalcService {
|
|
|
saveList.add(orderCalcSaveReqVO);
|
|
|
}
|
|
|
|
|
|
- private static void changeUserWallet(List<IntegralSaveReqVO> integralSaveReqVOS, IntegralDO integralDO, IntegralDO integralDOAncestor, Integer ancestorQuota, Integer descendantQuota) {
|
|
|
+ private static void changeUserWallet(List<IntegralSaveReqVO> integralSaveReqVOS, IntegralDO integralDO, IntegralDO integralDOAncestor, Integer ancestorQuota, Integer descendantQuota, Integer highQuota) {
|
|
|
// 修改用户钱包
|
|
|
+ // 增加直推人额度
|
|
|
+ integralDO.setHighQuota(integralDO.getHighQuota() + highQuota);
|
|
|
integralDO.setCurrentQuota(integralDO.getCurrentQuota() + descendantQuota);
|
|
|
+
|
|
|
+ // 增加推荐人额度
|
|
|
integralDOAncestor.setCurrentQuota(integralDO.getCurrentQuota() + ancestorQuota);
|
|
|
|
|
|
integralSaveReqVOS.add(BeanUtils.toBean(integralDO, IntegralSaveReqVO.class));
|
|
@@ -255,6 +325,15 @@ public class OrderCalcServiceImpl implements OrderCalcService {
|
|
|
.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()
|
|
@@ -282,10 +361,10 @@ public class OrderCalcServiceImpl implements OrderCalcService {
|
|
|
ptProfitLogSaveReqVOS.add(tjrLog);
|
|
|
ptProfitLogSaveReqVOS.add(ztrLog);
|
|
|
ptProfitLogSaveReqVOS.add(hyjLog);
|
|
|
+ ptProfitLogSaveReqVOS.add(highQuotaLog);
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
// 获取当前订单的下单人的直推关系
|
|
|
public SharePathDO getSharePath(Long userId) {
|
|
|
|