|  |  |  | 
|---|
|  |  |  | 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.common.utils.MallUtils; | 
|---|
|  |  |  | 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.IMallMoneyFlowService; | 
|---|
|  |  |  | import cc.mrbird.febs.mall.service.IMemberProfitService; | 
|---|
|  |  |  | import cc.mrbird.febs.mall.service.*; | 
|---|
|  |  |  | import cc.mrbird.febs.mall.vo.AdminTeamEqualsPerkVo; | 
|---|
|  |  |  | import cc.mrbird.febs.rabbit.producter.AgentProducer; | 
|---|
|  |  |  | 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; | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import java.math.BigDecimal; | 
|---|
|  |  |  | import java.math.RoundingMode; | 
|---|
|  |  |  | import java.util.Date; | 
|---|
|  |  |  | import java.util.List; | 
|---|
|  |  |  | import java.util.*; | 
|---|
|  |  |  | import java.util.stream.Collectors; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * @author wzy | 
|---|
|  |  |  | 
|---|
|  |  |  | private final IMallMoneyFlowService moneyFlowService; | 
|---|
|  |  |  | private final DataDictionaryCustomMapper dataDictionaryCustomMapper; | 
|---|
|  |  |  | private final MallMoneyFlowMapper mallMoneyFlowMapper; | 
|---|
|  |  |  | private final MallAchieveRecordMapper mallAchieveRecordMapper; | 
|---|
|  |  |  | private final RedisUtils redisUtils; | 
|---|
|  |  |  | private final MallMemberWalletMapper mallMemberWalletMapper; | 
|---|
|  |  |  | private final IAgentService iAgentService; | 
|---|
|  |  |  | private final IMallMoneyFlowService mallMoneyFlowService; | 
|---|
|  |  |  | private final MallMqRecordMapper mallMqRecordMapper; | 
|---|
|  |  |  | private final AgentProducer agentProducer; | 
|---|
|  |  |  | private final MallScoreRecordMapper mallScoreRecordMapper; | 
|---|
|  |  |  | private final MallScoreAchieveReleaseMapper mallScoreAchieveReleaseMapper; | 
|---|
|  |  |  | private final MallScoreVoucherMapper mallScoreVoucherMapper; | 
|---|
|  |  |  | private final CommonService commonService; | 
|---|
|  |  |  | private final MallProductBuyRecordMapper mallProductBuyRecordMapper; | 
|---|
|  |  |  | private final MallProductBuyMapper mallProductBuyMapper; | 
|---|
|  |  |  | private final MallProductSellMapper mallProductSellMapper; | 
|---|
|  |  |  | private final MallProductSellRecordMapper mallProductSellRecordMapper; | 
|---|
|  |  |  | private final MallMemberAmountMapper mallMemberAmountMapper; | 
|---|
|  |  |  | private final IMallMoneyFlowService iMallMoneyFlowService; | 
|---|
|  |  |  | private final MallProductNftMapper mallProductNftMapper; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @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); | 
|---|
|  |  |  | BigDecimal totalIncome = mallOrderInfoMapper.selectTotalAmountUnCostForDate(profitDate, null, "D"); | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | 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) { | 
|---|
|  |  |  | return; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | DataDictionaryCustom dic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(DataDictionaryEnum.STATIC_BONUS.getType(), DataDictionaryEnum.STATIC_BONUS.getCode()); | 
|---|
|  |  |  | BigDecimal perProfit = totalIncome.divide(new BigDecimal(dic.getValue()), 2, RoundingMode.HALF_UP).divide(BigDecimal.valueOf(100), 2, RoundingMode.HALF_UP); | 
|---|
|  |  |  | BigDecimal perProfit = totalIncome.multiply(new BigDecimal(dic.getValue()).divide(BigDecimal.valueOf(100), 2, RoundingMode.HALF_UP)); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Map<Long, List<Map<String, Object>>> map = new HashMap<>(); | 
|---|
|  |  |  | Map<Long, BigDecimal> goodsProp = new HashMap<>(); | 
|---|
|  |  |  | for (MallMember member : members) { | 
|---|
|  |  |  | List<MallGoods> goodsList = mallGoodsMapper.selectOrderGoodsList(member.getId(), profitDate); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | for (MallGoods goods : goodsList) { | 
|---|
|  |  |  | BigDecimal goodsProfit = goods.getStaticProp().multiply(perProfit); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | int reduce = walletService.reduce(goodsProfit, member.getId(), "score"); | 
|---|
|  |  |  | if (reduce == 2) { | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | if (goods.getIsNormal() == 1) { | 
|---|
|  |  |  | continue; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | walletService.add(goodsProfit, member.getId(), "commission"); | 
|---|
|  |  |  | moneyFlowService.addMoneyFlow(member.getId(), goodsProfit, MoneyFlowTypeEnum.STATIC_BONUS.getValue(), goods.getOrderNo(), FlowTypeEnum.COMMISSION.getValue()); | 
|---|
|  |  |  | moneyFlowService.addMoneyFlow(member.getId(), goodsProfit.negate(), MoneyFlowTypeEnum.STATIC_BONUS.getValue(), goods.getOrderNo(), FlowTypeEnum.SCORE.getValue()); | 
|---|
|  |  |  | List<Map<String, Object>> list = map.get(goods.getId()); | 
|---|
|  |  |  | if (CollUtil.isEmpty(list)) { | 
|---|
|  |  |  | list = new ArrayList<>(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Map<String, Object> listItem = new HashMap<>(); | 
|---|
|  |  |  | listItem.put("memberId", member.getId()); | 
|---|
|  |  |  | listItem.put("orderNo", goods.getOrderNo()); | 
|---|
|  |  |  | list.add(listItem); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | map.put(goods.getId(), list); | 
|---|
|  |  |  | goodsProp.put(goods.getId(), goods.getStaticProp()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (!map.isEmpty()) { | 
|---|
|  |  |  | for (Map.Entry<Long, List<Map<String, Object>>> entry : map.entrySet()) { | 
|---|
|  |  |  | List<Map<String, Object>> list = entry.getValue(); | 
|---|
|  |  |  | BigDecimal staticProfit = goodsProp.get(entry.getKey()).divide(new BigDecimal("100"), 2, RoundingMode.HALF_UP).multiply(perProfit); | 
|---|
|  |  |  | BigDecimal preStaticProfit = staticProfit.divide(new BigDecimal(list.size()), 2, RoundingMode.HALF_UP); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | for (Map<String, Object> item : list) { | 
|---|
|  |  |  | //                    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); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 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); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public void dynamicProfit(Long orderId) { | 
|---|
|  |  |  | return; | 
|---|
|  |  |  | //        dynamicProfit(orderId, 2); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | @Transactional(rollbackFor = Exception.class) | 
|---|
|  |  |  | public void dynamicProfit(Long orderId) { | 
|---|
|  |  |  | public void dynamicProfit(Long orderId, Integer isNormal) { | 
|---|
|  |  |  | log.info("######直推奖励, 订单ID:{}######", orderId); | 
|---|
|  |  |  | MallOrderInfo orderInfo = mallOrderInfoMapper.selectById(orderId); | 
|---|
|  |  |  | if (orderInfo.getOrderType() == 2) { | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<MallOrderItem> items = mallOrderInfoMapper.getMallOrderItemByOrderId(orderId); | 
|---|
|  |  |  | for (MallOrderItem item : items) { | 
|---|
|  |  |  | item.setHasSettle(1); | 
|---|
|  |  |  | mallOrderItemMapper.updateById(item); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 减去成本后算收益 | 
|---|
|  |  |  | BigDecimal amount = item.getPrice().subtract(item.getCostPrice()).multiply(BigDecimal.valueOf(item.getCnt())); | 
|---|
|  |  |  | if (amount.compareTo(BigDecimal.ZERO) < 1) { | 
|---|
|  |  |  | continue; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Integer isReturn = null; | 
|---|
|  |  |  | if (item.getIsNormal() == 1) { | 
|---|
|  |  |  | isReturn = 2; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // 判断套餐或者普通商品,结算对应商品的动态分红 | 
|---|
|  |  |  | //            if (!Objects.equals(item.getIsNormal(), isNormal)) { | 
|---|
|  |  |  | //                continue; | 
|---|
|  |  |  | //            } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // =======直推返利== start ===== | 
|---|
|  |  |  | // 直接奖励收益 | 
|---|
|  |  |  | BigDecimal dynamicProfit = amount.divide(new BigDecimal(dic.getValue()), 2, RoundingMode.HALF_UP); | 
|---|
|  |  |  | BigDecimal dynamicProfit = amount.multiply(new BigDecimal(dic.getValue()).divide(new BigDecimal(100), 2, RoundingMode.HALF_UP)); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (dynamicProfit.compareTo(BigDecimal.ZERO) < 1) { | 
|---|
|  |  |  | 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(), isReturn); | 
|---|
|  |  |  | moneyFlowService.addMoneyFlow(parent.getId(), dynamicProfit.negate(), MoneyFlowTypeEnum.DYNAMIC_ACHIEVE.getValue(), orderInfo.getOrderNo(), FlowTypeEnum.SCORE.getValue()); | 
|---|
|  |  |  | // =======直推返利== end ===== | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // =======隔代奖== start ===== | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 直推数量 | 
|---|
|  |  |  | Integer directCnt = mallMemberMapper.selectOwnCntByInviteId(member.getReferrerId()); | 
|---|
|  |  |  | 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; | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 隔代推荐奖 收益 | 
|---|
|  |  |  | direct = direct.divide(indrectDicProp, 2, RoundingMode.HALF_UP); | 
|---|
|  |  |  | direct = direct.multiply(indrectDicProp.divide(new BigDecimal("100"), 2, RoundingMode.HALF_UP)); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // direct 收益小于1,则跳出 | 
|---|
|  |  |  | if (direct.compareTo(BigDecimal.ONE) < 1) { | 
|---|
|  |  |  | continue; | 
|---|
|  |  |  | 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(), isReturn); | 
|---|
|  |  |  | 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 ===== | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | if (profitDate == null) { | 
|---|
|  |  |  | profitDate = DateUtil.offset(new Date(), DateField.DAY_OF_YEAR, -1); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | BigDecimal totalIncome = mallOrderInfoMapper.selectTotalAmountUnCostForDate(profitDate, null, "D"); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 套餐业绩 | 
|---|
|  |  |  | //        BigDecimal tcIncome = mallOrderInfoMapper.selectTotalAmountUnCostForDate(profitDate, null, "D", 2); | 
|---|
|  |  |  | // 普通商品业绩 | 
|---|
|  |  |  | //        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()); | 
|---|
|  |  |  | List<MallMember> agentMembers = mallMemberMapper.selectByIdAndNoLevel(null, AgentLevelEnum.SECOND_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 | 
|---|
|  |  |  | 
|---|
|  |  |  | 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); | 
|---|
|  |  |  | 
|---|
|  |  |  | return; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | BigDecimal totalIncome = mallOrderInfoMapper.selectTotalAmountUnCostForDate(profitDate, null, "M"); | 
|---|
|  |  |  | // 套餐业绩 | 
|---|
|  |  |  | //        BigDecimal tcIncome = mallOrderInfoMapper.selectTotalAmountUnCostForDate(profitDate, null, "M", 2); | 
|---|
|  |  |  | // 普通商品业绩 | 
|---|
|  |  |  | //        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 = new BigDecimal(dic.getValue()).divide(totalIncome, 2, RoundingMode.HALF_UP); | 
|---|
|  |  |  | BigDecimal preBonus = rankBonusTotal.divide(BigDecimal.valueOf(100),2 , RoundingMode.HALF_UP); | 
|---|
|  |  |  | 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); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 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); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 拿推荐人收益(代理,直推,排名)的10%加权平分给下面直推 | 
|---|
|  |  |  | * 拿推荐人的收益(代理,直推,排名)的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()); | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | BigDecimal reduceProfit = income.multiply(prop); | 
|---|
|  |  |  | int reduce = walletService.reduce(reduceProfit.negate(), mallMember.getId(), "commission"); | 
|---|
|  |  |  | if (reduce == 2) { | 
|---|
|  |  |  | if (reduceProfit.compareTo(BigDecimal.ZERO) < 1) { | 
|---|
|  |  |  | continue; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | int reduce = walletService.reduce(reduceProfit, mallMember.getId(), "commission"); | 
|---|
|  |  |  | 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.negate(), 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==####"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public void storeAndDirectorProfit(Date profitDate) { | 
|---|
|  |  |  | log.info("#####==店补/董事==start==######"); | 
|---|
|  |  |  | 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); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 董事 | 
|---|
|  |  |  | DataDictionaryCustom dic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(DataDictionaryEnum.DIRECTOR_BONUS.getType(), DataDictionaryEnum.DIRECTOR_BONUS.getCode()); | 
|---|
|  |  |  | List<MallMember> directors = mallMemberMapper.selectDirectorsOrStoreMaster(1); | 
|---|
|  |  |  | if (CollUtil.isNotEmpty(directors)) { | 
|---|
|  |  |  | BigDecimal total = totalIncome.multiply(new BigDecimal(dic.getValue()).divide(new BigDecimal("100"), 2, RoundingMode.HALF_UP)); | 
|---|
|  |  |  | BigDecimal pre = total.divide(new BigDecimal(directors.size()), 2, RoundingMode.HALF_UP); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | for (MallMember director : directors) { | 
|---|
|  |  |  | if (pre.compareTo(BigDecimal.ZERO) < 1) { | 
|---|
|  |  |  | 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()); | 
|---|
|  |  |  | changeScoreAndCommission(director.getId(), pre, MoneyFlowTypeEnum.DIRECTOR_BONUS.getValue(), null); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 店补 | 
|---|
|  |  |  | dic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(DataDictionaryEnum.COMMUNITY_BONUS.getType(), DataDictionaryEnum.COMMUNITY_BONUS.getCode()); | 
|---|
|  |  |  | List<MallMember> storeMasters = mallMemberMapper.selectDirectorsOrStoreMaster(2); | 
|---|
|  |  |  | if (CollUtil.isNotEmpty(storeMasters)) { | 
|---|
|  |  |  | BigDecimal total = totalIncome.multiply(new BigDecimal(dic.getValue()).divide(new BigDecimal("100"), 2, RoundingMode.HALF_UP)); | 
|---|
|  |  |  | BigDecimal pre = total.divide(new BigDecimal(storeMasters.size()), 2, RoundingMode.HALF_UP); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | for (MallMember storeMaster : storeMasters) { | 
|---|
|  |  |  | if (pre.compareTo(BigDecimal.ZERO) < 1) { | 
|---|
|  |  |  | 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()); | 
|---|
|  |  |  | changeScoreAndCommission(storeMaster.getId(), pre, MoneyFlowTypeEnum.COMMUNITY_BONUS.getValue(), null); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 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); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public void agentPerkJob(Date profitDate) { | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 代理商补贴 | 
|---|
|  |  |  | *  全体代理商 | 
|---|
|  |  |  | *  前一天全部业绩的百分比用来平分 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | log.info("######==代理商补贴==start==####"); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<MallMember> mallMembersAgentPerkList = mallMemberMapper.selectMemberByDirector(1); | 
|---|
|  |  |  | if (CollUtil.isEmpty(mallMembersAgentPerkList)) { | 
|---|
|  |  |  | return; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (profitDate == null) { | 
|---|
|  |  |  | profitDate = DateUtil.offset(new Date(), DateField.DAY_OF_YEAR, -1); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //前一天的总业绩 | 
|---|
|  |  |  | BigDecimal agentPerkAmountSum = mallAchieveRecordMapper.selectAchieveTotal("D", profitDate); | 
|---|
|  |  |  | //补贴百分比 | 
|---|
|  |  |  | DataDictionaryCustom agentPerkDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode( | 
|---|
|  |  |  | DataDictionaryEnum.AGENT_PERK.getType(), | 
|---|
|  |  |  | DataDictionaryEnum.AGENT_PERK.getCode() | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | if(ObjectUtil.isEmpty(agentPerkDic)){ | 
|---|
|  |  |  | return; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | BigDecimal agentPerk = new BigDecimal(agentPerkDic.getValue()).multiply(new BigDecimal("0.01")); | 
|---|
|  |  |  | agentPerkAmountSum = agentPerkAmountSum.multiply(agentPerk); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | BigDecimal agentPerkAmount = agentPerkAmountSum.divide(new BigDecimal(mallMembersAgentPerkList.size()), BigDecimal.ROUND_DOWN).setScale(2, BigDecimal.ROUND_DOWN); | 
|---|
|  |  |  | List<Long> mallMembersAgentPerkIds = mallMembersAgentPerkList.stream().map(MallMember::getId).collect(Collectors.toList()); | 
|---|
|  |  |  | List<MallMemberWallet> mallMemberWallets = mallMemberWalletMapper.selectMemberWalletsByIds(mallMembersAgentPerkIds); | 
|---|
|  |  |  | iAgentService.flowTotalScoreBalance( | 
|---|
|  |  |  | mallMemberWallets, | 
|---|
|  |  |  | agentPerkAmount, | 
|---|
|  |  |  | MoneyFlowTypeEnum.AGENT_PERK.getValue(), | 
|---|
|  |  |  | MallUtils.getOrderNum("AP"), | 
|---|
|  |  |  | 1L | 
|---|
|  |  |  | ); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | log.info("#####==代理商补贴==end==######" + | 
|---|
|  |  |  | "今日总补贴###" + agentPerkAmountSum.setScale(2, RoundingMode.HALF_UP) | 
|---|
|  |  |  | +"###人均###"+agentPerkAmount.setScale(2, RoundingMode.HALF_UP) | 
|---|
|  |  |  | +"###人数###"+mallMemberWallets.size()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public void offLinePerkJob(Date profitDate) { | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 线下服务中心补贴 | 
|---|
|  |  |  | *  全体线下服务商 | 
|---|
|  |  |  | *  前一天团队业绩的百分比用来平分 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | log.info("######==线下服务中心补贴==start==####"); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<MallMember> mallMembersOffLinePerkList = mallMemberMapper.selectMemberByStoreMaster(1); | 
|---|
|  |  |  | if (CollUtil.isEmpty(mallMembersOffLinePerkList)) { | 
|---|
|  |  |  | return; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //补贴百分比 | 
|---|
|  |  |  | DataDictionaryCustom offLinePerkDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode( | 
|---|
|  |  |  | DataDictionaryEnum.OFFLINE_PERK.getType(), | 
|---|
|  |  |  | DataDictionaryEnum.OFFLINE_PERK.getCode() | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | if(ObjectUtil.isEmpty(offLinePerkDic)){ | 
|---|
|  |  |  | return; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | BigDecimal offLinePerk = new BigDecimal(offLinePerkDic.getValue()).multiply(new BigDecimal("0.01")); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (profitDate == null) { | 
|---|
|  |  |  | profitDate = DateUtil.offset(new Date(), DateField.DAY_OF_YEAR, -1); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | for(MallMember mallMembersOffLinePerk : mallMembersOffLinePerkList){ | 
|---|
|  |  |  | String inviteId = mallMembersOffLinePerk.getInviteId(); | 
|---|
|  |  |  | //获取团队下所有成员 | 
|---|
|  |  |  | List<MallMember> allMallMemberList = mallMemberMapper.selectAllChildAgentListByInviteId(inviteId); | 
|---|
|  |  |  | //子团队中是否有线下服务商 | 
|---|
|  |  |  | List<MallMember> storeMasterMallMemberList = mallMemberMapper.selectAllChildAgentListByInviteIdAndStoreMaster(inviteId, 1); | 
|---|
|  |  |  | if(CollUtil.isNotEmpty(storeMasterMallMemberList)){ | 
|---|
|  |  |  | //如果有,该子团队成员不算业绩 | 
|---|
|  |  |  | List<MallMember> storeMasterMallMembers = new ArrayList<>(); | 
|---|
|  |  |  | for(MallMember storeMasterMallMember : storeMasterMallMemberList){ | 
|---|
|  |  |  | List<MallMember> storeMasterList = mallMemberMapper.selectAllChildAgentListByInviteId(storeMasterMallMember.getInviteId()); | 
|---|
|  |  |  | storeMasterMallMembers.addAll(storeMasterList); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | allMallMemberList.removeAll(storeMasterMallMembers); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //团队下所有人的业绩 | 
|---|
|  |  |  | List<Long> mallMembersOffLinePerkIds = allMallMemberList.stream().map(MallMember::getId).collect(Collectors.toList()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | BigDecimal offLinePerkAmountSum = mallAchieveRecordMapper.selectSumAchieveByMemberIds(mallMembersOffLinePerkIds,profitDate); | 
|---|
|  |  |  | //该团队产生的业绩金额 | 
|---|
|  |  |  | offLinePerkAmountSum = offLinePerkAmountSum.multiply(offLinePerk).setScale(2,BigDecimal.ROUND_DOWN); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //所有合伙人补贴至消费礼包的三倍额度需要复购一次。 | 
|---|
|  |  |  | MallMemberWallet mallMemberWallet = mallMemberWalletMapper.selectWalletByMemberId(mallMembersOffLinePerk.getId()); | 
|---|
|  |  |  | BigDecimal totalScore = mallMemberWallet.getTotalScore(); | 
|---|
|  |  |  | if(totalScore.compareTo(offLinePerkAmountSum) < 0){ | 
|---|
|  |  |  | offLinePerkAmountSum = totalScore; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if(BigDecimal.ZERO.compareTo(offLinePerkAmountSum) < 0){ | 
|---|
|  |  |  | //减少补贴额度 | 
|---|
|  |  |  | mallMemberWalletMapper.reduceTotalScoreById(offLinePerkAmountSum, mallMemberWallet.getId()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | iAgentService.reduceStar(mallMemberWallet.getMemberId(),offLinePerkAmountSum); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | mallMemberWalletMapper.addBalanceById(offLinePerkAmountSum, mallMemberWallet.getId()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | mallMoneyFlowService.addMoneyFlow( | 
|---|
|  |  |  | mallMembersOffLinePerk.getId(), | 
|---|
|  |  |  | offLinePerkAmountSum, | 
|---|
|  |  |  | MoneyFlowTypeEnum.OFFLINE_PERK.getValue(), | 
|---|
|  |  |  | MallUtils.getOrderNum("OLP"), | 
|---|
|  |  |  | FlowTypeEnum.BALANCE.getValue()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public void teamEqualsPerkJob(Date profitDate) { | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 全体用户 | 
|---|
|  |  |  | *      对象:产生了收益的用户的直属上级 | 
|---|
|  |  |  | *      条件:等级和用户等级一样 | 
|---|
|  |  |  | *      补贴:每日补贴的10%,例如用户当日的补贴总额为100,直属上级拿100*10%=10, | 
|---|
|  |  |  | *      限制:直推收益除外。 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | if (profitDate == null) { | 
|---|
|  |  |  | profitDate = DateUtil.offset(new Date(), DateField.DAY_OF_YEAR, -1); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //平级补贴百分比 | 
|---|
|  |  |  | DataDictionaryCustom teamEqualsPerkDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode( | 
|---|
|  |  |  | DataDictionaryEnum.TEAM_EQUALS_PERK.getType(), | 
|---|
|  |  |  | DataDictionaryEnum.TEAM_EQUALS_PERK.getCode()); | 
|---|
|  |  |  | BigDecimal teamEqualsPerkPercent = new BigDecimal(teamEqualsPerkDic.getValue()).abs().multiply(BigDecimal.valueOf(0.01)); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //产生了收益的用户和直属上级 | 
|---|
|  |  |  | List<AdminTeamEqualsPerkVo> adminTeamEqualsPerkVos = mallMoneyFlowMapper.selectTeamEqualsMemberByDate(profitDate); | 
|---|
|  |  |  | if(CollUtil.isNotEmpty(adminTeamEqualsPerkVos)){ | 
|---|
|  |  |  | for(AdminTeamEqualsPerkVo adminTeamEqualsPerkVo : adminTeamEqualsPerkVos){ | 
|---|
|  |  |  | BigDecimal sumAmount = adminTeamEqualsPerkVo.getSumAmount(); | 
|---|
|  |  |  | //平级补贴 | 
|---|
|  |  |  | BigDecimal teamEqualsPerkAmount = teamEqualsPerkPercent.multiply(sumAmount).setScale(2, BigDecimal.ROUND_DOWN); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | MallMemberWallet mallMemberWallet = mallMemberWalletMapper.selectWalletByMemberId(adminTeamEqualsPerkVo.getRtMemberId()); | 
|---|
|  |  |  | BigDecimal totalScore = mallMemberWallet.getTotalScore(); | 
|---|
|  |  |  | if(totalScore.compareTo(teamEqualsPerkAmount) < 0){ | 
|---|
|  |  |  | teamEqualsPerkAmount = totalScore; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if(BigDecimal.ZERO.compareTo(teamEqualsPerkAmount) < 0){ | 
|---|
|  |  |  | //减少补贴额度 | 
|---|
|  |  |  | mallMemberWalletMapper.reduceTotalScoreById(teamEqualsPerkAmount, mallMemberWallet.getId()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | iAgentService.reduceStar(mallMemberWallet.getMemberId(),teamEqualsPerkAmount); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | mallMemberWalletMapper.addBalanceById(teamEqualsPerkAmount, mallMemberWallet.getId()); | 
|---|
|  |  |  | // | 
|---|
|  |  |  | //                    mallMoneyFlowService.addMoneyFlow( | 
|---|
|  |  |  | //                            adminTeamEqualsPerkVo.getRtMemberId(), | 
|---|
|  |  |  | //                            teamEqualsPerkAmount, | 
|---|
|  |  |  | //                            MoneyFlowTypeEnum.TEAM_EQUALS_PERK.getValue(), | 
|---|
|  |  |  | //                            MallUtils.getOrderNum("TEP"), | 
|---|
|  |  |  | //                            FlowTypeEnum.BALANCE.getValue()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | mallMoneyFlowService.addMoneyFlow( | 
|---|
|  |  |  | adminTeamEqualsPerkVo.getRtMemberId(), | 
|---|
|  |  |  | teamEqualsPerkAmount, | 
|---|
|  |  |  | MoneyFlowTypeEnum.TEAM_EQUALS_PERK.getValue(), | 
|---|
|  |  |  | MallUtils.getOrderNum("TEP"), | 
|---|
|  |  |  | "平级奖励补贴", | 
|---|
|  |  |  | "补贴额度:"+mallMemberWallet.getTotalScore(), | 
|---|
|  |  |  | adminTeamEqualsPerkVo.getMemberId(), | 
|---|
|  |  |  | 2, | 
|---|
|  |  |  | FlowTypeEnum.BALANCE.getValue(), | 
|---|
|  |  |  | 1); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public void mqPerkRetryJob() { | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 每次拿重试次数大于零 | 
|---|
|  |  |  | * 按ID asc排序的十条数据 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | //        List<MallMqRecord> mallMqRecords = mallMqRecordMapper.selectByStateLimitTen(2); | 
|---|
|  |  |  | //        if(CollUtil.isEmpty(mallMqRecords)){ | 
|---|
|  |  |  | //            return; | 
|---|
|  |  |  | //        } | 
|---|
|  |  |  | //        DateTime dateTime = DateUtil.offsetMinute(new Date(), -5); | 
|---|
|  |  |  | //        for(MallMqRecord mallMqRecord : mallMqRecords){ | 
|---|
|  |  |  | //            if(DateUtil.compare(dateTime,mallMqRecord.getCreateTime()) <= 0){ | 
|---|
|  |  |  | //                continue; | 
|---|
|  |  |  | //            } | 
|---|
|  |  |  | //            Integer retryTimes = mallMqRecord.getRetryTimes(); | 
|---|
|  |  |  | //            if(retryTimes <= 0){ | 
|---|
|  |  |  | //                continue; | 
|---|
|  |  |  | //            } | 
|---|
|  |  |  | //            retryTimes = retryTimes - 1; | 
|---|
|  |  |  | //            mallMqRecord.setRetryTimes(retryTimes); | 
|---|
|  |  |  | //            mallMqRecordMapper.updateById(mallMqRecord); | 
|---|
|  |  |  | // | 
|---|
|  |  |  | //            Long orderId = mallMqRecord.getOrderId(); | 
|---|
|  |  |  | //            if(mallMqRecord.getState() == 2){ | 
|---|
|  |  |  | //                agentProducer.sendPerkMoneyMsg(orderId); | 
|---|
|  |  |  | //            } | 
|---|
|  |  |  | //        } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | @Transactional(rollbackFor = Exception.class) | 
|---|
|  |  |  | public void scoreRecordReleaseJob() { | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 每日按照比例释放记录的百分比到用户的绿色凭证账户 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | //获取全部剩余数量大于零的记录 | 
|---|
|  |  |  | List<MallScoreRecord> mallScoreRecords = mallScoreRecordMapper.selectList(); | 
|---|
|  |  |  | if(CollUtil.isEmpty(mallScoreRecords)){ | 
|---|
|  |  |  | return; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | DataDictionaryCustom roleReleasePercentDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode( | 
|---|
|  |  |  | GreenScoreEnum.ROLE_RELEASE_PERCENT.getType(), | 
|---|
|  |  |  | GreenScoreEnum.ROLE_RELEASE_PERCENT.getCode() | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | if(ObjectUtil.isEmpty(roleReleasePercentDic)){ | 
|---|
|  |  |  | return; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //释放比例 | 
|---|
|  |  |  | BigDecimal roleReleasePercent = new BigDecimal(roleReleasePercentDic.getValue()).multiply(new BigDecimal(0.001)); | 
|---|
|  |  |  | for(MallScoreRecord mallScoreRecord : mallScoreRecords){ | 
|---|
|  |  |  | Long memberId = mallScoreRecord.getMemberId(); | 
|---|
|  |  |  | //每日释放的绿色凭证数量 = 总数 * 释放比例 | 
|---|
|  |  |  | //            BigDecimal scoreCnt = mallScoreRecord.getScoreCnt(); | 
|---|
|  |  |  | BigDecimal scoreCnt = mallScoreRecord.getSurplusCnt(); | 
|---|
|  |  |  | BigDecimal scoreReleaseCnt = scoreCnt.multiply(roleReleasePercent).setScale(2,BigDecimal.ROUND_DOWN); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | BigDecimal surplusCnt = mallScoreRecord.getSurplusCnt(); | 
|---|
|  |  |  | if(scoreReleaseCnt.compareTo(surplusCnt) >= 0){ | 
|---|
|  |  |  | scoreReleaseCnt = surplusCnt; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if(scoreReleaseCnt.compareTo(BigDecimal.ZERO) > 0){ | 
|---|
|  |  |  | releaseToMemberAndAddFlow(scoreReleaseCnt,memberId, | 
|---|
|  |  |  | MoneyFlowTypeEnum.ROLE_RELEASE_SCORE.getValue(),mallScoreRecord.getScoreNo()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //更新凭证记录的剩余数量 | 
|---|
|  |  |  | surplusCnt = surplusCnt.subtract(scoreReleaseCnt); | 
|---|
|  |  |  | mallScoreRecord.setSurplusCnt(surplusCnt); | 
|---|
|  |  |  | mallScoreRecordMapper.updateById(mallScoreRecord); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | @Transactional(rollbackFor = Exception.class) | 
|---|
|  |  |  | public void achieveReleaseJob() { | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 业绩产生凭证 | 
|---|
|  |  |  | *      获取每日最大产生的凭证数量 | 
|---|
|  |  |  | *      获取每日总业绩 | 
|---|
|  |  |  | *      获取业绩产生凭证的最大值和最小值 | 
|---|
|  |  |  | *      每条业绩记录占 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //获取每日总业绩 | 
|---|
|  |  |  | Date profitDate = DateUtil.offset(new Date(), DateField.DAY_OF_YEAR, -1); | 
|---|
|  |  |  | BigDecimal achieveTotal = mallAchieveRecordMapper.selectAchieveTotal("D", profitDate); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | DataDictionaryCustom achieveMinDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode( | 
|---|
|  |  |  | GreenScoreEnum.ACHIEVE_MIN.getType(), | 
|---|
|  |  |  | GreenScoreEnum.ACHIEVE_MIN.getCode() | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | //业绩的最小值 | 
|---|
|  |  |  | BigDecimal achieveMin = new BigDecimal(achieveMinDic.getValue() == null ? "0" : achieveMinDic.getValue()); | 
|---|
|  |  |  | if(achieveTotal.compareTo(achieveMin) < 0){ | 
|---|
|  |  |  | return; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | DataDictionaryCustom achieveMaxDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode( | 
|---|
|  |  |  | GreenScoreEnum.ACHIEVE_MAX.getType(), | 
|---|
|  |  |  | GreenScoreEnum.ACHIEVE_MAX.getCode() | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | //业绩的最大值 | 
|---|
|  |  |  | BigDecimal achieveMax = new BigDecimal(achieveMaxDic.getValue() == null ? "0" : achieveMaxDic.getValue()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 获取每日最大产生的凭证数量 | 
|---|
|  |  |  | *      改成每日产出固定值 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | //        BigDecimal achieveDailyRelease = getAchieveDailyRelease(); | 
|---|
|  |  |  | DataDictionaryCustom achieveReleaseDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode( | 
|---|
|  |  |  | GreenScoreEnum.ACHIEVE_RELEASE.getType(), | 
|---|
|  |  |  | GreenScoreEnum.ACHIEVE_RELEASE.getCode() | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | BigDecimal achieveDailyRelease = new BigDecimal(achieveReleaseDic.getValue() == null ? "0" : achieveReleaseDic.getValue()); | 
|---|
|  |  |  | if(achieveDailyRelease.compareTo(BigDecimal.ZERO) <= 0){ | 
|---|
|  |  |  | return; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if(achieveTotal.compareTo(achieveMax) < 0){ | 
|---|
|  |  |  | BigDecimal divide = achieveTotal.divide(achieveMax, 2, BigDecimal.ROUND_DOWN); | 
|---|
|  |  |  | achieveDailyRelease = achieveDailyRelease.multiply(divide).setScale(2,BigDecimal.ROUND_DOWN); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 实际每日最大产生的凭证数量 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | BigDecimal achieveDailyReleaseReal = BigDecimal.ZERO; | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 业务编号 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | String scoreNo = MallUtils.getOrderNum("ARSX"); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 20%给合伙人、联创 | 
|---|
|  |  |  | *  5% 给联创 10% | 
|---|
|  |  |  | *  15% 给合伙人 10% | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | DataDictionaryCustom roleAchievePercentDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode( | 
|---|
|  |  |  | GreenScoreEnum.ROLE_ACHIEVE_PERCENT.getType(), | 
|---|
|  |  |  | GreenScoreEnum.ROLE_ACHIEVE_PERCENT.getCode() | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | //业绩产生凭证给创世的比例 | 
|---|
|  |  |  | BigDecimal roleAchievePercent = new BigDecimal(roleAchievePercentDic.getValue() == null ? "0" : roleAchievePercentDic.getValue()) | 
|---|
|  |  |  | .multiply(new BigDecimal(0.01)); | 
|---|
|  |  |  | //创世的凭证数量 | 
|---|
|  |  |  | BigDecimal roleAchieveRelease = achieveDailyRelease.multiply(roleAchievePercent).setScale(2, BigDecimal.ROUND_DOWN); | 
|---|
|  |  |  | List<MallMember> roleAchieveReleaseMembers = mallMemberMapper.selectByRole(3,1); | 
|---|
|  |  |  | if(CollUtil.isNotEmpty(roleAchieveReleaseMembers)){ | 
|---|
|  |  |  | //联创拿走0.25 | 
|---|
|  |  |  | //            BigDecimal multiply = roleAchieveRelease.multiply(new BigDecimal(0.25)); | 
|---|
|  |  |  | BigDecimal multiply = roleAchieveRelease.multiply(new BigDecimal(0.5)); | 
|---|
|  |  |  | BigDecimal memberAchieveRelease = multiply.divide(new BigDecimal(roleAchieveReleaseMembers.size()), 2, BigDecimal.ROUND_DOWN); | 
|---|
|  |  |  | if(memberAchieveRelease.compareTo(BigDecimal.ZERO) > 0){ | 
|---|
|  |  |  | for(MallMember mallMember : roleAchieveReleaseMembers){ | 
|---|
|  |  |  |  | 
|---|
|  |  |  | releaseToMemberAndAddFlow(memberAchieveRelease,mallMember.getId(), | 
|---|
|  |  |  | MoneyFlowTypeEnum.ACHIEVE_RELEASE_SCORE_LC.getValue(),scoreNo); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | achieveDailyReleaseReal = achieveDailyReleaseReal.add(memberAchieveRelease); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //合伙人拿走0.75 | 
|---|
|  |  |  | List<MallMember> roleAchieveReleaseHHR = mallMemberMapper.selectByRole(4,1); | 
|---|
|  |  |  | if(CollUtil.isNotEmpty(roleAchieveReleaseHHR)){ | 
|---|
|  |  |  | //合伙人拿走0.75 | 
|---|
|  |  |  | //            BigDecimal multiply = roleAchieveRelease.multiply(new BigDecimal(0.75)); | 
|---|
|  |  |  | BigDecimal multiply = roleAchieveRelease.multiply(new BigDecimal(0.5)); | 
|---|
|  |  |  | BigDecimal memberAchieveReleaseHHR = multiply.divide(new BigDecimal(roleAchieveReleaseHHR.size()), 2, BigDecimal.ROUND_DOWN); | 
|---|
|  |  |  | if(memberAchieveReleaseHHR.compareTo(BigDecimal.ZERO) > 0){ | 
|---|
|  |  |  | for(MallMember mallMember : roleAchieveReleaseHHR){ | 
|---|
|  |  |  |  | 
|---|
|  |  |  | releaseToMemberAndAddFlow(memberAchieveReleaseHHR,mallMember.getId(), | 
|---|
|  |  |  | MoneyFlowTypeEnum.ACHIEVE_RELEASE_SCORE_HHR.getValue(),scoreNo); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | achieveDailyReleaseReal = achieveDailyReleaseReal.add(memberAchieveReleaseHHR); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 30%按贡献点分配给所有人 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | DataDictionaryCustom starAchievePercentDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode( | 
|---|
|  |  |  | GreenScoreEnum.STAR_ACHIEVE_PERCENT.getType(), | 
|---|
|  |  |  | GreenScoreEnum.STAR_ACHIEVE_PERCENT.getCode() | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | //业绩产生凭证给贡献点分配给所有人 | 
|---|
|  |  |  | BigDecimal starAchievePercent = new BigDecimal(starAchievePercentDic.getValue() == null ? "0" : starAchievePercentDic.getValue()) | 
|---|
|  |  |  | .multiply(new BigDecimal(0.01)); | 
|---|
|  |  |  | //贡献点的凭证数量 | 
|---|
|  |  |  | BigDecimal starAchieveRelease = achieveDailyRelease.multiply(starAchievePercent).setScale(2, BigDecimal.ROUND_DOWN); | 
|---|
|  |  |  | BigDecimal starSumCnt = mallMemberWalletMapper.selectSumStar(); | 
|---|
|  |  |  | if(starSumCnt.compareTo(BigDecimal.ZERO) > 0){ | 
|---|
|  |  |  | //每一个贡献点获取的凭证 | 
|---|
|  |  |  | BigDecimal starAchieveReleaseOne = starAchieveRelease.divide(starSumCnt, 2, BigDecimal.ROUND_DOWN); | 
|---|
|  |  |  | List<MallMemberWallet> mallMemberWallets = mallMemberWalletMapper.selectStar(); | 
|---|
|  |  |  | if(CollUtil.isNotEmpty(mallMemberWallets) && starAchieveReleaseOne.compareTo(BigDecimal.ZERO) > 0){ | 
|---|
|  |  |  | for(MallMemberWallet mallMemberWallet : mallMemberWallets){ | 
|---|
|  |  |  | //每个人获取的凭证 = 贡献点 * 每一个贡献点值的凭证 | 
|---|
|  |  |  | BigDecimal bigDecimal = starAchieveReleaseOne.multiply(new BigDecimal(mallMemberWallet.getStar())).setScale(2, BigDecimal.ROUND_DOWN); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | releaseToMemberAndAddFlow(bigDecimal,mallMemberWallet.getMemberId(), | 
|---|
|  |  |  | MoneyFlowTypeEnum.ACHIEVE_RELEASE_SCORE_GXD.getValue(),scoreNo); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | achieveDailyReleaseReal = achieveDailyReleaseReal.add(bigDecimal); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 50%按按星级分配给所有人 | 
|---|
|  |  |  | * 二星  30% | 
|---|
|  |  |  | * 三星  25% | 
|---|
|  |  |  | * 四星  20% | 
|---|
|  |  |  | * 五星  15% | 
|---|
|  |  |  | * 六星  10% | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | DataDictionaryCustom levelAchievePercentDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode( | 
|---|
|  |  |  | GreenScoreEnum.LEVEL_ACHIEVE_PERCENT.getType(), | 
|---|
|  |  |  | GreenScoreEnum.LEVEL_ACHIEVE_PERCENT.getCode() | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | //业绩产生凭证给星级分配给所有人 | 
|---|
|  |  |  | BigDecimal levelAchievePercent = new BigDecimal(levelAchievePercentDic.getValue() == null ? "0" : levelAchievePercentDic.getValue()) | 
|---|
|  |  |  | .multiply(new BigDecimal(0.01)); | 
|---|
|  |  |  | //业绩产生凭证给星级分配给所有人总数 | 
|---|
|  |  |  | BigDecimal levelAchieveRelease = achieveDailyRelease.multiply(levelAchievePercent).setScale(2, BigDecimal.ROUND_DOWN); | 
|---|
|  |  |  | BigDecimal thirdRelease = releaseByLevel(levelAchieveRelease, AgentLevelEnum.THIRD_LEVEL.getCode(), new BigDecimal(0.3),scoreNo); | 
|---|
|  |  |  | achieveDailyReleaseReal = achieveDailyReleaseReal.add(thirdRelease); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | BigDecimal fourRelease = releaseByLevel(levelAchieveRelease, AgentLevelEnum.FOUR_LEVEL.getCode(), new BigDecimal(0.25),scoreNo); | 
|---|
|  |  |  | achieveDailyReleaseReal = achieveDailyReleaseReal.add(fourRelease); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | BigDecimal fiveRelease = releaseByLevel(levelAchieveRelease, AgentLevelEnum.FIFTH_LEVEL.getCode(), new BigDecimal(0.2),scoreNo); | 
|---|
|  |  |  | achieveDailyReleaseReal = achieveDailyReleaseReal.add(fiveRelease); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | BigDecimal sixRelease = releaseByLevel(levelAchieveRelease, AgentLevelEnum.SIX_LEVEL.getCode(), new BigDecimal(0.15),scoreNo); | 
|---|
|  |  |  | achieveDailyReleaseReal = achieveDailyReleaseReal.add(sixRelease); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | BigDecimal sevenRelease = releaseByLevel(levelAchieveRelease, AgentLevelEnum.SEVEN_LEVEL.getCode(), new BigDecimal(0.1),scoreNo); | 
|---|
|  |  |  | achieveDailyReleaseReal = achieveDailyReleaseReal.add(sevenRelease); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if(achieveDailyReleaseReal.compareTo(BigDecimal.ZERO) > 0){ | 
|---|
|  |  |  | DataDictionaryCustom surplusCntDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode( | 
|---|
|  |  |  | GreenScoreEnum.SURPLUS_CNT.getType(), | 
|---|
|  |  |  | GreenScoreEnum.SURPLUS_CNT.getCode() | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | //绿色积分剩余数量 | 
|---|
|  |  |  | BigDecimal surplusCnt = new BigDecimal(surplusCntDic.getValue() == null ? "0" : surplusCntDic.getValue()); | 
|---|
|  |  |  | BigDecimal subtract = surplusCnt.subtract(achieveDailyReleaseReal).setScale(2,BigDecimal.ROUND_DOWN); | 
|---|
|  |  |  | surplusCntDic.setValue(subtract.toString()); | 
|---|
|  |  |  | dataDictionaryCustomMapper.updateById(surplusCntDic); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | log.info("昨日实际业绩:{},昨日凭证总共:{},实际产生凭证:{}", | 
|---|
|  |  |  | achieveTotal,achieveDailyRelease,achieveDailyReleaseReal); | 
|---|
|  |  |  | MallScoreAchieveRelease mallScoreAchieveRelease = new MallScoreAchieveRelease(); | 
|---|
|  |  |  | mallScoreAchieveRelease.setAchieve(achieveTotal); | 
|---|
|  |  |  | mallScoreAchieveRelease.setReleaseNo(scoreNo); | 
|---|
|  |  |  | mallScoreAchieveRelease.setVoucherExpect(achieveDailyRelease); | 
|---|
|  |  |  | mallScoreAchieveRelease.setVoucherReal(achieveDailyReleaseReal); | 
|---|
|  |  |  | mallScoreAchieveReleaseMapper.insert(mallScoreAchieveRelease); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | @Transactional(rollbackFor = Exception.class) | 
|---|
|  |  |  | public void selaHalfVoucher(String price) { | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 获取所有凭证大于0的用户 | 
|---|
|  |  |  | * 当前价格卖出账户的一半凭证 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | BigDecimal scorePrice = new BigDecimal(price == null ? "0" : price); | 
|---|
|  |  |  | if(scorePrice.compareTo(BigDecimal.ZERO) <= 0){ | 
|---|
|  |  |  | return; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | List<MallMemberWallet> mallMemberWallets = mallMemberWalletMapper.selectList(null); | 
|---|
|  |  |  | if(CollUtil.isNotEmpty(mallMemberWallets)){ | 
|---|
|  |  |  | List<MallMemberWallet> wallets = mallMemberWallets | 
|---|
|  |  |  | .stream() | 
|---|
|  |  |  | .filter(mallMemberWallet -> mallMemberWallet.getVoucherCnt().compareTo(BigDecimal.ZERO) > 0) | 
|---|
|  |  |  | .collect(Collectors.toList()); | 
|---|
|  |  |  | if(CollUtil.isNotEmpty(wallets)){ | 
|---|
|  |  |  | BigDecimal scorePoolCntAdd = BigDecimal.ZERO; | 
|---|
|  |  |  | //绿色积分剩余数量 | 
|---|
|  |  |  | for(MallMemberWallet mallMemberWallet : wallets){ | 
|---|
|  |  |  | //增加账户的凭证金额,减少当前的一半的凭证数量 | 
|---|
|  |  |  | BigDecimal voucherCnt = mallMemberWallet.getVoucherCnt().divide(new BigDecimal(2), 2, BigDecimal.ROUND_DOWN) | 
|---|
|  |  |  | .setScale(2,BigDecimal.ROUND_DOWN); | 
|---|
|  |  |  | BigDecimal voucherAmountAdd = scorePrice.multiply(voucherCnt) | 
|---|
|  |  |  | .setScale(2,BigDecimal.ROUND_DOWN); | 
|---|
|  |  |  | mallMemberWalletMapper.addVorCherAmountAndCntById(voucherAmountAdd,voucherCnt,mallMemberWallet.getId()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | scorePoolCntAdd = scorePoolCntAdd.add(voucherCnt); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | DataDictionaryCustom surplusCntDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode( | 
|---|
|  |  |  | GreenScoreEnum.SURPLUS_CNT.getType(), | 
|---|
|  |  |  | GreenScoreEnum.SURPLUS_CNT.getCode() | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | //增加绿色积分剩余数量 | 
|---|
|  |  |  | BigDecimal surplusCnt = new BigDecimal(surplusCntDic.getValue() == null ? "0" : surplusCntDic.getValue()); | 
|---|
|  |  |  | BigDecimal voucherCntAdd = surplusCnt.add(voucherCnt).setScale(2,BigDecimal.ROUND_DOWN); | 
|---|
|  |  |  | surplusCntDic.setValue(voucherCntAdd.toString()); | 
|---|
|  |  |  | dataDictionaryCustomMapper.updateById(surplusCntDic); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 生成一条卖出记录 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | String voucherNo = MallUtils.getOrderNum("VS"); | 
|---|
|  |  |  | MallScoreVoucher mallScoreVoucher = new MallScoreVoucher(); | 
|---|
|  |  |  | mallScoreVoucher.setVoucherNo(voucherNo); | 
|---|
|  |  |  | mallScoreVoucher.setMemberId(mallMemberWallet.getMemberId()); | 
|---|
|  |  |  | mallScoreVoucher.setVoucherCnt(voucherCnt); | 
|---|
|  |  |  | mallScoreVoucher.setPrice(scorePrice); | 
|---|
|  |  |  | mallScoreVoucher.setVoucherAmount(voucherAmountAdd); | 
|---|
|  |  |  | mallScoreVoucher.setType("S"); | 
|---|
|  |  |  | mallScoreVoucherMapper.insert(mallScoreVoucher); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //产生一条流水记录 | 
|---|
|  |  |  | mallMoneyFlowService.addMoneyFlow( | 
|---|
|  |  |  | mallMemberWallet.getMemberId(), | 
|---|
|  |  |  | voucherAmountAdd, | 
|---|
|  |  |  | MoneyFlowTypeEnum.VOUCHER_SALE.getValue(), | 
|---|
|  |  |  | voucherNo, | 
|---|
|  |  |  | FlowTypeEnum.BALANCE.getValue()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //增加积分凭证池的凭证数量 | 
|---|
|  |  |  | DataDictionaryCustom scorePoolCntDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode( | 
|---|
|  |  |  | GreenScoreEnum.SCORE_POOL_CNT.getType(), | 
|---|
|  |  |  | GreenScoreEnum.SCORE_POOL_CNT.getCode() | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | //增加绿色积分剩余数量 | 
|---|
|  |  |  | BigDecimal scorePoolCnt = new BigDecimal(scorePoolCntDic.getValue() == null ? "0" : scorePoolCntDic.getValue()); | 
|---|
|  |  |  | scorePoolCnt = scorePoolCnt.add(scorePoolCntAdd); | 
|---|
|  |  |  | scorePoolCntDic.setValue(scorePoolCnt.toString()); | 
|---|
|  |  |  | dataDictionaryCustomMapper.updateById(scorePoolCntDic); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public void fcmNFTExchangeMsg(String cnt) { | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 销毁数量 按照比例销毁或者返利给节点 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | BigDecimal destoryCntTotal = new BigDecimal(cnt); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | DataDictionaryCustom totalPercentDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode( | 
|---|
|  |  |  | DataDictionaryEnum.FCM_DESTORY_TOTAL_PERCENT.getType(), | 
|---|
|  |  |  | DataDictionaryEnum.FCM_DESTORY_TOTAL_PERCENT.getCode() | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | BigDecimal totalPercent = new BigDecimal(totalPercentDic.getValue()).multiply(AppContants.BASIC_PERCENT); | 
|---|
|  |  |  | //销毁数量 | 
|---|
|  |  |  | BigDecimal destoryCnt = destoryCntTotal.multiply(totalPercent).setScale(2,BigDecimal.ROUND_DOWN); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | DataDictionaryCustom pointPercentDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode( | 
|---|
|  |  |  | DataDictionaryEnum.FCM_DESTORY_POINT_PERCENT.getType(), | 
|---|
|  |  |  | DataDictionaryEnum.FCM_DESTORY_POINT_PERCENT.getCode() | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | BigDecimal pointPercent = new BigDecimal(pointPercentDic.getValue()).multiply(AppContants.BASIC_PERCENT); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //节点评分总数量 | 
|---|
|  |  |  | BigDecimal pointCnt = destoryCntTotal.multiply(pointPercent).setScale(2,BigDecimal.ROUND_DOWN); | 
|---|
|  |  |  | //给每个节点平分pointCnt。 | 
|---|
|  |  |  | QueryWrapper<MallMember> queryWrapper = new QueryWrapper<>(); | 
|---|
|  |  |  | queryWrapper.eq("partner",1); | 
|---|
|  |  |  | List<MallMember> mallMembers = mallMemberMapper.selectList(queryWrapper); | 
|---|
|  |  |  | if(CollUtil.isNotEmpty(mallMembers)){ | 
|---|
|  |  |  | BigDecimal dividePointCnt = pointCnt.divide(new BigDecimal(mallMembers.size()), 2, BigDecimal.ROUND_DOWN); | 
|---|
|  |  |  | for(MallMember mallMember : mallMembers){ | 
|---|
|  |  |  | Long memberId = mallMember.getId(); | 
|---|
|  |  |  | MallMemberAmount mallMemberAmount = mallMemberAmountMapper.selectByMemberId(memberId); | 
|---|
|  |  |  | mallMemberAmount.setFcmCntAva(mallMemberAmount.getFcmCntAva().add(dividePointCnt)); | 
|---|
|  |  |  | mallMemberAmountMapper.updateFcmCntAvaById(mallMemberAmount); | 
|---|
|  |  |  | String orderNo = MallUtils.getOrderNum("JD"); | 
|---|
|  |  |  | iMallMoneyFlowService.addMoneyFlow( | 
|---|
|  |  |  | memberId, | 
|---|
|  |  |  | dividePointCnt, | 
|---|
|  |  |  | MoneyFlowTypeNewEnum.PERK_POINT.getValue(), | 
|---|
|  |  |  | orderNo, | 
|---|
|  |  |  | mallMember.getId(), | 
|---|
|  |  |  | FlowTypeNewEnum.FCM_COIN.getValue(), | 
|---|
|  |  |  | MoneyFlowTypeNewEnum.PERK_POINT.getDescrition()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //更新总销毁数量 | 
|---|
|  |  |  | DataDictionaryCustom fcmDestoryTotalDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode( | 
|---|
|  |  |  | DataDictionaryEnum.FCM_DESTORY_TOTAL.getType(), | 
|---|
|  |  |  | DataDictionaryEnum.FCM_DESTORY_TOTAL.getCode() | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | BigDecimal fcmDestoryTotal = new BigDecimal(fcmDestoryTotalDic.getValue()); | 
|---|
|  |  |  | fcmDestoryTotal = fcmDestoryTotal.add(destoryCnt); | 
|---|
|  |  |  | commonService.updateDataDic( | 
|---|
|  |  |  | DataDictionaryEnum.FCM_DESTORY_TOTAL.getType(), | 
|---|
|  |  |  | DataDictionaryEnum.FCM_DESTORY_TOTAL.getCode(), | 
|---|
|  |  |  | fcmDestoryTotal.toString()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | DataDictionaryCustom fcmDestoryCntDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode( | 
|---|
|  |  |  | DataDictionaryEnum.FCM_DESTORY_CNT.getType(), | 
|---|
|  |  |  | DataDictionaryEnum.FCM_DESTORY_CNT.getCode() | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | BigDecimal fcmDestoryCnt = new BigDecimal(fcmDestoryCntDic.getValue()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | BigDecimal fcmDestoryCntAdd = fcmDestoryCnt.add(destoryCnt); | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 每次销毁10000个,价格增加0.1 | 
|---|
|  |  |  | * 满足的次数 divide | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | BigDecimal divide = fcmDestoryCntAdd.divide(AppContants.FCM_BASIC, 0, BigDecimal.ROUND_DOWN); | 
|---|
|  |  |  | if(BigDecimal.ZERO.compareTo(divide) == 0){ | 
|---|
|  |  |  | commonService.updateDataDic( | 
|---|
|  |  |  | DataDictionaryEnum.FCM_DESTORY_CNT.getType(), | 
|---|
|  |  |  | DataDictionaryEnum.FCM_DESTORY_CNT.getCode(), | 
|---|
|  |  |  | fcmDestoryCntAdd.toString()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if(BigDecimal.ZERO.compareTo(divide) < 0){ | 
|---|
|  |  |  | //例:累计15000 去掉10000,累计只剩5000 | 
|---|
|  |  |  | BigDecimal fcmDestoryCntReal = fcmDestoryCntAdd.subtract(divide.multiply(AppContants.FCM_BASIC)); | 
|---|
|  |  |  | commonService.updateDataDic( | 
|---|
|  |  |  | DataDictionaryEnum.FCM_DESTORY_CNT.getType(), | 
|---|
|  |  |  | DataDictionaryEnum.FCM_DESTORY_CNT.getCode(), | 
|---|
|  |  |  | fcmDestoryCntReal.toString()); | 
|---|
|  |  |  | //更新价格 | 
|---|
|  |  |  | DataDictionaryCustom fcmPriceDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode( | 
|---|
|  |  |  | DataDictionaryEnum.FCM_PRICE.getType(), | 
|---|
|  |  |  | DataDictionaryEnum.FCM_PRICE.getCode() | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | BigDecimal fcmPrice = new BigDecimal(fcmPriceDic.getValue()); | 
|---|
|  |  |  | fcmPrice = fcmPrice.add(AppContants.FCM_BASIC_ADD_PRICE.multiply(divide)); | 
|---|
|  |  |  | commonService.updateDataDic( | 
|---|
|  |  |  | DataDictionaryEnum.FCM_PRICE.getType(), | 
|---|
|  |  |  | DataDictionaryEnum.FCM_PRICE.getCode(), | 
|---|
|  |  |  | fcmPrice.toString()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public void fcmOrderSellInsureMsg(Long sellRecordId) { | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 买单确认 | 
|---|
|  |  |  | * 判断买单是否存在、是否已支付 | 
|---|
|  |  |  | * 判断买单是否存在、是否已支付 | 
|---|
|  |  |  | * 更新卖单状态 | 
|---|
|  |  |  | * 更新买单状态 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | MallProductSellRecord mallProductSellRecord = mallProductSellRecordMapper.selectById(sellRecordId); | 
|---|
|  |  |  | if(ObjectUtil.isEmpty(mallProductSellRecord)){ | 
|---|
|  |  |  | return; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | Integer state = mallProductSellRecord.getState(); | 
|---|
|  |  |  | if(ProductEnum.PRODUCT_MATE_STATE_CONFIRM.getValue() != state){ | 
|---|
|  |  |  | return; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | MallProductBuyRecord mallProductBuyRecord = mallProductBuyRecordMapper.selectById(mallProductSellRecord.getBuyRecordId()); | 
|---|
|  |  |  | if(ObjectUtil.isEmpty(mallProductBuyRecord)){ | 
|---|
|  |  |  | return; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | Integer stateBuy = mallProductBuyRecord.getState(); | 
|---|
|  |  |  | if(ProductEnum.PRODUCT_MATE_STATE_CONFIRM.getValue() != stateBuy){ | 
|---|
|  |  |  | return; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | mallProductSellRecord.setState(ProductEnum.PRODUCT_MATE_STATE_FINISH.getValue()); | 
|---|
|  |  |  | mallProductSellRecordMapper.updateById(mallProductSellRecord); | 
|---|
|  |  |  | mallProductBuyRecord.setState(ProductEnum.PRODUCT_MATE_STATE_FINISH.getValue()); | 
|---|
|  |  |  | mallProductBuyRecordMapper.updateById(mallProductBuyRecord); | 
|---|
|  |  |  | Long sellId = mallProductSellRecord.getSellId(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //已完成的买单 | 
|---|
|  |  |  | List<MallProductSellRecord> mallProductSellRecords = mallProductSellRecordMapper.selectListBySellId(sellId,ProductEnum.PRODUCT_MATE_STATE_FINISH.getValue()); | 
|---|
|  |  |  | if(CollUtil.isNotEmpty(mallProductSellRecords)){ | 
|---|
|  |  |  | //实际支付总数 | 
|---|
|  |  |  | BigDecimal nftCntTotal = mallProductSellRecords.stream().map(MallProductSellRecord::getNftCnt).reduce(BigDecimal.ZERO, BigDecimal::add); | 
|---|
|  |  |  | MallProductSell mallProductSell = mallProductSellMapper.selectById(sellId); | 
|---|
|  |  |  | if(nftCntTotal.compareTo(mallProductSell.getNftCnt()) >= 0){ | 
|---|
|  |  |  | mallProductSell.setState(ProductEnum.PRODUCT_SELL_SUCCESS.getValue()); | 
|---|
|  |  |  | mallProductSellMapper.updateById(mallProductSell); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Long buyId = mallProductBuyRecord.getBuyId(); | 
|---|
|  |  |  | List<MallProductBuyRecord> mallProductBuyRecords = mallProductBuyRecordMapper.selectListByBuyId(buyId,ProductEnum.PRODUCT_MATE_STATE_FINISH.getValue()); | 
|---|
|  |  |  | if(CollUtil.isNotEmpty(mallProductBuyRecords)){ | 
|---|
|  |  |  | //实际支付总数 | 
|---|
|  |  |  | BigDecimal nftCntTotalBuy = mallProductBuyRecords.stream().map(MallProductBuyRecord::getPickNftCnt).reduce(BigDecimal.ZERO, BigDecimal::add); | 
|---|
|  |  |  | MallProductBuy mallProductBuy = mallProductBuyMapper.selectById(buyId); | 
|---|
|  |  |  | if(nftCntTotalBuy.compareTo(mallProductBuy.getNftTotal()) >= 0){ | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Long productNftId = mallProductBuy.getProductNftId(); | 
|---|
|  |  |  | MallProductNft mallProductNft = mallProductNftMapper.selectById(productNftId); | 
|---|
|  |  |  | BigDecimal perkTime = mallProductNft.getPerkTime(); | 
|---|
|  |  |  | BigDecimal totalPerk = perkTime.multiply(mallProductBuy.getNftTotal()).setScale(2, BigDecimal.ROUND_DOWN); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | mallProductBuy.setTotalPerk(totalPerk); | 
|---|
|  |  |  | mallProductBuy.setState(ProductEnum.PRODUCT_BUY_SUCCESS.getValue()); | 
|---|
|  |  |  | mallProductBuy.setPayTime(DateUtil.date()); | 
|---|
|  |  |  | mallProductBuyMapper.updateById(mallProductBuy); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | MallMemberAmount mallMemberAmount = mallMemberAmountMapper.selectByMemberId(mallProductBuy.getMemberId()); | 
|---|
|  |  |  | mallMemberAmount.setTotalPerk(mallMemberAmount.getTotalPerk().add(totalPerk)); | 
|---|
|  |  |  | mallMemberAmountMapper.updateTotalPerkById(mallMemberAmount); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 更新用户上级收益,冻结7天,7天时间到期自动释放到动态钱包 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | Long memberId = mallProductBuy.getMemberId(); | 
|---|
|  |  |  | MallMember mallMember = mallMemberMapper.selectById(memberId); | 
|---|
|  |  |  | if(ObjectUtil.isNotEmpty(mallMember)){ | 
|---|
|  |  |  | //直推 | 
|---|
|  |  |  | String referrerId = mallMember.getReferrerId(); | 
|---|
|  |  |  | MallMember directMember = mallMemberMapper.selectInfoByInviteId(referrerId); | 
|---|
|  |  |  | if(ObjectUtil.isNotEmpty(directMember)){ | 
|---|
|  |  |  | BigDecimal basicPerkDirectPercent = new BigDecimal(dataDictionaryCustomMapper.selectDicDataByTypeAndCode( | 
|---|
|  |  |  | DataDictionaryEnum.BASIC_PERK_DIRECT.getType(), | 
|---|
|  |  |  | DataDictionaryEnum.BASIC_PERK_DIRECT.getCode() | 
|---|
|  |  |  | ).getValue()).multiply(new BigDecimal("0.01")); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | BigDecimal nftTotal = mallProductBuy.getNftTotal(); | 
|---|
|  |  |  | BigDecimal basicPerkDirect = nftTotal.multiply(basicPerkDirectPercent).setScale(2, BigDecimal.ROUND_DOWN); | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 如果用户是冻结,则直接销毁 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | Integer isFrozen = directMember.getIsFrozen(); | 
|---|
|  |  |  | if(ProductEnum.MEMBER_FROZEN.getValue() == isFrozen){ | 
|---|
|  |  |  |  | 
|---|
|  |  |  | MallMemberAmount mallMemberAmountMine = mallMemberAmountMapper.selectByMemberId(directMember.getId()); | 
|---|
|  |  |  | if(BigDecimal.ZERO.compareTo(mallMemberAmountMine.getTotalPerk().subtract(basicPerkDirect)) >= 0){ | 
|---|
|  |  |  | return; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | mallMemberAmountMine.setTotalPerk(mallMemberAmountMine.getTotalPerk().subtract(basicPerkDirect)); | 
|---|
|  |  |  | mallMemberAmountMapper.updateTrendsNftAndFrozenNftById(mallMemberAmountMine); | 
|---|
|  |  |  | //插入一条流水记录 | 
|---|
|  |  |  | String orderNo = MallUtils.getOrderNum("FNFTW"); | 
|---|
|  |  |  | mallMoneyFlowService.addMoneyFlow( | 
|---|
|  |  |  | memberId, | 
|---|
|  |  |  | basicPerkDirect.negate(), | 
|---|
|  |  |  | MoneyFlowTypeNewEnum.BASIC_PERK_DIRECT_WRONG.getValue(), | 
|---|
|  |  |  | orderNo, | 
|---|
|  |  |  | null, | 
|---|
|  |  |  | FlowTypeNewEnum.NFT.getValue(), | 
|---|
|  |  |  | MoneyFlowTypeNewEnum.BASIC_PERK_DIRECT_WRONG.getDescrition(), | 
|---|
|  |  |  | AppContants.MEMBER_FLOW_ING); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | }else { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | MallMemberAmount mallMemberAmountMine = mallMemberAmountMapper.selectByMemberId(directMember.getId()); | 
|---|
|  |  |  | if(BigDecimal.ZERO.compareTo(mallMemberAmountMine.getTotalPerk().subtract(basicPerkDirect)) >= 0){ | 
|---|
|  |  |  | return; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | mallMemberAmountMine.setTotalPerk(mallMemberAmountMine.getTotalPerk().subtract(basicPerkDirect)); | 
|---|
|  |  |  | mallMemberAmountMapper.updateTrendsNftAndFrozenNftById(mallMemberAmountMine); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | MallMemberAmount mallMemberAmountNft = mallMemberAmountMapper.selectByMemberId(directMember.getId()); | 
|---|
|  |  |  | mallMemberAmountNft.setTrendsNft(mallMemberAmountNft.getTrendsNft().add(basicPerkDirect)); | 
|---|
|  |  |  | mallMemberAmountMapper.updateTrendsNftById(mallMemberAmountNft); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //插入一条流水记录 | 
|---|
|  |  |  | String orderNo = MallUtils.getOrderNum("NFT"); | 
|---|
|  |  |  | mallMoneyFlowService.addMoneyFlow( | 
|---|
|  |  |  | memberId, | 
|---|
|  |  |  | basicPerkDirect, | 
|---|
|  |  |  | MoneyFlowTypeNewEnum.BASIC_PERK_DIRECT_DONE.getValue(), | 
|---|
|  |  |  | orderNo, | 
|---|
|  |  |  | null, | 
|---|
|  |  |  | FlowTypeNewEnum.NFT.getValue(), | 
|---|
|  |  |  | MoneyFlowTypeNewEnum.BASIC_PERK_DIRECT_DONE.getDescrition(), | 
|---|
|  |  |  | AppContants.MEMBER_FLOW_DONE); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public void fcmOrderBuyCancelMsg(Long buyRecordId) { | 
|---|
|  |  |  | MallProductBuyRecord mallProductBuyRecord = mallProductBuyRecordMapper.selectById(buyRecordId); | 
|---|
|  |  |  | if(ProductEnum.PRODUCT_MATE_STATE_WAIT_PAY.getValue() != mallProductBuyRecord.getState()){ | 
|---|
|  |  |  | return; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | Long sellRecordId = mallProductBuyRecord.getSellRecordId(); | 
|---|
|  |  |  | //更新买单子表的数据 | 
|---|
|  |  |  | mallProductBuyRecord.setState(ProductEnum.PRODUCT_MATE_STATE_FAIL.getValue()); | 
|---|
|  |  |  | mallProductBuyRecordMapper.updateById(mallProductBuyRecord); | 
|---|
|  |  |  | //更新买单主表 | 
|---|
|  |  |  | MallProductBuy mallProductBuy = mallProductBuyMapper.selectById(mallProductBuyRecord.getBuyId()); | 
|---|
|  |  |  | mallProductBuy.setNftAva(mallProductBuy.getNftAva().add(mallProductBuyRecord.getPickNftCnt())); | 
|---|
|  |  |  | mallProductBuyMapper.updateById(mallProductBuy); | 
|---|
|  |  |  | Long memberId = mallProductBuy.getMemberId(); | 
|---|
|  |  |  | MallMember mallMember = mallMemberMapper.selectById(memberId); | 
|---|
|  |  |  | mallMember.setIsFrozen(ProductEnum.MEMBER_FROZEN.getValue()); | 
|---|
|  |  |  | mallMemberMapper.updateById(mallMember); | 
|---|
|  |  |  | //更新卖单子表的数据 | 
|---|
|  |  |  | MallProductSellRecord mallProductSellRecord = mallProductSellRecordMapper.selectById(sellRecordId); | 
|---|
|  |  |  | mallProductSellRecord.setState(ProductEnum.PRODUCT_MATE_STATE_FAIL.getValue()); | 
|---|
|  |  |  | mallProductSellRecordMapper.updateById(mallProductSellRecord); | 
|---|
|  |  |  | //更新卖单主表 | 
|---|
|  |  |  | Long sellId = mallProductSellRecord.getSellId(); | 
|---|
|  |  |  | MallProductSell mallProductSell = mallProductSellMapper.selectById(sellId); | 
|---|
|  |  |  | mallProductSell.setNftCntAva(mallProductSell.getNftCntAva().add(mallProductSellRecord.getNftCnt())); | 
|---|
|  |  |  | mallProductSellMapper.updateById(mallProductSell); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public static void main(String[] args) { | 
|---|
|  |  |  | BigDecimal divide = new BigDecimal(12000).divide(new BigDecimal(10000), 0, BigDecimal.ROUND_DOWN); | 
|---|
|  |  |  | System.out.println(divide); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 给用户的增加凭证数据,并且增加流水 | 
|---|
|  |  |  | * @param memberAchieveRelease 释放数量 | 
|---|
|  |  |  | * @param memberId 用户ID | 
|---|
|  |  |  | * @param Type 流水类型 | 
|---|
|  |  |  | * @param flowNo 流水编号 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | private void releaseToMemberAndAddFlow(BigDecimal memberAchieveRelease,Long memberId,int Type,String flowNo){ | 
|---|
|  |  |  | //释放到用户的账户 | 
|---|
|  |  |  | mallMemberWalletMapper.addVorCherCntByMemberId(memberAchieveRelease,memberId); | 
|---|
|  |  |  | //产生一条流水记录 TODO 需要去掉注释 | 
|---|
|  |  |  | mallMoneyFlowService.addMoneyFlow( | 
|---|
|  |  |  | memberId, | 
|---|
|  |  |  | memberAchieveRelease, | 
|---|
|  |  |  | Type, | 
|---|
|  |  |  | flowNo, | 
|---|
|  |  |  | FlowTypeEnum.VOUCHER_CNT.getValue()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | *  根据星级等级和占比,给该星级的用户释放凭证 | 
|---|
|  |  |  | * @param levelAchieveRelease | 
|---|
|  |  |  | * @param level | 
|---|
|  |  |  | * @param percent | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | private BigDecimal releaseByLevel(BigDecimal levelAchieveRelease,String level,BigDecimal percent,String scoreNo){ | 
|---|
|  |  |  | //实际支付的凭证数量 | 
|---|
|  |  |  | BigDecimal levelReleaseReal = BigDecimal.ZERO; | 
|---|
|  |  |  | //当前星级的人数 | 
|---|
|  |  |  | List<MallMember> levelMembers = mallMemberMapper.selectMemberWithLevel(level); | 
|---|
|  |  |  | if(CollUtil.isNotEmpty(levelMembers)){ | 
|---|
|  |  |  | //这个星级该获得的凭证数量 = 总数 * 比例 | 
|---|
|  |  |  | BigDecimal levelReleaseCnt = levelAchieveRelease.multiply(percent).setScale(2, BigDecimal.ROUND_DOWN); | 
|---|
|  |  |  | if(levelReleaseCnt.compareTo(BigDecimal.ZERO) > 0){ | 
|---|
|  |  |  | //每个人获得的数量 | 
|---|
|  |  |  | BigDecimal levelRelease = levelReleaseCnt.divide(new BigDecimal(levelMembers.size()), 2, BigDecimal.ROUND_DOWN); | 
|---|
|  |  |  | if(levelRelease.compareTo(BigDecimal.ZERO) > 0){ | 
|---|
|  |  |  | for(MallMember mallMember : levelMembers){ | 
|---|
|  |  |  | releaseToMemberAndAddFlow(levelRelease,mallMember.getId(),MoneyFlowTypeEnum.ACHIEVE_RELEASE_SCORE_XJ.getValue(),scoreNo); | 
|---|
|  |  |  | levelReleaseReal.add(levelRelease); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return levelReleaseReal; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 获取每日最大产生的凭证数量 | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | private BigDecimal getAchieveDailyRelease(){ | 
|---|
|  |  |  | DataDictionaryCustom achieveReleasePercentDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode( | 
|---|
|  |  |  | GreenScoreEnum.ACHIEVE_RELEASE_PERCENT.getType(), | 
|---|
|  |  |  | GreenScoreEnum.ACHIEVE_RELEASE_PERCENT.getCode() | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | BigDecimal achieveReleasePercent = new BigDecimal(achieveReleasePercentDic.getValue() == null ? "0" : achieveReleasePercentDic.getValue()) | 
|---|
|  |  |  | .multiply(new BigDecimal(0.0001)); | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | DataDictionaryCustom totalCntDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode( | 
|---|
|  |  |  | GreenScoreEnum.TOTAL_CNT.getType(), | 
|---|
|  |  |  | GreenScoreEnum.TOTAL_CNT.getCode() | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | //总凭证数量 | 
|---|
|  |  |  | BigDecimal totalCnt = new BigDecimal(totalCntDic.getValue() == null ? "0" : totalCntDic.getValue()).multiply(new BigDecimal(0.9)); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //获取每日最大产生的凭证数量 | 
|---|
|  |  |  | BigDecimal achieveRelease = totalCnt.multiply(achieveReleasePercent); | 
|---|
|  |  |  | return achieveRelease; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|