| | |
| | | import com.baomidou.mybatisplus.extension.service.IService; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.util.Map; |
| | | |
| | | public interface IApiMallMemberWalletService extends IService<MallMemberWallet> { |
| | | |
| | |
| | | |
| | | int reduce(BigDecimal amount, Long memberId, String field); |
| | | |
| | | int reduce(BigDecimal amount, Long memberId, String field, Map<String, BigDecimal> map); |
| | | |
| | | void commissionChange(CommissionChangeDto commissionChange); |
| | | } |
| | |
| | | |
| | | import java.lang.reflect.Field; |
| | | import java.math.BigDecimal; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * @author wzy |
| | |
| | | } |
| | | |
| | | @Override |
| | | public int reduce(BigDecimal amount, Long memberId, String field) { |
| | | public int reduce(BigDecimal amount, Long memberId, String field, Map<String, BigDecimal> map) { |
| | | int i = 0; |
| | | boolean flag = true; |
| | | |
| | |
| | | BigDecimal balance = (BigDecimal) declaredField.get(wallet); |
| | | |
| | | if (amount.compareTo(balance) > 0) { |
| | | // 判断 赠送积分,如果剩下赠送积分不等于0且小于amount, 则扣除所有赠送积分 |
| | | if ("score".equals(field)) { |
| | | if (balance.compareTo(BigDecimal.ZERO) == 0) { |
| | | return 2; |
| | | } |
| | | |
| | | amount = balance; |
| | | map.put("amount", amount); |
| | | } else { |
| | | return 2; |
| | | } |
| | | } |
| | | declaredField.set(update, balance.subtract(amount)); |
| | | |
| | |
| | | } |
| | | |
| | | @Override |
| | | public int reduce(BigDecimal amount, Long memberId, String field) { |
| | | return reduce(amount, memberId, field); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void commissionChange(CommissionChangeDto commissionChange) { |
| | | MallMember member = LoginUserUtil.getLoginUser(); |
| | |
| | | Long memberId = (Long) item.get("memberId"); |
| | | String orderNo = (String) item.get("orderNo"); |
| | | |
| | | int reduce = walletService.reduce(preStaticProfit, memberId, "score"); |
| | | if (reduce == 2) { |
| | | break; |
| | | } |
| | | |
| | | walletService.add(preStaticProfit, memberId, "commission"); |
| | | moneyFlowService.addMoneyFlow(memberId, preStaticProfit, MoneyFlowTypeEnum.STATIC_BONUS.getValue(), orderNo, FlowTypeEnum.COMMISSION.getValue()); |
| | | moneyFlowService.addMoneyFlow(memberId, preStaticProfit.negate(), MoneyFlowTypeEnum.STATIC_BONUS.getValue(), orderNo, FlowTypeEnum.SCORE.getValue()); |
| | | // int reduce = walletService.reduce(preStaticProfit, memberId, "score"); |
| | | // if (reduce == 2) { |
| | | // break; |
| | | // } |
| | | // |
| | | // walletService.add(preStaticProfit, memberId, "commission"); |
| | | // moneyFlowService.addMoneyFlow(memberId, preStaticProfit, MoneyFlowTypeEnum.STATIC_BONUS.getValue(), orderNo, FlowTypeEnum.COMMISSION.getValue()); |
| | | // moneyFlowService.addMoneyFlow(memberId, preStaticProfit.negate(), MoneyFlowTypeEnum.STATIC_BONUS.getValue(), orderNo, FlowTypeEnum.SCORE.getValue()); |
| | | changeScoreAndCommission(memberId, preStaticProfit, MoneyFlowTypeEnum.STATIC_BONUS.getValue(), orderNo); |
| | | } |
| | | } |
| | | } |
| | |
| | | continue; |
| | | } |
| | | |
| | | int reduce = walletService.reduce(dynamicProfit, parent.getId(), "score"); |
| | | if (reduce == 2) { |
| | | // int reduce = walletService.reduce(dynamicProfit, parent.getId(), "score"); |
| | | // if (reduce == 2) { |
| | | // continue; |
| | | // } |
| | | // walletService.add(dynamicProfit, parent.getId(), "commission"); |
| | | // moneyFlowService.addMoneyFlow(parent.getId(), dynamicProfit, MoneyFlowTypeEnum.DYNAMIC_ACHIEVE.getValue(), orderInfo.getOrderNo(), FlowTypeEnum.COMMISSION.getValue()); |
| | | // moneyFlowService.addMoneyFlow(parent.getId(), dynamicProfit.negate(), MoneyFlowTypeEnum.DYNAMIC_ACHIEVE.getValue(), orderInfo.getOrderNo(), FlowTypeEnum.SCORE.getValue()); |
| | | |
| | | dynamicProfit = changeScoreAndCommission(parent.getId(), dynamicProfit, MoneyFlowTypeEnum.DYNAMIC_ACHIEVE.getValue(), orderInfo.getOrderNo()); |
| | | if (dynamicProfit.compareTo(BigDecimal.ZERO) < 1) { |
| | | continue; |
| | | } |
| | | |
| | | walletService.add(dynamicProfit, parent.getId(), "commission"); |
| | | |
| | | moneyFlowService.addMoneyFlow(parent.getId(), dynamicProfit, MoneyFlowTypeEnum.DYNAMIC_ACHIEVE.getValue(), orderInfo.getOrderNo(), FlowTypeEnum.COMMISSION.getValue()); |
| | | moneyFlowService.addMoneyFlow(parent.getId(), dynamicProfit.negate(), MoneyFlowTypeEnum.DYNAMIC_ACHIEVE.getValue(), orderInfo.getOrderNo(), FlowTypeEnum.SCORE.getValue()); |
| | | // =======直推返利== end ===== |
| | | |
| | | // =======隔代奖== start ===== |
| | |
| | | if (direct.compareTo(BigDecimal.ONE) < 1) { |
| | | break; |
| | | } |
| | | |
| | | int reduceResult = walletService.reduce(direct, parentMember.getId(), "score"); |
| | | if (reduceResult == 2) { |
| | | continue; |
| | | } |
| | | |
| | | walletService.add(direct, parentMember.getId(), "commission"); |
| | | moneyFlowService.addMoneyFlow(parentMember.getId(), direct, MoneyFlowTypeEnum.RECOMMEND_BONUS.getValue(), orderInfo.getOrderNo(), FlowTypeEnum.COMMISSION.getValue()); |
| | | moneyFlowService.addMoneyFlow(parentMember.getId(), direct.negate(), MoneyFlowTypeEnum.RECOMMEND_BONUS.getValue(), orderInfo.getOrderNo(), FlowTypeEnum.SCORE.getValue()); |
| | | // int reduceResult = walletService.reduce(direct, parentMember.getId(), "score"); |
| | | // if (reduceResult == 2) { |
| | | // continue; |
| | | // } |
| | | // |
| | | // walletService.add(direct, parentMember.getId(), "commission"); |
| | | // moneyFlowService.addMoneyFlow(parentMember.getId(), direct, MoneyFlowTypeEnum.RECOMMEND_BONUS.getValue(), orderInfo.getOrderNo(), FlowTypeEnum.COMMISSION.getValue()); |
| | | // moneyFlowService.addMoneyFlow(parentMember.getId(), direct.negate(), MoneyFlowTypeEnum.RECOMMEND_BONUS.getValue(), orderInfo.getOrderNo(), FlowTypeEnum.SCORE.getValue()); |
| | | changeScoreAndCommission(parentMember.getId(), direct, MoneyFlowTypeEnum.RECOMMEND_BONUS.getValue(), orderInfo.getOrderNo()); |
| | | } |
| | | // =======隔代奖== end ===== |
| | | } |
| | |
| | | BigDecimal income = profit.multiply(profitProp).divide(BigDecimal.valueOf(agentMemberList.size()), 2, RoundingMode.HALF_UP); |
| | | |
| | | 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()); |
| | | // 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; |
| | | } |
| | | |
| | | 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 |
| | |
| | | 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); |
| | | } |
| | | } |
| | | |
| | |
| | | if (reduce == 2) { |
| | | continue; |
| | | } |
| | | |
| | | moneyFlowService.addMoneyFlow(mallMember.getId(), reduceProfit.negate(), MoneyFlowTypeEnum.THANKFUL.getValue(), null, FlowTypeEnum.COMMISSION.getValue()); |
| | | |
| | | for (MallMember child : children) { |
| | | BigDecimal preProfit = income.multiply(prop).divide(BigDecimal.valueOf(children.size()), 2, RoundingMode.HALF_DOWN); |
| | | if (preProfit.compareTo(BigDecimal.ZERO) < 1) { |
| | | continue; |
| | | } |
| | | |
| | | int reduce1 = walletService.reduce(preProfit, child.getId(), "score"); |
| | | if (reduce1 == 2) { |
| | | continue; |
| | | } |
| | | |
| | | walletService.add(preProfit, child.getId(), "commission"); |
| | | moneyFlowService.addMoneyFlow(child.getId(), preProfit, MoneyFlowTypeEnum.THANKFUL.getValue(), null, mallMember.getId(), FlowTypeEnum.COMMISSION.getValue()); |
| | | moneyFlowService.addMoneyFlow(child.getId(), preProfit.negate(), MoneyFlowTypeEnum.THANKFUL.getValue(), null, mallMember.getId(), FlowTypeEnum.SCORE.getValue()); |
| | | // int reduce1 = walletService.reduce(preProfit, child.getId(), "score"); |
| | | // if (reduce1 == 2) { |
| | | // continue; |
| | | // } |
| | | // walletService.add(preProfit, child.getId(), "commission"); |
| | | // moneyFlowService.addMoneyFlow(child.getId(), preProfit, MoneyFlowTypeEnum.THANKFUL.getValue(), null, mallMember.getId(), FlowTypeEnum.COMMISSION.getValue()); |
| | | // moneyFlowService.addMoneyFlow(child.getId(), preProfit.negate(), MoneyFlowTypeEnum.THANKFUL.getValue(), null, mallMember.getId(), FlowTypeEnum.SCORE.getValue()); |
| | | changeScoreAndCommission(child.getId(), preProfit, MoneyFlowTypeEnum.THANKFUL.getValue(), null); |
| | | } |
| | | } |
| | | log.info("######==感恩奖==end==####"); |
| | |
| | | continue; |
| | | } |
| | | |
| | | int reduce = walletService.reduce(pre, director.getId(), "score"); |
| | | if (reduce == 2) { |
| | | continue; |
| | | } |
| | | |
| | | walletService.add(pre, director.getId(), "commission"); |
| | | moneyFlowService.addMoneyFlow(director.getId(), pre, MoneyFlowTypeEnum.DIRECTOR_BONUS.getValue(), null, FlowTypeEnum.COMMISSION.getValue()); |
| | | moneyFlowService.addMoneyFlow(director.getId(), pre.negate(), MoneyFlowTypeEnum.DIRECTOR_BONUS.getValue(), null, FlowTypeEnum.SCORE.getValue()); |
| | | // int reduce = walletService.reduce(pre, director.getId(), "score"); |
| | | // if (reduce == 2) { |
| | | // continue; |
| | | // } |
| | | // walletService.add(pre, director.getId(), "commission"); |
| | | // moneyFlowService.addMoneyFlow(director.getId(), pre, MoneyFlowTypeEnum.DIRECTOR_BONUS.getValue(), null, FlowTypeEnum.COMMISSION.getValue()); |
| | | // moneyFlowService.addMoneyFlow(director.getId(), pre.negate(), MoneyFlowTypeEnum.DIRECTOR_BONUS.getValue(), null, FlowTypeEnum.SCORE.getValue()); |
| | | changeScoreAndCommission(director.getId(), pre, MoneyFlowTypeEnum.DIRECTOR_BONUS.getValue(), null); |
| | | } |
| | | } |
| | | |
| | |
| | | continue; |
| | | } |
| | | |
| | | int reduce = walletService.reduce(pre, storeMaster.getId(), "score"); |
| | | if (reduce == 2) { |
| | | continue; |
| | | } |
| | | |
| | | walletService.add(pre, storeMaster.getId(), "commission"); |
| | | moneyFlowService.addMoneyFlow(storeMaster.getId(), pre, MoneyFlowTypeEnum.COMMUNITY_BONUS.getValue(), null, FlowTypeEnum.COMMISSION.getValue()); |
| | | moneyFlowService.addMoneyFlow(storeMaster.getId(), pre.negate(), MoneyFlowTypeEnum.COMMUNITY_BONUS.getValue(), null, FlowTypeEnum.SCORE.getValue()); |
| | | // int reduce = walletService.reduce(pre, storeMaster.getId(), "score"); |
| | | // if (reduce == 2) { |
| | | // continue; |
| | | // } |
| | | // walletService.add(pre, storeMaster.getId(), "commission"); |
| | | // moneyFlowService.addMoneyFlow(storeMaster.getId(), pre, MoneyFlowTypeEnum.COMMUNITY_BONUS.getValue(), null, FlowTypeEnum.COMMISSION.getValue()); |
| | | // moneyFlowService.addMoneyFlow(storeMaster.getId(), pre.negate(), MoneyFlowTypeEnum.COMMUNITY_BONUS.getValue(), null, FlowTypeEnum.SCORE.getValue()); |
| | | changeScoreAndCommission(storeMaster.getId(), pre, MoneyFlowTypeEnum.COMMUNITY_BONUS.getValue(), null); |
| | | } |
| | | } |
| | | |
| | | log.info("#####==店补/董事==end==######"); |
| | | } |
| | | } |
| | |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.util.Date; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * @author wzy |
| | |
| | | mallAchieveService.add(item.getId()); |
| | | } |
| | | } |
| | | |
| | | @Test |
| | | public void paramTest() { |
| | | Map<String, Integer> map = new HashMap<>(); |
| | | BigDecimal amount = new BigDecimal("100"); |
| | | map.put("amount", 1); |
| | | changeAmount(map); |
| | | System.out.println(map.get("amount")); |
| | | } |
| | | |
| | | public void changeAmount(Map<String, Integer> amount) { |
| | | amount.put("amount", 2); |
| | | } |
| | | } |