| | |
| | | import cc.mrbird.febs.common.enumerates.FlowTypeEnum; |
| | | import cc.mrbird.febs.common.enumerates.MoneyFlowTypeEnum; |
| | | import cc.mrbird.febs.common.utils.AppContants; |
| | | import cc.mrbird.febs.common.utils.RedisUtils; |
| | | import cc.mrbird.febs.mall.dto.ScorePoorDto; |
| | | import cc.mrbird.febs.mall.entity.*; |
| | | import cc.mrbird.febs.mall.mapper.*; |
| | | import cc.mrbird.febs.mall.service.IApiMallMemberWalletService; |
| | |
| | | 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.StrUtil; |
| | | import cn.hutool.json.JSONUtil; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import lombok.RequiredArgsConstructor; |
| | |
| | | private final DataDictionaryCustomMapper dataDictionaryCustomMapper; |
| | | private final MallMoneyFlowMapper mallMoneyFlowMapper; |
| | | private final MallAchieveRecordMapper mallAchieveRecordMapper; |
| | | private final RedisUtils redisUtils; |
| | | private final MallMemberWalletMapper mallMemberWalletMapper; |
| | | |
| | | @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 normalIncome = mallOrderInfoMapper.selectTotalAmountUnCostForDate(profitDate, null, "D", 1); |
| | | //今日总业绩 |
| | | BigDecimal totalIncome = mallAchieveRecordMapper.selectAchieveTotal("D", profitDate); |
| | | |
| | | if (totalIncome.compareTo(BigDecimal.ZERO) == 0) { |
| | |
| | | BigDecimal preStaticProfit = staticProfit.divide(new BigDecimal(list.size()), 2, RoundingMode.HALF_UP); |
| | | |
| | | for (Map<String, Object> item : list) { |
| | | Long memberId = (Long) item.get("memberId"); |
| | | // Long memberId = (Long) item.get("memberId"); |
| | | String orderNo = (String) item.get("orderNo"); |
| | | |
| | | changeAllScoreAndCommission(preStaticProfit,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()); |
| | | changeScoreAndCommission(memberId, preStaticProfit, MoneyFlowTypeEnum.STATIC_BONUS.getValue(), orderNo); |
| | | // changeScoreAndCommission(memberId, preStaticProfit, MoneyFlowTypeEnum.STATIC_BONUS.getValue(), orderNo); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | public void changeAllScoreAndCommission(BigDecimal preStaticProfit,String orderNo){ |
| | | List<MallMember> members = mallMemberMapper.selectList(null); |
| | | for(MallMember mallMember : members){ |
| | | changeScoreAndCommission(mallMember.getId(), preStaticProfit, MoneyFlowTypeEnum.STATIC_BONUS.getValue(), orderNo); |
| | | } |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | // 判断套餐或者普通商品,结算对应商品的动态分红 |
| | | if (!Objects.equals(item.getIsNormal(), isNormal)) { |
| | | continue; |
| | | } |
| | | // if (!Objects.equals(item.getIsNormal(), isNormal)) { |
| | | // continue; |
| | | // } |
| | | |
| | | // =======直推返利== start ===== |
| | | // 直接奖励收益 |
| | |
| | | } |
| | | |
| | | BigDecimal income = profit.multiply(profitProp).divide(BigDecimal.valueOf(agentMemberList.size()), 2, RoundingMode.HALF_UP); |
| | | if (income.compareTo(BigDecimal.ZERO) < 1) { |
| | | continue; |
| | | } |
| | | |
| | | for (MallMember agentMember : agentMemberList) { |
| | | // int reduce = walletService.reduce(income, agentMember.getId(), "score"); |
| | |
| | | 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); |
| | |
| | | // BigDecimal tcIncome = mallOrderInfoMapper.selectTotalAmountUnCostForDate(profitDate, null, "M", 2); |
| | | // 普通商品业绩 |
| | | // BigDecimal normalIncome = mallOrderInfoMapper.selectTotalAmountUnCostForDate(profitDate, null, "M", 1); |
| | | BigDecimal totalIncome = mallAchieveRecordMapper.selectAchieveTotal("D", profitDate); |
| | | 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()); |
| | |
| | | * 拿推荐人的收益(代理,直推,排名)的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()); |
| | |
| | | } |
| | | log.info("#####==店补/董事==end==######"); |
| | | } |
| | | |
| | | @Override |
| | | public void scorePool() { |
| | | log.info("#####==积分池==start==######"); |
| | | |
| | | String redisKey = "scorePool"; |
| | | // List<MallOrderInfo> mallOrderInfos = mallOrderInfoMapper.selectList(new QueryWrapper<>()); |
| | | // if(CollUtil.isEmpty(mallOrderInfos)){ |
| | | // redisUtils.set(redisKey,0,0L); |
| | | // return; |
| | | // } |
| | | /** |
| | | * 后一天2点,结算前一天的所有消费 |
| | | * 积分池增加每日消费的10% |
| | | * 每天释放1%,给全体用户 |
| | | */ |
| | | //前一天的所有消费的10% |
| | | DataDictionaryCustom dic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(DataDictionaryEnum.SCORE_POOR_RADIO.getType(), DataDictionaryEnum.SCORE_POOR_RADIO.getCode()); |
| | | if(ObjectUtil.isEmpty(dic)){ |
| | | return; |
| | | } |
| | | ScorePoorDto scorePoorDto = JSONUtil.toBean(dic.getValue(), ScorePoorDto.class); |
| | | BigDecimal everydayRatio = scorePoorDto.getEverydayRatio().multiply(new BigDecimal(0.01)); |
| | | BigDecimal dividEquallyRatio = scorePoorDto.getDividEquallyRatio().multiply(new BigDecimal(0.01)); |
| | | |
| | | Date date = DateUtil.offsetDay(new Date(), -1); |
| | | BigDecimal totalAmount = mallOrderInfoMapper.selectTotalAmountByPayDoneAndDataString(1, date); |
| | | BigDecimal multiplyTotalAmount = totalAmount.multiply(everydayRatio); |
| | | String scorePoolRedis = redisUtils.getString(redisKey); |
| | | if(StrUtil.isBlank(scorePoolRedis)){ |
| | | redisUtils.set(redisKey,0,0L); |
| | | } |
| | | |
| | | BigDecimal scorePoolOld = new BigDecimal(redisUtils.getString(redisKey)); |
| | | BigDecimal scorePoolNew = scorePoolOld.add(multiplyTotalAmount); |
| | | |
| | | //每天释放1%给全体用户 |
| | | BigDecimal scorePoolToDay = scorePoolNew.multiply(dividEquallyRatio); |
| | | |
| | | redisUtils.set(redisKey,scorePoolNew.subtract(scorePoolToDay).intValue(),0L); |
| | | |
| | | QueryWrapper<MallMember> formalMember = new QueryWrapper<>(); |
| | | formalMember.ne("level", AgentLevelEnum.ZERO_LEVEL.name()); |
| | | List<MallMember> mallMembers = mallMemberMapper.selectList(formalMember); |
| | | int cnt = 0; |
| | | if(CollUtil.isNotEmpty(mallMembers)){ |
| | | BigDecimal income = new BigDecimal(scorePoolToDay.divide(new BigDecimal(mallMembers.size()), 2, RoundingMode.HALF_UP).intValue()); |
| | | if(income.compareTo(BigDecimal.ZERO) < 1){ |
| | | return; |
| | | } |
| | | for(MallMember mallMember : mallMembers){ |
| | | /* |
| | | 平分成佣金,一比一减少赠送积分 |
| | | 如果没有赠送积分,则平分0 |
| | | */ |
| | | BigDecimal outCome = BigDecimal.ZERO; |
| | | MallMemberWallet mallMemberWallet = mallMemberWalletMapper.selectWalletByMemberId(mallMember.getId()); |
| | | if(mallMemberWallet.getScore().compareTo(BigDecimal.ZERO) < 1){ |
| | | continue; |
| | | } |
| | | if(mallMemberWallet.getScore().compareTo(income) < 0){ |
| | | outCome = new BigDecimal(mallMemberWallet.getScore().intValue()); |
| | | }else{ |
| | | outCome = income; |
| | | } |
| | | walletService.add(outCome, mallMember.getId(), "commission"); |
| | | walletService.reduce(outCome, mallMember.getId(), "score"); |
| | | moneyFlowService.addMoneyFlow(mallMember.getId(), outCome, MoneyFlowTypeEnum.SCORE_POOL.getValue(), null, FlowTypeEnum.COMMISSION.getValue()); |
| | | moneyFlowService.addMoneyFlow(mallMember.getId(), outCome.negate(), MoneyFlowTypeEnum.SCORE_POOL.getValue(), null, FlowTypeEnum.SCORE.getValue()); |
| | | cnt ++; |
| | | } |
| | | } |
| | | log.info("#####==积分池==end==######;" + |
| | | "今日新增积分:" + multiplyTotalAmount.setScale(2, RoundingMode.HALF_UP) |
| | | +";平分积分数量:"+scorePoolToDay.setScale(2, RoundingMode.HALF_UP) |
| | | +";人数:"+cnt); |
| | | } |
| | | |
| | | } |