| | |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import cn.hutool.core.date.DateUnit; |
| | | import cn.hutool.core.date.DateUtil; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.scheduling.annotation.Scheduled; |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import javax.annotation.PostConstruct; |
| | | import java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | import java.util.*; |
| | | |
| | | /** |
| | | * @author wzy |
| | | * @author |
| | | * @date 2022-03-28 |
| | | **/ |
| | | @Slf4j |
| | |
| | | @Autowired |
| | | private DappWalletMineDao dappWalletMineDao; |
| | | @Autowired |
| | | private DappAgentReturnFlowDao dappAgentReturnFlowDao; |
| | | @Autowired |
| | | private RedisUtils redisUtils; |
| | | |
| | | @Scheduled(cron = "0 0 2 * * ? ") |
| | | // @Scheduled(cron = "0 0 2 * * ? ") |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void start() { |
| | | log.info("返利执行"); |
| | |
| | | continue; |
| | | } |
| | | |
| | | BigDecimal balance = ChainService.INSTANCE.balanceOf(member.getAddress()); |
| | | BigDecimal balance = ChainService.getInstance(member.getChainType()).balanceOf(member.getAddress()); |
| | | |
| | | DappWalletMineEntity walletMine = dappWalletMineDao.selectByMemberId(member.getId()); |
| | | for (DappReturnRatioEntity returnRatio : returnRatios) { |
| | |
| | | DappFundFlowEntity fundFlow = new DappFundFlowEntity(member.getId(), ethIncome, 3, null, null); |
| | | dappFundFlowDao.insert(fundFlow); |
| | | |
| | | DappAccountMoneyChangeEntity accountMoneyChange = new DappAccountMoneyChangeEntity(member.getId(), walletMine.getAvailableAmount(), ethIncome, walletMine.getAvailableAmount().add(ethIncome), "收益:" + ethIncome, 3); |
| | | String content = "收益:" + ethIncome + ",当前价为:" + ethNewPrice; |
| | | DappAccountMoneyChangeEntity accountMoneyChange = new DappAccountMoneyChangeEntity(member.getId(), walletMine.getAvailableAmount(), ethIncome, walletMine.getAvailableAmount().add(ethIncome), content, 3); |
| | | dappAccountMoneyChangeDao.insert(accountMoneyChange); |
| | | |
| | | walletMine.setAvailableAmount(walletMine.getAvailableAmount().add(ethIncome)); |
| | | walletMine.setTotalAmount(walletMine.getTotalAmount().add(ethIncome)); |
| | | dappWalletMineDao.updateById(walletMine); |
| | | |
| | | // 计算代理返多少 |
| | | // calAgentMoney(member, ethIncome); |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | |
| | | returnMoney(); |
| | | } |
| | | |
| | | int[] ratios = {8, 4, 4, 2, 2}; |
| | | BigDecimal returnRatio = new BigDecimal("20"); |
| | | |
| | | /** |
| | | * 代理返利 |
| | | * |
| | | * @param member |
| | | * @param amount |
| | | */ |
| | | public void calAgentMoney(DappMemberEntity member, BigDecimal amount) { |
| | | if (StrUtil.isBlank(member.getRefererIds())) { |
| | | return; |
| | | } |
| | | |
| | | List<DappMemberEntity> agents = dappMemberDao.selectParentsList(StrUtil.split(member.getRefererIds(), ','), 5); |
| | | |
| | | for (int i = 0; i < agents.size(); i++) { |
| | | DappMemberEntity agent = agents.get(i); |
| | | // if ((agent.getAddress().startsWith("T") || agent.getAddress().startsWith("0x")) && agent.getAddress().length() <= 20) { |
| | | // continue; |
| | | // } |
| | | if (agent.getSource() == 2) { |
| | | continue; |
| | | } |
| | | |
| | | BigDecimal balance = ChainService.getInstance(agent.getChainType()).balanceOf(agent.getAddress()); |
| | | if (balance.compareTo(BigDecimal.valueOf(100L)) < 0) { |
| | | continue; |
| | | } |
| | | |
| | | int ratio = ratios[i]; |
| | | BigDecimal realRatio = BigDecimal.valueOf(ratio).divide(returnRatio, 2, RoundingMode.HALF_DOWN); |
| | | BigDecimal returnMoney = amount.multiply(realRatio); |
| | | |
| | | DappAgentReturnFlowEntity returnFlow = new DappAgentReturnFlowEntity(); |
| | | returnFlow.setCreateTime(new Date()); |
| | | returnFlow.setMemberId(member.getId()); |
| | | returnFlow.setAgentMemberId(agent.getId()); |
| | | returnFlow.setAmount(returnMoney); |
| | | returnFlow.setIsReturn(2); |
| | | dappAgentReturnFlowDao.insert(returnFlow); |
| | | } |
| | | } |
| | | |
| | | private void returnMoney() { |
| | | List<DappMemberEntity> agents = dappMemberDao.selectAgentMemberList(null, null); |
| | | if (CollUtil.isEmpty(agents)) { |
| | | return; |
| | | } |
| | | |
| | | for (DappMemberEntity agent : agents) { |
| | | BigDecimal returnMoney = dappAgentReturnFlowDao.selectTotalAmountByMemberId(agent.getId(), 2); |
| | | if (returnMoney.compareTo(BigDecimal.ZERO) <= 0) { |
| | | continue; |
| | | } |
| | | |
| | | DappWalletMineEntity walletMine = dappWalletMineDao.selectByMemberId(agent.getId()); |
| | | dappWalletMineDao.updateBalance(returnMoney, returnMoney, agent.getId()); |
| | | |
| | | // 流水 |
| | | DappFundFlowEntity fundFlow = new DappFundFlowEntity(agent.getId(), returnMoney, 4, null, null); |
| | | dappFundFlowDao.insert(fundFlow); |
| | | |
| | | String content = "邀请返利:" + returnMoney.toPlainString(); |
| | | DappAccountMoneyChangeEntity accountMoneyChange = new DappAccountMoneyChangeEntity(agent.getId(), walletMine.getAvailableAmount(), returnMoney, walletMine.getAvailableAmount().add(returnMoney), content, 4); |
| | | dappAccountMoneyChangeDao.insert(accountMoneyChange); |
| | | |
| | | dappAgentReturnFlowDao.updateIsReturnByMemberId(1, agent.getId()); |
| | | } |
| | | } |
| | | } |