From cadeca36ff86f74371c77a05dc8422abc1e48855 Mon Sep 17 00:00:00 2001
From: KKSU <15274802129@163.com>
Date: Thu, 19 Dec 2024 16:28:40 +0800
Subject: [PATCH] feat(table): 添加合计行功能 - 在 mallMemberList.html 中添加了 totalRow 属性,用于显示碳币和碳积分的合计 - 在 moneyFlowList.html 中移除了 description 字段的 totalRow属性 - 在 sellVipList.html 中将 amount 和 amountFee 字段的 totalRow 属性改为 true
---
src/main/java/cc/mrbird/febs/mall/service/impl/MemberProfitServiceImpl.java | 367 ++++++++++++++++++++++++++++++++++++++--------------
1 files changed, 268 insertions(+), 99 deletions(-)
diff --git a/src/main/java/cc/mrbird/febs/mall/service/impl/MemberProfitServiceImpl.java b/src/main/java/cc/mrbird/febs/mall/service/impl/MemberProfitServiceImpl.java
index f087359..d65136d 100644
--- a/src/main/java/cc/mrbird/febs/mall/service/impl/MemberProfitServiceImpl.java
+++ b/src/main/java/cc/mrbird/febs/mall/service/impl/MemberProfitServiceImpl.java
@@ -1,22 +1,23 @@
package cc.mrbird.febs.mall.service.impl;
-import cc.mrbird.febs.common.enumerates.AgentLevelEnum;
-import cc.mrbird.febs.common.enumerates.DataDictionaryEnum;
-import cc.mrbird.febs.common.enumerates.FlowTypeEnum;
-import cc.mrbird.febs.common.enumerates.MoneyFlowTypeEnum;
+import cc.mrbird.febs.common.enumerates.*;
import cc.mrbird.febs.common.utils.AppContants;
import cc.mrbird.febs.mall.entity.*;
import cc.mrbird.febs.mall.mapper.*;
+import cc.mrbird.febs.mall.service.AsyncService;
import cc.mrbird.febs.mall.service.IApiMallMemberWalletService;
-import cc.mrbird.febs.mall.service.IMallAchieveService;
import cc.mrbird.febs.mall.service.IMallMoneyFlowService;
import cc.mrbird.febs.mall.service.IMemberProfitService;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateField;
+import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUnit;
import cn.hutool.core.date.DateUtil;
+import cn.hutool.core.util.ObjectUtil;
+import cn.hutool.core.util.RandomUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.RequiredArgsConstructor;
@@ -27,6 +28,7 @@
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.*;
+import java.util.stream.Collectors;
/**
* @author wzy
@@ -45,23 +47,30 @@
private final IMallMoneyFlowService moneyFlowService;
private final DataDictionaryCustomMapper dataDictionaryCustomMapper;
private final MallMoneyFlowMapper mallMoneyFlowMapper;
- private final IMallAchieveService mallAchieveService;
+ private final MallAchieveRecordMapper mallAchieveRecordMapper;
+ private final MallMemberCouponMapper mallMemberCouponMapper;
+ private final RunVipMapper runVipMapper;
+ private final MallMemberWalletMapper mallMemberWalletMapper;
+
+ private final AsyncService asyncService;
@Override
@Transactional(rollbackFor = Exception.class)
- public void staticProfit() {
+ public void staticProfit(Date profitDate) {
log.info("#####静态分红开始运行:{}#####", new Date());
List<MallMember> members = mallMemberMapper.selectList(null);
if (CollUtil.isEmpty(members)) {
return;
}
- Date profitDate = DateUtil.offset(new Date(), DateField.DAY_OF_YEAR, -1);
+ if (profitDate == null) {
+ profitDate = DateUtil.offset(new Date(), DateField.DAY_OF_YEAR, -1);
+ }
// 套餐业绩
- BigDecimal tcIncome = mallOrderInfoMapper.selectTotalAmountUnCostForDate(profitDate, null, "D", 2);
+// BigDecimal tcIncome = mallOrderInfoMapper.selectTotalAmountUnCostForDate(profitDate, null, "D", 2);
// 普通商品业绩
- BigDecimal normalIncome = mallOrderInfoMapper.selectTotalAmountUnCostForDate(profitDate, null, "D", 1);
- BigDecimal totalIncome = tcIncome.add(normalIncome);
+// BigDecimal normalIncome = mallOrderInfoMapper.selectTotalAmountUnCostForDate(profitDate, null, "D", 1);
+ BigDecimal totalIncome = mallAchieveRecordMapper.selectAchieveTotal("D", profitDate);
if (totalIncome.compareTo(BigDecimal.ZERO) == 0) {
return;
@@ -109,14 +118,15 @@
Long memberId = (Long) item.get("memberId");
String orderNo = (String) item.get("orderNo");
- int reduce = walletService.reduce(preStaticProfit, memberId, "score");
- if (reduce == 2) {
- break;
- }
-
- walletService.add(preStaticProfit, memberId, "commission");
- moneyFlowService.addMoneyFlow(memberId, preStaticProfit, MoneyFlowTypeEnum.STATIC_BONUS.getValue(), orderNo, FlowTypeEnum.COMMISSION.getValue());
- moneyFlowService.addMoneyFlow(memberId, preStaticProfit.negate(), MoneyFlowTypeEnum.STATIC_BONUS.getValue(), orderNo, FlowTypeEnum.SCORE.getValue());
+// int reduce = walletService.reduce(preStaticProfit, memberId, "score");
+// if (reduce == 2) {
+// break;
+// }
+//
+// walletService.add(preStaticProfit, memberId, "commission");
+// moneyFlowService.addMoneyFlow(memberId, preStaticProfit, MoneyFlowTypeEnum.STATIC_BONUS.getValue(), orderNo, FlowTypeEnum.COMMISSION.getValue());
+// moneyFlowService.addMoneyFlow(memberId, preStaticProfit.negate(), MoneyFlowTypeEnum.STATIC_BONUS.getValue(), orderNo, FlowTypeEnum.SCORE.getValue());
+ changeScoreAndCommission(memberId, preStaticProfit, MoneyFlowTypeEnum.STATIC_BONUS.getValue(), orderNo);
}
}
}
@@ -179,15 +189,18 @@
continue;
}
- int reduce = walletService.reduce(dynamicProfit, parent.getId(), "score");
- if (reduce == 2) {
+// int reduce = walletService.reduce(dynamicProfit, parent.getId(), "score");
+// if (reduce == 2) {
+// continue;
+// }
+// walletService.add(dynamicProfit, parent.getId(), "commission");
+// moneyFlowService.addMoneyFlow(parent.getId(), dynamicProfit, MoneyFlowTypeEnum.DYNAMIC_ACHIEVE.getValue(), orderInfo.getOrderNo(), FlowTypeEnum.COMMISSION.getValue());
+// moneyFlowService.addMoneyFlow(parent.getId(), dynamicProfit.negate(), MoneyFlowTypeEnum.DYNAMIC_ACHIEVE.getValue(), orderInfo.getOrderNo(), FlowTypeEnum.SCORE.getValue());
+
+ dynamicProfit = changeScoreAndCommission(parent.getId(), dynamicProfit, MoneyFlowTypeEnum.DYNAMIC_ACHIEVE.getValue(), orderInfo.getOrderNo());
+ if (dynamicProfit.compareTo(BigDecimal.ZERO) < 1) {
continue;
}
-
- walletService.add(dynamicProfit, parent.getId(), "commission");
-
- moneyFlowService.addMoneyFlow(parent.getId(), dynamicProfit, MoneyFlowTypeEnum.DYNAMIC_ACHIEVE.getValue(), orderInfo.getOrderNo(), FlowTypeEnum.COMMISSION.getValue());
- moneyFlowService.addMoneyFlow(parent.getId(), dynamicProfit.negate(), MoneyFlowTypeEnum.DYNAMIC_ACHIEVE.getValue(), orderInfo.getOrderNo(), FlowTypeEnum.SCORE.getValue());
// =======直推返利== end =====
// =======隔代奖== start =====
@@ -211,7 +224,7 @@
Integer directCnt = mallMemberMapper.selectOwnCntByInviteId(parentMember.getInviteId());
List<DataDictionaryCustom> dataDices = dataDictionaryCustomMapper.selectDicByType(DataDictionaryEnum.INDIRECT_BONUS_SETTING.getType());
- directCnt = directCnt == null ? 0 :directCnt;
+ directCnt = directCnt == null ? 0 : directCnt;
// 隔代比例
BigDecimal indrectDicProp = BigDecimal.ZERO;
@@ -229,15 +242,15 @@
if (direct.compareTo(BigDecimal.ONE) < 1) {
break;
}
-
- int reduceResult = walletService.reduce(direct, parentMember.getId(), "score");
- if (reduceResult == 2) {
- continue;
- }
-
- walletService.add(direct, parentMember.getId(), "commission");
- moneyFlowService.addMoneyFlow(parentMember.getId(), direct, MoneyFlowTypeEnum.RECOMMEND_BONUS.getValue(), orderInfo.getOrderNo(), FlowTypeEnum.COMMISSION.getValue());
- moneyFlowService.addMoneyFlow(parentMember.getId(), direct.negate(), MoneyFlowTypeEnum.RECOMMEND_BONUS.getValue(), orderInfo.getOrderNo(), FlowTypeEnum.SCORE.getValue());
+// int reduceResult = walletService.reduce(direct, parentMember.getId(), "score");
+// if (reduceResult == 2) {
+// continue;
+// }
+//
+// walletService.add(direct, parentMember.getId(), "commission");
+// moneyFlowService.addMoneyFlow(parentMember.getId(), direct, MoneyFlowTypeEnum.RECOMMEND_BONUS.getValue(), orderInfo.getOrderNo(), FlowTypeEnum.COMMISSION.getValue());
+// moneyFlowService.addMoneyFlow(parentMember.getId(), direct.negate(), MoneyFlowTypeEnum.RECOMMEND_BONUS.getValue(), orderInfo.getOrderNo(), FlowTypeEnum.SCORE.getValue());
+ changeScoreAndCommission(parentMember.getId(), direct, MoneyFlowTypeEnum.RECOMMEND_BONUS.getValue(), orderInfo.getOrderNo());
}
// =======隔代奖== end =====
}
@@ -251,43 +264,64 @@
profitDate = DateUtil.offset(new Date(), DateField.DAY_OF_YEAR, -1);
}
// 套餐业绩
- BigDecimal tcIncome = mallOrderInfoMapper.selectTotalAmountUnCostForDate(profitDate, null, "D", 2);
+// BigDecimal tcIncome = mallOrderInfoMapper.selectTotalAmountUnCostForDate(profitDate, null, "D", 2);
// 普通商品业绩
- BigDecimal normalIncome = mallOrderInfoMapper.selectTotalAmountUnCostForDate(profitDate, null, "D", 1);
- BigDecimal totalIncome = tcIncome.add(normalIncome);
+// BigDecimal normalIncome = mallOrderInfoMapper.selectTotalAmountUnCostForDate(profitDate, null, "D", 1);
+ BigDecimal totalIncome = mallAchieveRecordMapper.selectAchieveTotal("D", profitDate);
DataDictionaryCustom dic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(DataDictionaryEnum.AGENT_BONUS.getType(), DataDictionaryEnum.AGENT_BONUS.getCode());
- BigDecimal profit = totalIncome.divide(new BigDecimal(dic.getValue()), 2, RoundingMode.HALF_UP);
- BigDecimal preProfit = profit.divide(BigDecimal.valueOf(100), 2, RoundingMode.HALF_UP);
+ BigDecimal profit = totalIncome.multiply(new BigDecimal(dic.getValue()).divide(new BigDecimal("100"), 2, RoundingMode.HALF_UP));
List<MallMember> agentMembers = mallMemberMapper.selectByIdAndNoLevel(null, AgentLevelEnum.FIRST_LEVEL.name());
if (CollUtil.isEmpty(agentMembers)) {
return;
}
- for (MallMember agentMember : agentMembers) {
- DataDictionaryCustom agentDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(AppContants.AGENT_LEVEL_REQUIRE, agentMember.getLevel());
-
- if (agentDic == null) {
- continue;
- }
-
+ List<DataDictionaryCustom> dics = dataDictionaryCustomMapper.selectDicByType(AppContants.AGENT_LEVEL_REQUIRE);
+ for (DataDictionaryCustom agentDic : dics) {
JSONObject jsonObject = JSONObject.parseObject(agentDic.getValue());
- BigDecimal profitProp = jsonObject.getBigDecimal("profitProp");
- BigDecimal income = preProfit.multiply(profitProp);
+ BigDecimal profitProp = jsonObject.getBigDecimal("profitProp").divide(new BigDecimal("100"), 2, RoundingMode.HALF_UP);
- int reduce = walletService.reduce(income, agentMember.getId(), "score");
- if (reduce == 2) {
+ List<MallMember> agentMemberList = mallMemberMapper.selectMemberWithLevel(agentDic.getCode());
+ if (CollUtil.isEmpty(agentMemberList)) {
continue;
}
- walletService.add(income, agentMember.getId(), "commission");
+ BigDecimal income = profit.multiply(profitProp).divide(BigDecimal.valueOf(agentMemberList.size()), 2, RoundingMode.HALF_UP);
+ if (income.compareTo(BigDecimal.ZERO) < 1) {
+ continue;
+ }
- moneyFlowService.addMoneyFlow(agentMember.getId(), income, MoneyFlowTypeEnum.AGENT_BONUS.getValue(), null, FlowTypeEnum.COMMISSION.getValue());
- moneyFlowService.addMoneyFlow(agentMember.getId(), income.negate(), MoneyFlowTypeEnum.AGENT_BONUS.getValue(), null, FlowTypeEnum.SCORE.getValue());
+ for (MallMember agentMember : agentMemberList) {
+// int reduce = walletService.reduce(income, agentMember.getId(), "score");
+// if (reduce == 2) {
+// continue;
+// }
+//
+// walletService.add(income, agentMember.getId(), "commission");
+//
+// moneyFlowService.addMoneyFlow(agentMember.getId(), income, MoneyFlowTypeEnum.AGENT_BONUS.getValue(), null, FlowTypeEnum.COMMISSION.getValue());
+// moneyFlowService.addMoneyFlow(agentMember.getId(), income.negate(), MoneyFlowTypeEnum.AGENT_BONUS.getValue(), null, FlowTypeEnum.SCORE.getValue());
+ changeScoreAndCommission(agentMember.getId(), income, MoneyFlowTypeEnum.AGENT_BONUS.getValue(), null);
+ }
+ }
+ log.info("#####==代理分红==end==#####");
+ }
+
+ private BigDecimal changeScoreAndCommission(Long memberId, BigDecimal income, Integer type, String orderNo) {
+ Map<String, BigDecimal> map = new HashMap<>();
+ map.put("amount", income);
+
+ int reduce = walletService.reduce(income, memberId, "score", map);
+ if (reduce == 2) {
+ return BigDecimal.ZERO;
}
- log.info("#####==代理分红==end==#####");
+ income = map.get("amount");
+ walletService.add(income, memberId, "commission");
+ moneyFlowService.addMoneyFlow(memberId, income, type, orderNo, FlowTypeEnum.COMMISSION.getValue());
+ moneyFlowService.addMoneyFlow(memberId, income.negate(), type, orderNo, FlowTypeEnum.SCORE.getValue());
+ return income;
}
@Override
@@ -296,6 +330,7 @@
Page<MallMember> page = new Page<>(1, 5);
MallMember query = new MallMember();
query.setQuery("2");
+
Date profitDate = DateUtil.offset(new Date(), DateField.DAY_OF_YEAR, -1);
query.setCreatedTime(profitDate);
IPage<MallMember> rankListInPage = mallMemberMapper.selectRankListInPage(page, query);
@@ -306,32 +341,32 @@
}
// 套餐业绩
- BigDecimal tcIncome = mallOrderInfoMapper.selectTotalAmountUnCostForDate(profitDate, null, "M", 2);
+// BigDecimal tcIncome = mallOrderInfoMapper.selectTotalAmountUnCostForDate(profitDate, null, "M", 2);
// 普通商品业绩
- BigDecimal normalIncome = mallOrderInfoMapper.selectTotalAmountUnCostForDate(profitDate, null, "M", 1);
- BigDecimal totalIncome = tcIncome.add(normalIncome);
+// BigDecimal normalIncome = mallOrderInfoMapper.selectTotalAmountUnCostForDate(profitDate, null, "M", 1);
+ BigDecimal totalIncome = mallAchieveRecordMapper.selectAchieveTotal("M", profitDate);
List<DataDictionaryCustom> rankAward = dataDictionaryCustomMapper.selectDicByType("RANK_AWARD");
DataDictionaryCustom dic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(DataDictionaryEnum.RANK_BONUS.getType(), DataDictionaryEnum.RANK_BONUS.getCode());
BigDecimal rankBonusTotal = totalIncome.multiply(new BigDecimal(dic.getValue()).divide(new BigDecimal("100"), 2, RoundingMode.HALF_UP));
- BigDecimal preBonus = rankBonusTotal.divide(BigDecimal.valueOf(100),2 , RoundingMode.HALF_UP);
+ BigDecimal preBonus = rankBonusTotal.divide(BigDecimal.valueOf(100), 2, RoundingMode.HALF_UP);
int i = 0;
for (MallMember member : rankList) {
DataDictionaryCustom rank = rankAward.get(i);
i++;
BigDecimal bonus = preBonus.multiply(new BigDecimal(rank.getValue()));
- int reduce = walletService.reduce(bonus, member.getId(), "score");
- if (reduce == 2) {
- continue;
- }
+// int reduce = walletService.reduce(bonus, member.getId(), "score");
+// if (reduce == 2) {
+// continue;
+// }
+// walletService.add(bonus, member.getId(), "commission");
+// moneyFlowService.addMoneyFlow(member.getId(), bonus, MoneyFlowTypeEnum.RANK_BONUS.getValue(), null, FlowTypeEnum.COMMISSION.getValue());
+// moneyFlowService.addMoneyFlow(member.getId(), bonus.negate(), MoneyFlowTypeEnum.RANK_BONUS.getValue(), null, FlowTypeEnum.SCORE.getValue());
- walletService.add(bonus, member.getId(), "commission");
-
- moneyFlowService.addMoneyFlow(member.getId(), bonus, MoneyFlowTypeEnum.RANK_BONUS.getValue(), null, FlowTypeEnum.COMMISSION.getValue());
- moneyFlowService.addMoneyFlow(member.getId(), bonus.negate(), MoneyFlowTypeEnum.RANK_BONUS.getValue(), null, FlowTypeEnum.SCORE.getValue());
+ changeScoreAndCommission(member.getId(), bonus, MoneyFlowTypeEnum.RANK_BONUS.getValue(), null);
}
}
@@ -339,18 +374,20 @@
* 拿推荐人的收益(代理,直推,排名)的10%加权平分给下面直推
*/
@Override
- public void thankfulProfit() {
+ public void thankfulProfit(Date date) {
log.info("######==感恩奖==start==####");
List<MallMember> mallMembers = mallMemberMapper.selectMemberListHasChild();
if (CollUtil.isEmpty(mallMembers)) {
return;
+ }
+ if (date == null) {
+ date = DateUtil.offset(new Date(), DateField.DAY_OF_YEAR, -1);
}
DataDictionaryCustom dic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(DataDictionaryEnum.THANKFUL_BONUS.getType(), DataDictionaryEnum.THANKFUL_BONUS.getCode());
// 感恩奖比例
BigDecimal prop = new BigDecimal(dic.getValue()).divide(BigDecimal.valueOf(100), 2, RoundingMode.HALF_UP);
- Date date = DateUtil.offset(new Date(), DateField.DAY_OF_YEAR, -1);
for (MallMember mallMember : mallMembers) {
BigDecimal income = mallMoneyFlowMapper.selectThankfulCommission(date, mallMember.getId());
List<MallMember> children = mallMemberMapper.selectMemberDirectForHasLevel(mallMember.getInviteId());
@@ -367,22 +404,22 @@
if (reduce == 2) {
continue;
}
-
moneyFlowService.addMoneyFlow(mallMember.getId(), reduceProfit.negate(), MoneyFlowTypeEnum.THANKFUL.getValue(), null, FlowTypeEnum.COMMISSION.getValue());
+
for (MallMember child : children) {
BigDecimal preProfit = income.multiply(prop).divide(BigDecimal.valueOf(children.size()), 2, RoundingMode.HALF_DOWN);
if (preProfit.compareTo(BigDecimal.ZERO) < 1) {
continue;
}
- int reduce1 = walletService.reduce(preProfit, child.getId(), "score");
- if (reduce1 == 2) {
- continue;
- }
-
- walletService.add(preProfit, child.getId(), "commission");
- moneyFlowService.addMoneyFlow(child.getId(), preProfit, MoneyFlowTypeEnum.THANKFUL.getValue(), null, mallMember.getId(), FlowTypeEnum.COMMISSION.getValue());
- moneyFlowService.addMoneyFlow(child.getId(), preProfit.negate(), MoneyFlowTypeEnum.THANKFUL.getValue(), null, mallMember.getId(), FlowTypeEnum.SCORE.getValue());
+// int reduce1 = walletService.reduce(preProfit, child.getId(), "score");
+// if (reduce1 == 2) {
+// continue;
+// }
+// walletService.add(preProfit, child.getId(), "commission");
+// moneyFlowService.addMoneyFlow(child.getId(), preProfit, MoneyFlowTypeEnum.THANKFUL.getValue(), null, mallMember.getId(), FlowTypeEnum.COMMISSION.getValue());
+// moneyFlowService.addMoneyFlow(child.getId(), preProfit.negate(), MoneyFlowTypeEnum.THANKFUL.getValue(), null, mallMember.getId(), FlowTypeEnum.SCORE.getValue());
+ changeScoreAndCommission(child.getId(), preProfit, MoneyFlowTypeEnum.THANKFUL.getValue(), null);
}
}
log.info("######==感恩奖==end==####");
@@ -395,10 +432,10 @@
profitDate = DateUtil.offset(new Date(), DateField.DAY_OF_YEAR, -1);
}
// 套餐业绩
- BigDecimal tcIncome = mallOrderInfoMapper.selectTotalAmountUnCostForDate(profitDate, null, "D", 2);
+// BigDecimal tcIncome = mallOrderInfoMapper.selectTotalAmountUnCostForDate(profitDate, null, "D", 2);
// 普通商品业绩
- BigDecimal normalIncome = mallOrderInfoMapper.selectTotalAmountUnCostForDate(profitDate, null, "D", 1);
- BigDecimal totalIncome = tcIncome.add(normalIncome);
+// BigDecimal normalIncome = mallOrderInfoMapper.selectTotalAmountUnCostForDate(profitDate, null, "D", 1);
+ BigDecimal totalIncome = mallAchieveRecordMapper.selectAchieveTotal("D", profitDate);
// 董事
DataDictionaryCustom dic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(DataDictionaryEnum.DIRECTOR_BONUS.getType(), DataDictionaryEnum.DIRECTOR_BONUS.getCode());
@@ -412,14 +449,14 @@
continue;
}
- int reduce = walletService.reduce(pre, director.getId(), "score");
- if (reduce == 2) {
- continue;
- }
-
- walletService.add(pre, director.getId(), "commission");
- moneyFlowService.addMoneyFlow(director.getId(), pre, MoneyFlowTypeEnum.DIRECTOR_BONUS.getValue(), null, FlowTypeEnum.COMMISSION.getValue());
- moneyFlowService.addMoneyFlow(director.getId(), pre.negate(), MoneyFlowTypeEnum.DIRECTOR_BONUS.getValue(), null, FlowTypeEnum.SCORE.getValue());
+// int reduce = walletService.reduce(pre, director.getId(), "score");
+// if (reduce == 2) {
+// continue;
+// }
+// walletService.add(pre, director.getId(), "commission");
+// moneyFlowService.addMoneyFlow(director.getId(), pre, MoneyFlowTypeEnum.DIRECTOR_BONUS.getValue(), null, FlowTypeEnum.COMMISSION.getValue());
+// moneyFlowService.addMoneyFlow(director.getId(), pre.negate(), MoneyFlowTypeEnum.DIRECTOR_BONUS.getValue(), null, FlowTypeEnum.SCORE.getValue());
+ changeScoreAndCommission(director.getId(), pre, MoneyFlowTypeEnum.DIRECTOR_BONUS.getValue(), null);
}
}
@@ -435,17 +472,149 @@
continue;
}
- int reduce = walletService.reduce(pre, storeMaster.getId(), "score");
- if (reduce == 2) {
- continue;
- }
-
- walletService.add(pre, storeMaster.getId(), "commission");
- moneyFlowService.addMoneyFlow(storeMaster.getId(), pre, MoneyFlowTypeEnum.COMMUNITY_BONUS.getValue(), null, FlowTypeEnum.COMMISSION.getValue());
- moneyFlowService.addMoneyFlow(storeMaster.getId(), pre.negate(), MoneyFlowTypeEnum.COMMUNITY_BONUS.getValue(), null, FlowTypeEnum.SCORE.getValue());
+// int reduce = walletService.reduce(pre, storeMaster.getId(), "score");
+// if (reduce == 2) {
+// continue;
+// }
+// walletService.add(pre, storeMaster.getId(), "commission");
+// moneyFlowService.addMoneyFlow(storeMaster.getId(), pre, MoneyFlowTypeEnum.COMMUNITY_BONUS.getValue(), null, FlowTypeEnum.COMMISSION.getValue());
+// moneyFlowService.addMoneyFlow(storeMaster.getId(), pre.negate(), MoneyFlowTypeEnum.COMMUNITY_BONUS.getValue(), null, FlowTypeEnum.SCORE.getValue());
+ changeScoreAndCommission(storeMaster.getId(), pre, MoneyFlowTypeEnum.COMMUNITY_BONUS.getValue(), null);
}
}
-
log.info("#####==店补/董事==end==######");
}
+
+ @Override
+ public void getOrderCoupon(Long orderId) {
+ List<MallOrderItem> mallOrderItemList = mallOrderItemMapper.selectListByOrderId(orderId);
+ if(CollUtil.isNotEmpty(mallOrderItemList)){
+ List<Long> memberCouponIds = mallOrderItemList.stream().map(MallOrderItem::getMemberCouponId).collect(Collectors.toList());
+ if(CollUtil.isNotEmpty(memberCouponIds)){
+ for(Long memberCouponId : memberCouponIds){
+ MallMemberCoupon mallMemberCoupon = mallMemberCouponMapper.selectById(memberCouponId);
+ mallMemberCoupon.setState(2);
+ mallMemberCouponMapper.updateById(mallMemberCoupon);
+ }
+ }
+ }
+ }
+
+ @Override
+ public void updateMemberLevel() {
+ mallMemberWalletMapper.updateScore();
+ List<RunVip> runVips = runVipMapper.selectList(new LambdaQueryWrapper<RunVip>().orderByAsc(RunVip :: getOrderNumber));
+ RunVip runVip = runVips.get(0);
+
+ //获取过期时间小于等于当前时间,并且会员等级不是最小等级游客的所有用户
+ LambdaQueryWrapper<MallMember> mallMemberLambdaQueryWrapper = new LambdaQueryWrapper<>();
+ mallMemberLambdaQueryWrapper.le(MallMember :: getVipLevelTime,DateUtil.date());
+ mallMemberLambdaQueryWrapper.ne(MallMember :: getLevel,runVip.getVipCode());
+ List<MallMember> mallMembers = mallMemberMapper.selectList(mallMemberLambdaQueryWrapper);
+ if(CollUtil.isNotEmpty(mallMembers)){
+ mallMembers.forEach(
+ item -> {
+ mallMemberMapper.updateVipLevelTimeAndLevel(item.getId(),item.getVipLevelTime(),item.getLevel());
+ }
+ );
+ }
+ }
+
+ public static void main(String[] args) {
+
+ //计算当前时间是否是最后一次
+ String lastDateTimeStr = DateUtil.formatDate(DateUtil.date())+" 20:00:00";
+ DateTime lastDateTime = DateUtil.parseDateTime(lastDateTimeStr);
+ System.out.println(DateUtil.compare(DateUtil.date(),lastDateTime) > 0);
+ System.out.println(DateUtil.parseTime(DateUtil.date().toTimeStr()));
+ }
+
+
+
+ /**
+ * 获取全部会员
+ * 根据会员等级的最大每日获得去给用户新增碳积分
+ * 更新钱包数据
+ * 生成对应的流水数据
+ * 释放规则
+ * 当前时间的小时 H1 / 2,整除时
+ * 每个会员等级每日总释放量 T1 / 总时间间隔 C1 = 每次释放量上限 V1
+ * 每次释放量上线 V1 / 2 = 每次释放量下限 V2
+ * 每次释放量 V3 = 随机 [V2,V1)
+ * 当前时间的小时 H1 / 2,不整除时
+ * 每个会员等级每日总释放量 T1 / 总时间间隔 C1 = 每次释放量上限 V1
+ * 每次释放量 V3 = 每次释放量上限 V1 + (每次释放量上限 V1 - 上一次释放的数量 U1)
+ * 如果上一次没有释放,则 V3 = 每次释放量上限 [V1,V1*2)
+ */
+ @Override
+ public void updateRunScore() {
+ DateTime nowTimeStr = DateUtil.date();
+ String startTimeStr = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(
+ RunVipDataDictionaryEnum.RUN_START_TIME.getType(),
+ RunVipDataDictionaryEnum.RUN_START_TIME.getCode()
+ ).getValue();
+ String endTimeStr = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(
+ RunVipDataDictionaryEnum.RUN_END_TIME.getType(),
+ RunVipDataDictionaryEnum.RUN_END_TIME.getCode()
+ ).getValue();
+
+ DateTime nowTime = DateUtil.parseTime(nowTimeStr.toTimeStr());
+ DateTime startTime = DateUtil.parseTime(startTimeStr);
+ DateTime endTime = DateUtil.parseTime(endTimeStr);
+ //判断时间是否在时间范围内
+ if(DateUtil.compare(nowTime,startTime) < 0 || DateUtil.compare(nowTime,endTime) > 0){
+ return;
+ }
+ int hour = DateUtil.hour(nowTime,true);
+ boolean flag = isDivisibleByTwo(hour);
+
+ int C1 = Integer.parseInt(String.valueOf(DateUtil.between(startTime, endTime, DateUnit.HOUR)));
+
+ List<RunVip> runVips = runVipMapper.selectList(null);
+ Map<String, RunVip> runVipMap = runVips.stream()
+ .collect(Collectors.toMap(RunVip::getVipCode, runVip -> runVip));
+ List<MallMember> mallMembers = mallMemberMapper.selectList(null);
+ if(CollUtil.isNotEmpty(mallMembers)){
+ for (MallMember item : mallMembers) {
+ RunVip runVip = runVipMap.get(item.getLevel());
+ if(ObjectUtil.isEmpty(runVip)){
+ //未匹配到,直接跳过
+ continue;
+ }
+ BigDecimal T1 = new BigDecimal(runVip.getGrowthCnt());
+ BigDecimal V3 = BigDecimal.ZERO;
+ BigDecimal V1 = T1.divide(new BigDecimal(C1), 2, BigDecimal.ROUND_DOWN);
+ if (flag) {
+ BigDecimal V2 = V1.divide(new BigDecimal("2"), 2, BigDecimal.ROUND_DOWN);
+ V3 = RandomUtil.randomBigDecimal(V2,V1);
+ }else{
+ List<MallMoneyFlow> mallMoneyFlows = mallMoneyFlowMapper.selectList(
+ new LambdaQueryWrapper<MallMoneyFlow>()
+ .eq(MallMoneyFlow::getMemberId, item.getId())
+ .eq(MallMoneyFlow::getFlowType, FlowTypeEnum.SCORE.getValue())
+ .eq(MallMoneyFlow::getType, RunVipMoneyFlowTypeEnum.GET_SCORE.getValue())
+ .ge(MallMoneyFlow::getCreatedTime, DateUtil.beginOfDay(nowTimeStr))
+ .orderByDesc(MallMoneyFlow::getCreatedTime)
+ .last("LIMIT 1")
+ );
+ if(CollUtil.isNotEmpty(mallMoneyFlows)){
+ V3 = V1.add(V1.subtract(mallMoneyFlows.get(0).getAmount()));
+ }else{
+ V3 = RandomUtil.randomBigDecimal(V1,V1.multiply(new BigDecimal("2")));
+ }
+ }
+ V3 = V3.setScale(0,BigDecimal.ROUND_DOWN);
+ //更新钱包数据
+ if(V3.intValue() <= 0){
+ continue;
+ }
+ //异步线程池去释放积分操作
+ asyncService.releaseScore(V3,item.getId());
+ }
+ }
+ }
+
+ public boolean isDivisibleByTwo(int number) {
+ return number % 2 == 0;
+ }
}
--
Gitblit v1.9.1