Browse Source

更新计算程序

Yangzw 9 months ago
parent
commit
e4938f7178

+ 2 - 0
feifan-module-distri/feifan-module-distri-biz/src/main/java/cn/newfeifan/mall/module/distri/controller/admin/duser/vo/DuserRespVO.java

@@ -76,4 +76,6 @@ public class DuserRespVO {
     @Schema(description = "用户头像")
     private String avatar;
 
+    @Schema(description = "用户积分")
+    private Long integral;
 }

+ 11 - 3
feifan-module-distri/feifan-module-distri-biz/src/main/java/cn/newfeifan/mall/module/distri/service/duser/DuserServiceImpl.java

@@ -72,6 +72,8 @@ public class DuserServiceImpl implements DuserService {
     @Resource
     private SocialStatusChangeLogService socialStatusChangeLogService;
 
+
+
     @Override
     public Long createDuser(DuserSaveReqVO createReqVO) {
         // 插入
@@ -303,9 +305,15 @@ public class DuserServiceImpl implements DuserService {
             duserRespVO.setAvatar(memberUserService.getUser(duserRespVO.getUserId()).getAvatar());
 
             SocialStatusDO socialStatus = socialStatusService.getSocialStatus(duserRespVO.getSocialStatusId());
-            if(socialStatus == null) continue;
-            duserRespVO.setSocialStatusLevel(socialStatus.getLevel());
-            duserRespVO.setSocialStatusLevelName(socialStatus.getName());
+            if(socialStatus != null) {
+                duserRespVO.setSocialStatusLevel(socialStatus.getLevel());
+                duserRespVO.setSocialStatusLevelName(socialStatus.getName());
+            }
+
+            IntegralDO integral = integralService.getIntegral(duserRespVO.getIntegralId());
+            if(integral != null){
+                duserRespVO.setIntegral(integral.getCurrentQuota());
+            }
         }
     }
 }

+ 56 - 27
feifan-module-distri/feifan-module-distri-biz/src/main/java/cn/newfeifan/mall/module/distri/service/partitioncrash/PartitionCrashServiceImpl.java

@@ -142,11 +142,14 @@ public class PartitionCrashServiceImpl implements PartitionCrashService {
     @Override
     public void calcCrash(List<Long> userId) {
 
+        Map<Long, Long> userHighQuotaMap = new HashMap<>();
+
         // 获取所有的营销用户
         List<DuserDO> duserDOS = duserService.selectAllUser();
         if (duserDOS.isEmpty()) {
             return;
         }
+        //记录所有用户的id和积分
         List<HashMap<Long, Long>> afterCrashMap = new ArrayList<>();
         // 获取当前合赢奖百分比
         OrderPercentageDO orderPercentageDO = orderPercentageService.queryStatus();
@@ -266,7 +269,10 @@ public class PartitionCrashServiceImpl implements PartitionCrashService {
                 BigDecimal multiply = smallBigDecimal.divide(new BigDecimal("2.0"), 4, RoundingMode.DOWN);
                 if (compare(highQuota, multiply) && multiply.longValue() != 0) {
                     integralDO.setCurrentQuota(integralDO.getCurrentQuota() + multiply.intValue());
-//                    integralDO.setHighQuota(integralDO.getHighQuota() - multiply.intValue());
+                    integralDO.setHighQuota(integralDO.getHighQuota() - multiply.intValue());
+
+                    addHighQuota(userHighQuotaMap, integralDO.getUserId(), (long) multiply.intValue());
+
                     integralDO.setAccumulatedQuota(integralDO.getAccumulatedQuota() + multiply.intValue());
                     // 碰撞后的额度添加到日志中 增加日志模块
                     integralService.updateIntegral(BeanUtils.toBean(integralDO, IntegralSaveReqVO.class));
@@ -275,16 +281,19 @@ public class PartitionCrashServiceImpl implements PartitionCrashService {
                 if (compare(parentHighQuota, multiply) && multiply.longValue() != 0) {
                     // 减去最高额度
                     parentIntegralDo.setCurrentQuota(parentIntegralDo.getCurrentQuota() + multiply.intValue());
-//                    parentIntegralDo.setHighQuota(parentIntegralDo.getHighQuota() - multiply.intValue());
+                    parentIntegralDo.setHighQuota(parentIntegralDo.getHighQuota() - multiply.intValue());
+
+                    addHighQuota(userHighQuotaMap, parentIntegralDo.getUserId(), (long) multiply.intValue());
+
                     parentIntegralDo.setAccumulatedQuota(parentIntegralDo.getAccumulatedQuota() + multiply.intValue());
                     // 碰撞后的额度添加到日志中 增加日志模块
                     integralService.updateIntegral(BeanUtils.toBean(parentIntegralDo, IntegralSaveReqVO.class));
                     ptProfitLogService.addMessage(parentIntegralDo.getUserId(), CaclEnum.SMALL_QUOTA_CRASH, Long.parseLong(String.valueOf(multiply.intValue())), parentIntegralDo.getCurrentQuota(), JsonUtils.toJsonString(orderPercentageDO));
                 }
-                if(highQuota < multiply.longValue() && multiply.longValue() != 0L){
+                if (highQuota < multiply.longValue() && multiply.longValue() != 0L) {
                     calcIntegral(multiply.longValue(), integralDO.getUserId(), JsonUtils.toJsonString(orderPercentageDO));
                 }
-                if(parentHighQuota < multiply.longValue() && multiply.longValue() != 0L){
+                if (parentHighQuota < multiply.longValue() && multiply.longValue() != 0L) {
                     calcIntegral(multiply.longValue(), parentIntegralDo.getUserId(), JsonUtils.toJsonString(orderPercentageDO));
                 }
 
@@ -336,32 +345,41 @@ public class PartitionCrashServiceImpl implements PartitionCrashService {
                 // 获取当前用户的钱包
                 IntegralDO integralDO = integralDOMap.get(entry.getKey());
                 // 获取当前父亲的钱包
-                Long parent = sonAndParent.get(entry.getKey());
-                IntegralDO parentIntegralDo = integralDOMap.get(parent);
+//                Long parent = sonAndParent.get(entry.getKey());
+//                IntegralDO parentIntegralDo = integralDOMap.get(parent);
                 Long highQuota = integralDO.getHighQuota() + new BigDecimal(orderPercentageDO.getBaseMaxQuota()).longValue();       //加上基础的最大额度值
-                Long parentHighQuota = parentIntegralDo.getHighQuota() + new BigDecimal(orderPercentageDO.getBaseMaxQuota()).longValue();
-                if(highQuota  < entry.getValue()){
-                    continue;
-                }
-                if(parentHighQuota < entry.getValue()){
-                    continue;
+
+                for (Long key : userHighQuotaMap.keySet()) {
+                    if (key.equals(entry.getKey())) {
+                        if (userHighQuotaMap.get(key) > 0L) {
+                            highQuota = highQuota + entry.getValue();
+                            userHighQuotaMap.put(key, userHighQuotaMap.get(key) - entry.getValue());
+                            break;
+                        }
+                    }
                 }
 
-                integralDO.setHighQuota(integralDO.getHighQuota() - entry.getValue());
-                parentIntegralDo.setHighQuota(parentIntegralDo.getHighQuota() - entry.getValue());
-                integralService.updateIntegral(BeanUtils.toBean(integralDO, IntegralSaveReqVO.class));
-                integralService.updateIntegral(BeanUtils.toBean(parentIntegralDo, IntegralSaveReqVO.class));
-
-                // 扣除平台收益
-                log.info("扣除平台收益[合赢奖] " + "用户 " + entry.getKey() + "额度: " + entry.getValue());
-                ptProfit.setPtGrossAdd(ptProfit.getPtGrossAdd() - entry.getValue());
-                // 平台扣除积分
-                ptProfit.setPtTotalAdd(ptProfit.getPtTotalAdd() - entry.getValue());
-                // 碰撞后的额度添加到日志中 增加日志模块
-                ptProfitLogService.addMessage(entry.getKey(), CaclEnum.AFTER_CRASH_CALC_PT_TOTAL_QUOTA
-                        , -entry.getValue(), ptProfit.getPtTotalAdd(), JsonUtils.toJsonString(orderPercentageDO));
-                ptProfitLogService.addMessage(entry.getKey(), CaclEnum.AFTER_CRASH_CALC_PT_TOTAL_GROSS_QUOTA
-                        , -entry.getValue(), ptProfit.getPtTotalAdd(), JsonUtils.toJsonString(orderPercentageDO));
+//                Long parentHighQuota = parentIntegralDo.getHighQuota() + new BigDecimal(orderPercentageDO.getBaseMaxQuota()).longValue();
+                if (highQuota >= entry.getValue()) {
+//                    integralDO.setHighQuota(integralDO.getHighQuota() - entry.getValue());
+                    integralService.updateIntegral(BeanUtils.toBean(integralDO, IntegralSaveReqVO.class));
+//                if (parentHighQuota >= entry.getValue()) {
+//                    parentIntegralDo.setHighQuota(parentIntegralDo.getHighQuota() - entry.getValue());
+//                    integralService.updateIntegral(BeanUtils.toBean(parentIntegralDo, IntegralSaveReqVO.class));
+//                }
+
+
+                    // 扣除平台收益
+                    log.info("扣除平台收益[合赢奖] " + "用户 " + entry.getKey() + "额度: " + entry.getValue());
+                    ptProfit.setPtGrossAdd(ptProfit.getPtGrossAdd() - entry.getValue());
+                    // 平台扣除积分
+                    ptProfit.setPtTotalAdd(ptProfit.getPtTotalAdd() - entry.getValue());
+                    // 碰撞后的额度添加到日志中 增加日志模块
+                    ptProfitLogService.addMessage(entry.getKey(), CaclEnum.AFTER_CRASH_CALC_PT_TOTAL_QUOTA
+                            , -entry.getValue(), ptProfit.getPtTotalAdd(), JsonUtils.toJsonString(orderPercentageDO));
+                    ptProfitLogService.addMessage(entry.getKey(), CaclEnum.AFTER_CRASH_CALC_PT_TOTAL_GROSS_QUOTA
+                            , -entry.getValue(), ptProfit.getPtTotalAdd(), JsonUtils.toJsonString(orderPercentageDO));
+                }
             }
         }
         ptProfitService.updatePtProfit(PtProfitSaveReqVO.builder().id(ptProfit.getId())
@@ -382,6 +400,17 @@ public class PartitionCrashServiceImpl implements PartitionCrashService {
         createPtProfitDailyStatisticsLog(sum);
     }
 
+    //向集合中放用户获取的积分
+    private void addHighQuota(Map<Long, Long> map, Long userId, Long value) {
+        for (Long key : map.keySet()) {
+            if (key.equals(userId)) {
+                map.put(key, map.get(key) + value);
+                break;
+            }
+        }
+        map.put(userId, value);
+    }
+
     private void calcIntegral(Long multiply, Long userId, String jsonString) {
         PtProfitDO ptProfit = ptProfitService.getPtProfit();
         ptProfitLogService.addMessage(userId, CaclEnum.GROSS_PROFIT_BONUS_QUOTA_PERC_EXCEED_MAXIMUM_LIMIT, multiply,

+ 4 - 2
feifan-module-member/feifan-module-member-biz/src/main/java/cn/newfeifan/mall/module/member/service/user/MemberUserServiceImpl.java

@@ -326,8 +326,10 @@ public class MemberUserServiceImpl implements MemberUserService {
         }
 
         MemberUserDO memberUserDO = memberUserMapper.selectByMobile(mobile);
-        memberUserDO.setSystemUsersId(systemUserId);
-        memberUserMapper.updateById(memberUserDO);
+        if(memberUserDO!=null){
+            memberUserDO.setSystemUsersId(systemUserId);
+            memberUserMapper.updateById(memberUserDO);
+        }
     }
 
     @Override