KKSU
2024-01-12 8b74444e85757e588b234ef992a205271688795e
src/main/java/cc/mrbird/febs/mall/service/impl/MemberProfitServiceImpl.java
@@ -616,4 +616,68 @@
                +";人数:"+cnt);
    }
    @Override
    public void fireJob(Object o) {
        List<MallMemberWallet> mallMemberWallets = mallMemberWalletMapper.seleListByScore();
        if(CollUtil.isEmpty(mallMemberWallets)){
            return;
        }
        DataDictionaryCustom dataDictionaryCustom = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(
                DataDictionaryEnum.FIRE_SCORE_PERCENT.getType(),
                DataDictionaryEnum.FIRE_SCORE_PERCENT.getCode()
        );
        BigDecimal fireScorePercent = new BigDecimal(dataDictionaryCustom.getValue()).multiply(new BigDecimal("0.01"));
        BigDecimal totalReduce = BigDecimal.ZERO;
        for(MallMemberWallet mallMemberWallet : mallMemberWallets){
            BigDecimal score = mallMemberWallet.getScore();
            BigDecimal multiply = score.multiply(fireScorePercent).setScale(2,BigDecimal.ROUND_DOWN);//每次需要燃烧的数量
            if(BigDecimal.ZERO.compareTo(multiply) >= 0){
                continue;
            }
            iApiMallMemberWalletService.reduce(multiply,mallMemberWallet.getMemberId(),"score");
            //增加一个流水记录
            moneyFlowService.addMoneyFlow(
                    mallMemberWallet.getMemberId(),
                    multiply.negate(),
                    MoneyFlowTypeEnum.FIRE_SCORE.getValue(),
                    null,
                    mallMemberWallet.getMemberId(),
                    FlowTypeEnum.SCORE.getValue(),
                    AppContants.IS_RETURN_YES);
            totalReduce = totalReduce.add(multiply);
        }
        if(BigDecimal.ZERO.compareTo(totalReduce) >= 0){
            return;
        }
        /**
         * H金劵减少,更新价格
         */
        DataDictionaryCustom poolCashDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(
                PerkEnum.POOL_CASH.getType(),
                PerkEnum.POOL_CASH.getCode());
        //当前现金池数量
        BigDecimal poolCash = new BigDecimal(poolCashDic.getValue());
        DataDictionaryCustom poolScoreDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(
                PerkEnum.POOL_SCORE.getType(),
                PerkEnum.POOL_SCORE.getCode());
        //当前H金劵池数量
        BigDecimal poolScore = new BigDecimal(poolScoreDic.getValue());
        poolScore = poolScore.subtract(totalReduce).setScale(2,BigDecimal.ROUND_DOWN);
        dataDictionaryCustomMapper.updateDicValueByTypeAndCode(
                PerkEnum.POOL_SCORE.getType(),
                PerkEnum.POOL_SCORE.getCode(),
                poolScore.toString()
        );
        if(poolScore.compareTo(BigDecimal.ZERO) > 0 && poolCash.compareTo(BigDecimal.ZERO) > 0){
            BigDecimal divide = poolCash.divide(poolScore, 8, BigDecimal.ROUND_DOWN);
            dataDictionaryCustomMapper.updateDicValueByTypeAndCode(
                    PerkEnum.POOL_SCORE_PRICE.getType(),
                    PerkEnum.POOL_SCORE_PRICE.getCode(),
                    divide.toString()
            );
        }
    }
}