| | |
| | | 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.*; |
| | |
| | | private DappAccountMoneyChangeDao dappAccountMoneyChangeDao; |
| | | @Autowired |
| | | private DappWalletMineDao dappWalletMineDao; |
| | | @Autowired |
| | | private DappAgentReturnFlowDao dappAgentReturnFlowDao; |
| | | @Autowired |
| | | private RedisUtils redisUtils; |
| | | |
| | |
| | | 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 |
| | | */ |
| | | private void calAgentMoney(DappMemberEntity member, BigDecimal amount) { |
| | | if (StrUtil.isBlank(member.getRefererIds())) { |
| | | return; |
| | | } |
| | | |
| | | List<DappMemberEntity> agents = dappMemberDao.selectAgentMemberList(StrUtil.split(member.getRefererIds(), ','), 5); |
| | | |
| | | for (int i = 0; i < agents.size(); i++) { |
| | | DappMemberEntity agent = agents.get(i); |
| | | BigDecimal balance = ChainService.INSTANCE.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); |
| | | } |
| | | } |
| | | } |