|
@@ -1,8 +1,14 @@
|
|
|
package cn.newfeifan.mall.module.distri.service.ordercalc;
|
|
|
|
|
|
import cn.newfeifan.mall.framework.common.mq.message.order.DistriOrderMessage;
|
|
|
+import cn.newfeifan.mall.framework.common.util.json.JsonUtils;
|
|
|
+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.dal.dataobject.orderpercentage.OrderPercentageDO;
|
|
|
+import cn.newfeifan.mall.module.distri.dal.dataobject.ptprofit.PtProfitDO;
|
|
|
import cn.newfeifan.mall.module.distri.service.orderpercentage.OrderPercentageService;
|
|
|
+import cn.newfeifan.mall.module.distri.service.ptprofit.PtProfitService;
|
|
|
+import cn.newfeifan.mall.module.distri.service.ptprofitlog.PtProfitLogService;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
@@ -22,6 +28,7 @@ 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.enums.ErrorCodeConstants.*;
|
|
|
|
|
|
/**
|
|
@@ -36,6 +43,13 @@ public class OrderCalcServiceImpl implements OrderCalcService {
|
|
|
@Resource
|
|
|
private OrderCalcMapper orderCalcMapper;
|
|
|
|
|
|
+ @Resource
|
|
|
+ private PtProfitService ptProfitService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private PtProfitLogService ptProfitLogService;
|
|
|
+
|
|
|
+
|
|
|
@Override
|
|
|
public Long createOrderCalc(OrderCalcSaveReqVO createReqVO) {
|
|
|
// 插入
|
|
@@ -85,8 +99,18 @@ public class OrderCalcServiceImpl implements OrderCalcService {
|
|
|
public void calc(List<DistriOrderMessage> tradeOrderDO) {
|
|
|
|
|
|
OrderPercentageDO orderPercentageDO = orderPercentageService.queryStatus();
|
|
|
+ // 当前计算百分比模板
|
|
|
+ String percentTemplate = JsonUtils.toJsonString(orderPercentageDO);
|
|
|
+
|
|
|
|
|
|
+ // 每个订单收益
|
|
|
List<OrderCalcSaveReqVO> saveList = new ArrayList<>();
|
|
|
+ // 平台收益
|
|
|
+ List<PtProfitSaveReqVO> ptProfitSaveReqVOS = new ArrayList<>();
|
|
|
+ // 平台收益日志
|
|
|
+ List<PtProfitLogSaveReqVO> ptProfitLogSaveReqVOS = new ArrayList<>();
|
|
|
+
|
|
|
+ PtProfitDO ptProfitDO = ptProfitService.getPtProfit();
|
|
|
|
|
|
tradeOrderDO.forEach(k -> {
|
|
|
|
|
@@ -115,17 +139,52 @@ public class OrderCalcServiceImpl implements OrderCalcService {
|
|
|
.grossProfitAncestorQuota(ancestorQuota)
|
|
|
.grossProfitBonusQuota(bonusQuota)
|
|
|
.grossProfitPlatformQuota(platformQuota)
|
|
|
+ .percentTemplate(percentTemplate)
|
|
|
.build();
|
|
|
saveList.add(orderCalcSaveReqVO);
|
|
|
|
|
|
// 每个订单计算的过程
|
|
|
-
|
|
|
// 增加平台收益
|
|
|
+ // 平台服务费
|
|
|
+ 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();
|
|
|
+ ptProfitSaveReqVOS.add(ptProfitSaveReqVO);
|
|
|
+
|
|
|
+ // 平台记录
|
|
|
+ PtProfitLogSaveReqVO ptGrossAddLog = PtProfitLogSaveReqVO.builder()
|
|
|
+ .orderId(k.getOrderId())
|
|
|
+ .profitStatus(1)
|
|
|
+ .amount(platformQuota)
|
|
|
+ .afterAmount(ptProfitSaveReqVO.getPtGrossAdd())
|
|
|
+ .percentTemplate(percentTemplate).build();
|
|
|
+
|
|
|
+ PtProfitLogSaveReqVO ptAddLog = PtProfitLogSaveReqVO.builder()
|
|
|
+ .orderId(k.getOrderId())
|
|
|
+ .profitStatus(2)
|
|
|
+ .amount(grossProfit * (PERCENT - orderPercentageDO.getGrossProfitBonusQuotaPerc()))
|
|
|
+ .afterAmount(ptProfitSaveReqVO.getPtAdd())
|
|
|
+ .percentTemplate(percentTemplate).build();
|
|
|
+ ptProfitLogSaveReqVOS.add(ptGrossAddLog);
|
|
|
+ ptProfitLogSaveReqVOS.add(ptAddLog);
|
|
|
|
|
|
|
|
|
+ });
|
|
|
|
|
|
+ // 将信息存储到数据库中
|
|
|
+ orderCalcMapper.insertBatch(BeanUtils.toBean(saveList, OrderCalcDO.class));
|
|
|
+ ptProfitService.saveBatch(ptProfitSaveReqVOS);
|
|
|
+ ptProfitLogService.saveBatch(ptProfitLogSaveReqVOS);
|
|
|
|
|
|
- });
|
|
|
+
|
|
|
+ // todo 计算当天用户的碰撞
|
|
|
|
|
|
|
|
|
}
|