Jelajahi Sumber

首次提交

Yangzw 2 bulan lalu
induk
melakukan
eb6031ed00

+ 17 - 19
feifan-module-distri/feifan-module-distri-biz/src/main/java/cn/newfeifan/mall/module/distri/dal/mysql/sharepath/SharePathMapper.java

@@ -22,24 +22,15 @@ public interface SharePathMapper extends BaseMapperX<SharePathDO> {
         return selectPage(reqVO, new LambdaQueryWrapperX<SharePathDO>()
                 .eqIfPresent(SharePathDO::getDepth, reqVO.getDepth())
                 .betweenIfPresent(SharePathDO::getCreateTime, reqVO.getCreateTime())
-                .eqIfPresent(SharePathDO::getAncestor, reqVO.getAncestor())
-                .eqIfPresent(SharePathDO::getDescendant, reqVO.getDescendant())
-                .eqIfPresent(SharePathDO::getSort, reqVO.getSort())
-                .likeIfPresent(SharePathDO::getAncName, reqVO.getAncName())
-                .eqIfPresent(SharePathDO::getAncPhone, reqVO.getAncPhone())
-                .likeIfPresent(SharePathDO::getDescName, reqVO.getDescName())
-                .eqIfPresent(SharePathDO::getDescPhone, reqVO.getDescPhone())
-                .likeIfPresent(SharePathDO::getAncNickName, reqVO.getAncNickName())
-                .likeIfPresent(SharePathDO::getDescNickName, reqVO.getDescNickName())
+                .eqIfPresent(SharePathDO::getReferrerId, reqVO.getReferrerId())
+                .eqIfPresent(SharePathDO::getUserId, reqVO.getUserId())
+                .eqIfPresent(SharePathDO::getPhone, reqVO.getPhone())
+                .likeIfPresent(SharePathDO::getUserName, reqVO.getUserName())
                 .orderByDesc(SharePathDO::getId));
     }
     default PageResult<SharePathDO> selectDescendantsPage(SharePathPageReqVO reqVO) {
         LambdaQueryWrapperX<SharePathDO> queryWrapper = new LambdaQueryWrapperX<SharePathDO>()
-                .eqIfPresent(SharePathDO::getAncestor, reqVO.getAncestor());
-        if(reqVO.getDepth() != null){
-            queryWrapper.eq(SharePathDO::getDepth, 1);
-            queryWrapper.orderByAsc(SharePathDO::getSort);
-        }
+                .eqIfPresent(SharePathDO::getReferrerId, reqVO.getUserId());
         return selectPage(reqVO, queryWrapper);
     }
 
@@ -70,13 +61,10 @@ public interface SharePathMapper extends BaseMapperX<SharePathDO> {
     List<Long> findLessSortedSiblings(@Param("descendantId") Long descendantId);
 
 
-    List<TreeNode> selectDescendants(@Param("ancestor") Long userId,  @Param("maxDepth") Integer maxDepth);
-
     default Long selectAncestorByDescendant(Long userId){
         return selectOne(new LambdaQueryWrapperX<SharePathDO>()
-                .eq(SharePathDO::getDescendant, userId)
-                .eq(SharePathDO::getDepth, 1)
-        ).getAncestor();
+                .eq(SharePathDO::getUserId, userId)
+        ).getReferrerId();
     }
 
     /**
@@ -86,6 +74,16 @@ public interface SharePathMapper extends BaseMapperX<SharePathDO> {
      * @return 分销关系
      */
     List<SharePathDO> selectListByVisitor(@Param("ancestor") Long ancestor, @Param("visitor") Boolean visitor);
+
+    /**
+     * 根据用户id查询分享关系
+     * @param userId 用户关系
+     * @param maxDepth 最大层级
+     * @return 分销关系
+     */
+    List<SharePathDO> selectListByUserId(@Param("userId") Long userId, @Param("maxDepth") Integer maxDepth);
+
+    List<SharePathDO> selectListPage(@Param("userId") Long userId, @Param("pageSize") Integer pageSize, @Param("pageNo") Integer pageNo);
 }
 
 

+ 35 - 89
feifan-module-distri/feifan-module-distri-biz/src/main/java/cn/newfeifan/mall/module/distri/service/ordercalc/OrderCalcServiceImpl.java

@@ -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));

+ 8 - 10
feifan-module-distri/feifan-module-distri-biz/src/main/java/cn/newfeifan/mall/module/distri/service/usertopupconsumptionpointsorder/UserTopUpConsumptionPointsOrderServiceImpl.java

@@ -1,10 +1,10 @@
 package cn.newfeifan.mall.module.distri.service.usertopupconsumptionpointsorder;
 
-import cn.newfeifan.mall.module.distri.controller.admin.consumptionchangelog.vo.ConsumptionChangeLogSaveReqVO;
+import cn.newfeifan.mall.module.distri.controller.admin.integralchangelog.vo.IntegralChangeLogSaveReqVO;
 import cn.newfeifan.mall.module.distri.controller.admin.integral.vo.IntegralSaveReqVO;
 import cn.newfeifan.mall.module.distri.dal.dataobject.integral.IntegralDO;
-import cn.newfeifan.mall.module.distri.enums.ConsumptionEnum;
-import cn.newfeifan.mall.module.distri.service.consumptionchangelog.ConsumptionChangeLogService;
+import cn.newfeifan.mall.module.distri.enums.IntegralEnum;
+import cn.newfeifan.mall.module.distri.service.integralchangelog.IntegralChangeLogService;
 import cn.newfeifan.mall.module.distri.service.integral.IntegralService;
 import cn.newfeifan.mall.module.pay.dal.dataobject.order.PayOrderDO;
 import org.springframework.stereotype.Service;
@@ -37,7 +37,7 @@ public class UserTopUpConsumptionPointsOrderServiceImpl implements UserTopUpCons
     @Resource
     private IntegralService integralService;
     @Resource
-    private ConsumptionChangeLogService consumptionChangeLogService;
+    private IntegralChangeLogService integralChangeLogService;
 
     @Override
     public Long createUserTopUpConsumptionPointsOrder(UserTopUpConsumptionPointsOrderSaveReqVO createReqVO) {
@@ -101,16 +101,14 @@ public class UserTopUpConsumptionPointsOrderServiceImpl implements UserTopUpCons
 
         // 获取钱包
         IntegralDO integralDO = integralService.selectByUser(topUpOrder.getUserId());
-        integralDO.setConsumptionPoints(integralDO.getConsumptionPoints() + topUpOrder.getPracticalConsumptionPoints());
         integralService.updateIntegral(BeanUtils.toBean(integralDO, IntegralSaveReqVO.class));
 
         // 消费分变动日志
-        consumptionChangeLogService.createConsumptionChangeLog(ConsumptionChangeLogSaveReqVO.builder()
+        integralChangeLogService.createConsumptionChangeLog(IntegralChangeLogSaveReqVO.builder()
                 .userId(topUpOrder.getUserId())
-                .consumptionStatus(ConsumptionEnum.TOP_UP_GET.getType())
-                .consumptionPoints(topUpOrder.getPracticalConsumptionPoints())
-                .afterConsumptionPoints(integralDO.getConsumptionPoints())
-                .practicalConsumptionPoints(topUpOrder.getTopUpConsumptionPoints())
+                .integralStatus(IntegralEnum.TOP_UP_GET.getType())
+                .integralPoints(topUpOrder.getPracticalConsumptionPoints())
+                .practicalIntegralPoints(topUpOrder.getTopUpConsumptionPoints())
                 .generateUserId(topUpOrder.getUserId())
                 .build());
     }