| | |
| | | if (CollUtil.isNotEmpty(orders)) { |
| | | for (YdOrderEntity order : orders) { |
| | | if ("P".equals(order.getYdProductEntity().getProUnit())) { |
| | | totalPower = totalPower.add(BigDecimal.valueOf(order.getQuantity() * 1024)); |
| | | totalPower = totalPower.add(BigDecimal.valueOf(order.getQuantity() * order.getYdProductEntity().getProNum() * 1024)); |
| | | } else { |
| | | totalPower = totalPower.add(BigDecimal.valueOf(order.getQuantity())); |
| | | totalPower = totalPower.add(BigDecimal.valueOf(order.getQuantity() * order.getYdProductEntity().getProNum())); |
| | | } |
| | | } |
| | | } |
| | | |
| | | BigDecimal needPower = basicLevelSetting.getCalculationPower().multiply(BigDecimal.valueOf(1024)); |
| | | return totalPower.compareTo(needPower) > 0; |
| | | BigDecimal needPower = BigDecimal.ZERO; |
| | | if ("P".equals(basicLevelSetting.getUnit())) { |
| | | needPower = basicLevelSetting.getCalculationPower().multiply(BigDecimal.valueOf(1024)); |
| | | } else { |
| | | needPower = basicLevelSetting.getCalculationPower(); |
| | | } |
| | | return totalPower.compareTo(needPower) >= 0; |
| | | } |
| | | |
| | | /** |
| | |
| | | List<String> inviteIds = StrUtil.split(memberEntity.getRefererIds(), ','); |
| | | List<MemberEntity> agents = memberDao.selectYdParentAgent(inviteIds); |
| | | |
| | | if (CollUtil.isNotEmpty(agents)) { |
| | | Map<Long, BigDecimal> returnRatio = buildReturnRatioObj(agents, 1); |
| | | |
| | | for (Map.Entry<Long, BigDecimal> entry : returnRatio.entrySet()) { |
| | | String conent = "USDT返利"; |
| | | BigDecimal amount = order.getAmount().multiply(entry.getValue()); |
| | | LogRecordUtils.insertMemberAccountMoneyChangeWithId(entry.getKey(), conent, amount, "USDT", 1, 6, order.getId()); |
| | | MemberWalletCoinEntity walletCoin = memberWalletCoinDao.selectWalletCoinBymIdAndCode(entry.getKey(), "USDT"); |
| | | |
| | | memberWalletCoinDao.updateBlockBalance(walletCoin.getId(), amount, BigDecimal.ZERO, 0); |
| | | } |
| | | |
| | | YdOrderEntity updateOrder = new YdOrderEntity(); |
| | | updateOrder.setReturnState(2); |
| | | updateOrder.setId(order.getId()); |
| | | ydOrderDao.updateById(updateOrder); |
| | | } |
| | | // if (CollUtil.isNotEmpty(agents)) { |
| | | // Map<Long, BigDecimal> returnRatio = buildReturnRatioObj(agents, 1); |
| | | // |
| | | // for (Map.Entry<Long, BigDecimal> entry : returnRatio.entrySet()) { |
| | | // String conent = "USDT返利"; |
| | | // BigDecimal amount = order.getAmount().multiply(entry.getValue()); |
| | | // LogRecordUtils.insertMemberAccountMoneyChangeWithId(entry.getKey(), conent, amount, "USDT", 1, 6, order.getId()); |
| | | // MemberWalletCoinEntity walletCoin = memberWalletCoinDao.selectWalletCoinBymIdAndCode(entry.getKey(), "USDT"); |
| | | // |
| | | // memberWalletCoinDao.updateBlockBalance(walletCoin.getId(), amount, BigDecimal.ZERO, 0); |
| | | // } |
| | | // |
| | | // YdOrderEntity updateOrder = new YdOrderEntity(); |
| | | // updateOrder.setReturnState(2); |
| | | // updateOrder.setId(order.getId()); |
| | | // ydOrderDao.updateById(updateOrder); |
| | | // } |
| | | |
| | | // 合伙人分红 |
| | | List<MemberEntity> partners = memberDao.selectPartnerMemberList(); |
| | |
| | | for (MemberEntity partner : partners) { |
| | | String conent = "合伙人USDT分红"; |
| | | LogRecordUtils.insertMemberAccountMoneyChangeWithId(partner.getId(), conent, returnAmount, "USDT", 1, 9, order.getId()); |
| | | MemberWalletCoinEntity walletCoin = memberWalletCoinDao.selectWalletCoinBymIdAndCode(partner.getId(), "USDT"); |
| | | |
| | | memberWalletCoinDao.updateBlockBalance(walletCoin.getId(), returnAmount, BigDecimal.ZERO, 0); |
| | | // MemberWalletCoinEntity walletCoin = memberWalletCoinDao.selectWalletCoinBymIdAndCode(partner.getId(), "USDT"); |
| | | // memberWalletCoinDao.updateBlockBalance(walletCoin.getId(), returnAmount, BigDecimal.ZERO, 0); |
| | | } |
| | | } |
| | | |
| | |
| | | private Map<Long, BigDecimal> buildReturnRatioObj(List<MemberEntity> agents, int type) { |
| | | Map<Long, BigDecimal> returnRatio = new HashMap<Long, BigDecimal>(); |
| | | Long lastId = null; |
| | | int i = 0; |
| | | for (MemberEntity agent : agents) { |
| | | YdBasicLevelSettingEntity settingEntity = agent.getYdBasicLevelSettingEntity(); |
| | | |
| | |
| | | } |
| | | if(settingEntity.getLevel() == 1) { |
| | | if (CollUtil.isNotEmpty(returnRatio)) { |
| | | BigDecimal lastRatio = returnRatio.get(lastId); |
| | | returnRatio.put(agent.getId(), ratio.subtract(lastRatio)); |
| | | if (i != 0) { |
| | | returnRatio.put(agent.getId(), BigDecimal.valueOf(0.01)); |
| | | } else { |
| | | BigDecimal lastRatio = returnRatio.get(lastId); |
| | | returnRatio.put(agent.getId(), ratio.subtract(lastRatio)); |
| | | } |
| | | } else { |
| | | returnRatio.put(agent.getId(), ratio); |
| | | } |
| | | break; |
| | | |
| | | if (i >= 1) { |
| | | break; |
| | | } |
| | | i++; |
| | | } |
| | | |
| | | if (CollUtil.isEmpty(returnRatio)) { |
| | |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void xchProfitDistributor(BigDecimal totalProfit) { |
| | | Date currentDate = new Date(); |
| | | List<YdProductEntity> products = ydProductDao.selectList(null); |
| | | List<YdProductEntity> products = ydProductDao.selectXchProductList(); |
| | | if (CollUtil.isNotEmpty(products)) { |
| | | BigDecimal totalCount = BigDecimal.ZERO; |
| | | for (YdProductEntity product : products) { |
| | | BigDecimal count = product.getTotalT(); |
| | | BigDecimal count = product.getTotalT().multiply(BigDecimal.valueOf(product.getProNum())); |
| | | if ("P".equals(product.getProUnit())) { |
| | | count = count.multiply(BigDecimal.valueOf(1024)); |
| | | } |
| | |
| | | // 单位XCH收益 |
| | | BigDecimal unitProfit = totalProfit.divide(totalCount, 8, BigDecimal.ROUND_DOWN); |
| | | log.info("单位XCH收益:{}", unitProfit); |
| | | |
| | | List<MemberEntity> partners = memberDao.selectPartnerMemberList(); |
| | | YdBasicSettingEntity setting = ydBasicSettingDao.selectById(1L); |
| | | |
| | | List<YdOrderEntity> orders = ydOrderDao.selectAllValidOrders(); |
| | | if (CollUtil.isNotEmpty(orders)) { |
| | |
| | | List<String> inviteIds = StrUtil.split(memberEntity.getRefererIds(), ','); |
| | | List<MemberEntity> agents = memberDao.selectYdParentAgent(inviteIds); |
| | | |
| | | BigDecimal count = BigDecimal.valueOf(order.getQuantity()); |
| | | BigDecimal count = BigDecimal.valueOf(order.getQuantity() * order.getYdProductEntity().getProNum()); |
| | | if ("P".equals(order.getYdProductEntity().getProUnit())) { |
| | | count = count.multiply(BigDecimal.valueOf(1024)); |
| | | } |
| | | |
| | | // 订单总收益 |
| | | BigDecimal orderProfit = count.multiply(unitProfit); |
| | | BigDecimal remainProfit = orderProfit; |
| | | if (CollUtil.isNotEmpty(agents)) { |
| | |
| | | } |
| | | } |
| | | |
| | | BigDecimal partnerAmount = orderProfit.multiply(setting.getPartnerXchRatio()); |
| | | remainProfit = remainProfit.subtract(partnerAmount); |
| | | // 合伙人收益 |
| | | if (CollUtil.isNotEmpty(partners)) { |
| | | BigDecimal unitPartnerAmount = partnerAmount.divide(BigDecimal.valueOf(partners.size()), 8, BigDecimal.ROUND_DOWN); |
| | | for (MemberEntity partner : partners) { |
| | | String conent = "合伙人XCH分红"; |
| | | LogRecordUtils.insertMemberAccountMoneyChangeWithId(partner.getId(), conent, unitPartnerAmount, "XCH", 1, 10, order.getId()); |
| | | } |
| | | } |
| | | |
| | | remainProfit = remainProfit.subtract(orderProfit.multiply(order.getYdProductEntity().getManageExpense())); |
| | | String content = "XCH收益"; |
| | | LogRecordUtils.insertMemberAccountMoneyChangeWithId(order.getMemberId(), content, remainProfit, "XCH", 1, 4, order.getId()); |