| | |
| | |
|
| | | @Transactional(rollbackFor = Exception.class)
|
| | | public void addDividentsSourceOrder(List<CommonOrder> commonOrderList) throws TeamDividentsSourceOrderException {
|
| | | if (commonOrderList.get(0).getThirdCreateTime().getTime() < Constant.NEW_ORDER_FANLI_RULE_TIME)
|
| | | return;
|
| | |
|
| | | UserLevelEnum level = UserLevelUtil.getByOrderRank(commonOrderList.get(0).getUrank());
|
| | | if (level == null)
|
| | | level = UserLevelEnum.daRen;
|
| | | BigDecimal rate = getSourceOrderDividentsRate(level);
|
| | | TeamDividentsSourceOrder order = TeamDividentsSourceOrderFactory.create(commonOrderList, rate);
|
| | | if (order == null)
|
| | | return;
|
| | | try {
|
| | | teamDividentsSourceOrderService.addTeamDividentsSourceOrder(order);
|
| | | } catch (TeamDividentsSourceOrderException e) {
|
| | | e.printStackTrace();
|
| | | } catch (ParamsException e) {
|
| | | e.printStackTrace();
|
| | | throw new TeamDividentsSourceOrderException(101, "参数不完整");
|
| | | }
|
| | | }
|
| | |
|
| | |
| | |
|
| | | // 是否可以分红
|
| | | private boolean isCanDividents(TeamUserLevelStatistic tus) {
|
| | | if (Constant.IS_TEST)
|
| | | return true;
|
| | | // if (Constant.IS_TEST && tus.getLevel() != UserLevelEnum.daRen && tus.getLevel() != UserLevelEnum.normalVIP)
|
| | | // return true;
|
| | |
|
| | | if (tus != null && (tus.getLevel() == UserLevelEnum.highVIP || tus.getLevel() == UserLevelEnum.superVIP
|
| | | || tus.getLevel() == UserLevelEnum.tearcher)) {
|
| | | if (tus.getLevel() == UserLevelEnum.highVIP) {
|
| | | int vipFirstCount = tus.getNormalFirstCount() + tus.getHighFirstCount() + tus.getSuperFirstCount()
|
| | | + tus.getTearcherFirstCount();
|
| | | if (vipFirstCount >= 3)// 直接粉丝普通会员等级以上的用户>=3
|
| | |
|
| | | if (tus.getLevel() == UserLevelEnum.tearcher) {
|
| | | int firstCount = tus.getSuperFirstCount() + tus.getTearcherFirstCount();
|
| | | int secondCount = tus.getHighSecondCount() + tus.getSuperSecondCount() + tus.getTearcherSecondCount();
|
| | | if (firstCount >= 3 && secondCount >= 3) {// 直接粉丝超级会员等级以上的用户>=3
|
| | | // 间接粉丝普通会员以上等级>=3
|
| | | return true;
|
| | | } else if (tus.getLevel() == UserLevelEnum.superVIP) {
|
| | | } else {
|
| | | // 如果导师不满足条件就需要降级为超级会员
|
| | | tus.setLevel(UserLevelEnum.superVIP);
|
| | | }
|
| | | }
|
| | |
|
| | | if (tus.getLevel() == UserLevelEnum.superVIP) {
|
| | | int firstCount = tus.getSuperFirstCount() + tus.getTearcherFirstCount();
|
| | | int secondCount = tus.getNormalSecondCount() + tus.getHighSecondCount() + tus.getSuperSecondCount()
|
| | | + tus.getTearcherSecondCount();
|
| | | if (firstCount >= 3 && secondCount >= 3) {// 直接粉丝超级会员等级以上的用户>=3
|
| | | // 间接粉丝普通会员以上等级>=3
|
| | | return true;
|
| | | } else {
|
| | | // 如果超级会员不满足条件就需要降级为高级会员
|
| | | tus.setLevel(UserLevelEnum.highVIP);
|
| | | }
|
| | | } else {
|
| | | int firstCount = tus.getSuperFirstCount() + tus.getTearcherFirstCount();
|
| | | int secondCount = tus.getHighSecondCount() + tus.getSuperSecondCount() + tus.getTearcherSecondCount();
|
| | | if (firstCount >= 3 && secondCount >= 3) {// 直接粉丝超级会员等级以上的用户>=3
|
| | | // 间接粉丝高级会员以上等级>=3
|
| | | }
|
| | |
|
| | | if (tus.getLevel() == UserLevelEnum.highVIP) {
|
| | | int vipFirstCount = tus.getNormalFirstCount() + tus.getHighFirstCount() + tus.getSuperFirstCount()
|
| | | + tus.getTearcherFirstCount();
|
| | | if (vipFirstCount >= 3)// 直接粉丝普通会员等级以上的用户>=3
|
| | | return true;
|
| | | }
|
| | | }
|
| | | }
|
| | | return false;
|
| | |
| | | if (threeSalesList == null)
|
| | | return;
|
| | |
|
| | | Map<Long, UserLevelEnum> uidLevel = new HashMap<Long, UserLevelEnum>();
|
| | | Map<Long, UserLevelEnum> uidLevelMap = new HashMap<Long, UserLevelEnum>();
|
| | | for (ThreeSale ts : threeSalesList) {
|
| | | if (ts.getBoss() != null) {
|
| | | TeamUserLevelStatistic tus = teamUserLevelStatisticService.selectByUid(ts.getBoss().getId());
|
| | |
| | | tus = teamUserLevelStatisticService.selectByUid(ts.getBoss().getId());
|
| | |
|
| | | if (isCanDividents(tus)) {
|
| | | uidLevel.put(tus.getId(), tus.getLevel());
|
| | | uidLevelMap.put(tus.getId(), tus.getLevel());
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | BigDecimal perDivident = computePerDivident(uidLevel, totalMoney);
|
| | | for (Iterator<Long> its = uidLevel.keySet().iterator(); its.hasNext();) {
|
| | | // 没有参与分红的用户
|
| | | if (uidLevelMap == null || uidLevelMap.size() == 0) {
|
| | | return;
|
| | | }
|
| | |
|
| | | BigDecimal perDivident = computePerDivident(uidLevelMap, totalMoney);
|
| | | for (Iterator<Long> its = uidLevelMap.keySet().iterator(); its.hasNext();) {
|
| | | Long uid = its.next();
|
| | | BigDecimal dividents = computeUserDivident(perDivident, uidLevel.get(uid));
|
| | | BigDecimal dividents = computeUserDivident(perDivident, uidLevelMap.get(uid));
|
| | | // 将资金分配到参与分红的用户
|
| | | TeamDividentsSourceUser teamDividentsSourceUser = new TeamDividentsSourceUser();
|
| | | teamDividentsSourceUser.setDay(day);
|
| | |
| | | teamDividentsSourceUser.setTargetUid(uid);
|
| | | teamDividentsSourceUserService.addTeamDividentsSourceUser(teamDividentsSourceUser);
|
| | | }
|
| | | // if (1 / 0 > 0)
|
| | | // return;
|
| | | }
|
| | |
|
| | | // 计算平均分红
|
| | | private BigDecimal computePerDivident(Map<Long, UserLevelEnum> uidLevels, BigDecimal totalMoney) {
|
| | | int count = 0;
|
| | | BigDecimal count = new BigDecimal(0);
|
| | | for (Iterator<Long> its = uidLevels.keySet().iterator(); its.hasNext();) {
|
| | | Long uid = its.next();
|
| | | if (uidLevels.get(uid) == UserLevelEnum.highVIP) {
|
| | | count += 1;
|
| | | count = count.add(new BigDecimal(1));
|
| | | } else if (uidLevels.get(uid) == UserLevelEnum.superVIP) {
|
| | | count += 2;
|
| | | count = count.add(new BigDecimal(2));
|
| | | } else if (uidLevels.get(uid) == UserLevelEnum.tearcher) {
|
| | | count = count.add(new BigDecimal(2.5));
|
| | | }
|
| | | }
|
| | | return MoneyBigDecimalUtil.div(totalMoney, new BigDecimal(count));
|
| | | return MoneyBigDecimalUtil.div(totalMoney, count);
|
| | | }
|
| | |
|
| | | private BigDecimal computeUserDivident(BigDecimal perDivident, UserLevelEnum userLevel) {
|
| | |
| | | } else if (userLevel == UserLevelEnum.superVIP) {
|
| | | return MoneyBigDecimalUtil.mul(perDivident, new BigDecimal(2));
|
| | | } else if (userLevel == UserLevelEnum.tearcher) {
|
| | | return MoneyBigDecimalUtil.mul(perDivident, new BigDecimal(2));
|
| | | return MoneyBigDecimalUtil.mul(perDivident, new BigDecimal(2.5));
|
| | | }
|
| | | return null;
|
| | | }
|
| | |
| | | * @throws
|
| | | */
|
| | | @Transactional(rollbackFor = Exception.class)
|
| | | public void addToTeamEincome(Long uid, String day) throws TeamDividentsRecordException, TeamDividentsDebtException,
|
| | | UserMoneyDetailException, ParamsException, TeamEincomeRecordException {
|
| | | Date preSendTime = new Date(TimeUtil.convertToTimeTemp(day, "yyyy-MM-dd"));
|
| | | public void addToTeamEincome(Long uid, Date preSendTime) throws TeamDividentsRecordException,
|
| | | TeamDividentsDebtException, UserMoneyDetailException, ParamsException, TeamEincomeRecordException {
|
| | | String day = TimeUtil.getGernalTime(preSendTime.getTime(), "yyyy-MM-dd");
|
| | | BigDecimal money = teamDividentsSourceUserService.sumMoneyByUidAndDay(uid, day);
|
| | | // 查询需要扣除的资金
|
| | | List<TeamDividentsDebt> list = teamDividentsDebtService.listNeedRepayDebt(uid, preSendTime, 1, 1000);
|
| | |
| | |
|
| | | // 有分红才显示资金明细
|
| | | if (money.compareTo(new BigDecimal(0)) > 0) {
|
| | |
|
| | | teamEincomeManager.addTeamDividents(uid, preSendTime, money);
|
| | | }
|
| | | }
|
| | |
| | | } else if (sourceOrder.getState() == TeamDividentsSourceOrder.STATE_CAN_SEND) {
|
| | | teamDividentsSourceOrderService.invalidOrder(orderNo, sourceType, "订单维权");
|
| | | }
|
| | |
|
| | | }
|
| | |
|
| | | /**
|