| | |
| | | import cc.mrbird.febs.rabbit.producer.ChainProducer; |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import cn.hutool.core.util.ObjectUtil; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import lombok.RequiredArgsConstructor; |
| | |
| | | private final DappAchieveItemMapper dappAchieveItemMapper; |
| | | private final ChainProducer chainProducer; |
| | | private final AsyncCjService asyncCjService; |
| | | private final DappMemberFundMapper dappMemberFundMapper; |
| | | |
| | | @Override |
| | | public WalletInfoVo walletInfo() { |
| | |
| | | walletInfo.setTzCoin(tzCoin); |
| | | |
| | | BigDecimal hdCoinGeren = dappFundFlowDao.selectAmountTotalByTypeAndMemberIdAndDate(member.getId(), FlowTypeEnum.HUA_DIAN_GEREN.getValue(),null); |
| | | BigDecimal hdCoinTuandui = dappFundFlowDao.selectAmountTotalByTypeAndMemberIdAndDate(member.getId(), FlowTypeEnum.HUA_DIAN_TUANDUI.getValue(),null); |
| | | walletInfo.setHdCoin(hdCoinGeren.add(hdCoinTuandui)); |
| | | BigDecimal hdCoinTuandui = dappFundFlowDao.selectAmountTotalByTypeAndMemberIdAndDate(member.getId(), FlowTypeEnum.HUA_DIAN_TUANDUI_DAIBI.getValue(),null); |
| | | BigDecimal hdCoinTuanduiUSDT = dappFundFlowDao.selectAmountTotalByTypeAndMemberIdAndDate(member.getId(), FlowTypeEnum.HUA_DIAN_TUANDUI_USDT.getValue(),null); |
| | | walletInfo.setHdCoin(hdCoinGeren.add(hdCoinTuandui).add(hdCoinTuanduiUSDT)); |
| | | |
| | | BigDecimal zyTotal = dappFundFlowDao.selectAmountTotalByTypeAndMemberIdAndDate(member.getId(), FlowTypeEnum.ZHI_YA.getValue(),null).negate(); |
| | | walletInfo.setZyTotal(zyTotal); |
| | |
| | | BigDecimal zyToday = dappFundFlowDao.selectAmountTotalByTypeAndMemberIdAndDate(member.getId(), FlowTypeEnum.ZHI_YA.getValue(), new Date()).negate(); |
| | | walletInfo.setZyToday(zyToday); |
| | | |
| | | BigDecimal ccTotal = dappFundFlowDao.selectAmountTotalByTypeAndMemberIdAndDate(member.getId(), FlowTypeEnum.ZHIYA_CHA_CHU.getValue(),null).negate(); |
| | | walletInfo.setCcTotal(ccTotal); |
| | | |
| | | BigDecimal ccToday = dappFundFlowDao.selectAmountTotalByTypeAndMemberIdAndDate(member.getId(), FlowTypeEnum.ZHIYA_CHA_CHU.getValue(), new Date()).negate(); |
| | | QueryWrapper<DappMemberFund> fundQueryWrapper = new QueryWrapper<>(); |
| | | fundQueryWrapper.eq("member_id",memberId); |
| | | List<DappMemberFund> ccTodays = dappMemberFundMapper.selectList(fundQueryWrapper); |
| | | BigDecimal ccToday = BigDecimal.ZERO; |
| | | if(CollUtil.isNotEmpty(ccTodays)){ |
| | | for(DappMemberFund dappMemberFund : ccTodays){ |
| | | BigDecimal usdtCoin = dappMemberFund.getUsdtCoin(); |
| | | BigDecimal coinTarget = dappMemberFund.getCoinTarget(); |
| | | BigDecimal add = coinTarget.add(usdtCoin); |
| | | ccToday = ccToday.add(add); |
| | | } |
| | | } |
| | | walletInfo.setCcToday(ccToday); |
| | | |
| | | List<DappMemberFund> dappMemberFunds = dappMemberFundMapper.selectList(null); |
| | | walletInfo.setCcTotal(CollUtil.isEmpty(dappMemberFunds) ? BigDecimal.ZERO : |
| | | dappMemberFunds.stream().map(DappMemberFund::getAmount).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(8,BigDecimal.ROUND_DOWN)); |
| | | |
| | | List<DappAchieve> dappAchieves = dappAchieveMapper.selectListByMemberId(memberId); |
| | | |
| | | BigDecimal goldAmountDone = dappAchieveMapper.selectGoldAmountByMemberId(memberId); |
| | | BigDecimal coinAmountDone = dappAchieveMapper.selectCoinAmountByMemberId(memberId); |
| | | if(CollUtil.isNotEmpty(dappAchieves)){ |
| | | BigDecimal goldAmount = dappAchieves.stream().map(DappAchieve::getGoldAmount).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(8,BigDecimal.ROUND_DOWN); |
| | | BigDecimal coinAmount = dappAchieves.stream().map(DappAchieve::getCoinAmount).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(8,BigDecimal.ROUND_DOWN); |
| | | BigDecimal goldAmountAva = goldAmount.subtract(goldAmountDone);//金本位剩余 |
| | | BigDecimal coinAmountAva = coinAmount.subtract(coinAmountDone);//币本位剩余 |
| | | if(goldAmountAva.compareTo(new BigDecimal(0.001)) > 0){ |
| | | walletInfo.setGoldAmount(goldAmountAva); |
| | | }else{ |
| | | walletInfo.setGoldAmount(BigDecimal.ZERO); |
| | | } |
| | | if(coinAmountAva.compareTo(new BigDecimal(0.001)) > 0){ |
| | | walletInfo.setCoinAmount(coinAmountAva); |
| | | }else{ |
| | | walletInfo.setCoinAmount(BigDecimal.ZERO); |
| | | } |
| | | }else{ |
| | | walletInfo.setGoldAmount(BigDecimal.ZERO); |
| | | walletInfo.setCoinAmount(BigDecimal.ZERO); |
| | | } |
| | | |
| | | BigDecimal gfaDays = new BigDecimal(redisUtils.getString(DataDicEnum.GFA_DAYS.getValue())).setScale(2,BigDecimal.ROUND_DOWN); |
| | | walletInfo.setGfaDays(gfaDays); |
| | |
| | | if (recordInPageDto.getType() != null && recordInPageDto.getType() != 0) { |
| | | dappFundFlowEntity.setStatus(recordInPageDto.getType()); |
| | | } |
| | | if (recordInPageDto.getState() != null && recordInPageDto.getState() != 0) { |
| | | dappFundFlowEntity.setType(recordInPageDto.getState()); |
| | | } |
| | | dappFundFlowEntity.setMemberId(member.getId()); |
| | | IPage<DappFundFlowEntity> records = dappFundFlowDao.selectInPages(page, dappFundFlowEntity); |
| | | return records.getRecords(); |
| | |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public Long transfer(TransferDto transferDto) { |
| | | DappMemberEntity member = LoginUserUtil.getAppUser(); |
| | | // QueryWrapper<DappFundFlowEntity> objectQueryWrapper = new QueryWrapper<>(); |
| | | // objectQueryWrapper.eq("type" ,FlowTypeEnum.ZHI_YA.getValue()); |
| | | // objectQueryWrapper.eq("status" ,DappFundFlowEntity.WITHDRAW_STATUS_AGREE); |
| | | // objectQueryWrapper.eq("member_id" ,member.getId()); |
| | | // List<DappFundFlowEntity> dappFundFlowEntities = dappFundFlowDao.selectList(objectQueryWrapper); |
| | | |
| | | List<DappFundFlowEntity> dappFundFlowEntities = dappFundFlowDao.selectAmountTotalByTypeAndMemberIdAndDateAndState( |
| | | member.getId(), |
| | | FlowTypeEnum.ZHI_YA.getValue(), |
| | | DappFundFlowEntity.WITHDRAW_STATUS_AGREE, |
| | | new Date()); |
| | | BigDecimal zhiyaAmount = new BigDecimal(redisUtils.getString(DataDicEnum.MEMBER_ZHIYA_AMOUNT.getValue())); |
| | | |
| | | Integer zhiyaTime = Integer.parseInt(redisUtils.getString(DataDicEnum.MEMBER_ZHIYA_TIME.getValue())); |
| | | if(CollUtil.isNotEmpty(dappFundFlowEntities)){ |
| | | if(dappFundFlowEntities.size() >= zhiyaTime){ |
| | | throw new FebsException("今日暂停质押"); |
| | | } |
| | | BigDecimal teamAchieveMemberSum = dappFundFlowEntities.stream().map(DappFundFlowEntity::getAmount).reduce(BigDecimal.ZERO, BigDecimal::add).negate(); |
| | | if(zhiyaAmount.compareTo(teamAchieveMemberSum.add(transferDto.getAmount())) < 0){ |
| | | throw new FebsException("今日最多质押"+zhiyaAmount.subtract(teamAchieveMemberSum).setScale(4,BigDecimal.ROUND_DOWN)); |
| | | } |
| | | } |
| | | |
| | | |
| | | String hasStart = redisUtils.getString(DataDicEnum.SYSTEM_START_FLAG.getValue()); |
| | | BigDecimal minAmount = new BigDecimal(redisUtils.getString(DataDicEnum.GFA_BUY_MIN_AMOUNT.getValue())); |
| | |
| | | if (transferDto.getAmount().compareTo(minAmount) < 0) { |
| | | throw new FebsException("超过购买限制"); |
| | | } |
| | | if (BigDecimal.ZERO.compareTo(gfaDays) >= 0) { |
| | | throw new FebsException("今日暂停质押"); |
| | | } |
| | | if (transferDto.getAmount().compareTo(gfaDays) > 0) { |
| | | throw new FebsException("今日最多质押"+gfaDays); |
| | | // if (BigDecimal.ZERO.compareTo(gfaDays) >= 0) { |
| | | // throw new FebsException("今日暂停质押"); |
| | | // } |
| | | if (transferDto.getAmount().compareTo(zhiyaAmount) > 0) { |
| | | throw new FebsException("今日最多质押"+zhiyaAmount); |
| | | } |
| | | } else { |
| | | throw new FebsException("暂停质押"); |
| | |
| | | //新增一条用户质押记录 |
| | | DappAchieve dappAchieve = new DappAchieve(); |
| | | dappAchieve.setMemberId(memberId); |
| | | dappAchieve.setPrice(transferDto.getPrice()); |
| | | dappAchieve.setAmount(amount); |
| | | BigDecimal achieveReleasePercent = new BigDecimal("0.01").multiply( |
| | | new BigDecimal(redisUtils.getString(DataDicEnum.GFA_ACHIEVE_RELEASE.getValue())).setScale(2,BigDecimal.ROUND_DOWN) |
| | |
| | | dappAchieve.setAmountMax(achieveOut.multiply(amount).setScale(2,BigDecimal.ROUND_DOWN)); |
| | | dappAchieve.setState(DappAchieve.STATUS_ING); |
| | | dappAchieve.setAmountDone(BigDecimal.ZERO); |
| | | |
| | | /** |
| | | * 计算金本位和币本位 |
| | | * 金本位:数量*价格*70*产矿百分比 |
| | | * 币本位:数量*30*产矿百分比 |
| | | */ |
| | | BigDecimal price = dappAchieve.getPrice(); |
| | | BigDecimal goldAmount = amount.multiply(price).multiply(new BigDecimal("0.7")).multiply(achieveOut).setScale(8, BigDecimal.ROUND_DOWN); |
| | | BigDecimal coinAmount = amount.multiply(new BigDecimal("0.3")).multiply(achieveOut).setScale(8, BigDecimal.ROUND_DOWN); |
| | | dappAchieve.setGoldAmount(goldAmount); |
| | | dappAchieve.setCoinAmount(coinAmount); |
| | | dappAchieveMapper.insert(dappAchieve); |
| | | |
| | | asyncCjService.insertTeamPerk(flow.getId(), dappAchieve.getId()); |
| | | // asyncCjService.calculateAchieve(dappAchieve); |
| | | |
| | | //发送一个延时队列消息。24小时之后产生第一次的质押产出 |
| | | chainProducer.sendZhiYaDelayMsg(dappAchieve.getId(), 24 * 60 * 60 * 1000L); |
| | | // chainProducer.sendZhiYaDelayMsg(dappAchieve.getId(), 24 * 60 * 60 * 1000L); |
| | | } else { |
| | | dappFundFlowDao.deleteById(transferDto.getId()); |
| | | } |
| | |
| | | @Override |
| | | public IPage<DappAchieve> dappAchieveInPage(DappAchieve dappAchieve, QueryRequest request) { |
| | | Page<DappAchieve> page = new Page<>(request.getPageNum(), request.getPageSize()); |
| | | return dappAchieveMapper.selectInPage(page, dappAchieve); |
| | | IPage<DappAchieve> dappAchieveIPage = dappAchieveMapper.selectInPage(page, dappAchieve); |
| | | List<DappAchieve> records = dappAchieveIPage.getRecords(); |
| | | if(CollUtil.isNotEmpty(records)){ |
| | | for(DappAchieve dappAchieve1 : records){ |
| | | dappAchieve1.setUsdtAmount(dappAchieve1.getAmount().multiply(dappAchieve1.getPrice()).setScale(2,BigDecimal.ROUND_DOWN)); |
| | | } |
| | | } |
| | | return dappAchieveIPage; |
| | | } |
| | | |
| | | @Override |
| | |
| | | } |
| | | flowType = FlowTypeEnum.DAI_BI_OUT.getValue(); |
| | | flowDes = FlowTypeEnum.DAI_BI_OUT.getDescrition(); |
| | | |
| | | dappMemberEntity.setBalance(balance.subtract(amount).setScale(2,BigDecimal.ROUND_DOWN)); |
| | | dappMemberDao.updateBalanceWithVersion(dappMemberEntity); |
| | | }else{ |
| | | if(new BigDecimal("100").compareTo(amount) > 0){ |
| | | if(new BigDecimal("1").compareTo(amount) > 0){ |
| | | throw new FebsException("最小数量为100"); |
| | | } |
| | | if(usdtBalance.compareTo(amount) < 0){ |
| | |
| | | } |
| | | flowType = FlowTypeEnum.USDT_OUT.getValue(); |
| | | flowDes = FlowTypeEnum.USDT_OUT.getDescrition(); |
| | | |
| | | dappMemberEntity.setUsdtBalance(usdtBalance.subtract(amount).setScale(2,BigDecimal.ROUND_DOWN)); |
| | | dappMemberDao.updateUsdtBalanceWithVersion(dappMemberEntity); |
| | | } |
| | | |
| | | DappFundFlowEntity fundFlowTuiJian = new DappFundFlowEntity( |
| | |
| | | dappMemberEntity.getAddress()); |
| | | dappFundFlowDao.insert(fundFlowTuiJian); |
| | | |
| | | dappMemberEntity.setBalance(balance.subtract(amount).setScale(2,BigDecimal.ROUND_DOWN)); |
| | | dappMemberEntity.setUsdtBalance(usdtBalance.subtract(amount).setScale(2,BigDecimal.ROUND_DOWN)); |
| | | dappMemberDao.updateBalanceAndUsdtBalanceWithVersion(dappMemberEntity); |
| | | // dappMemberEntity.setBalance(balance.subtract(amount).setScale(2,BigDecimal.ROUND_DOWN)); |
| | | // dappMemberEntity.setUsdtBalance(usdtBalance.subtract(amount).setScale(2,BigDecimal.ROUND_DOWN)); |
| | | // dappMemberDao.updateBalanceAndUsdtBalanceWithVersion(dappMemberEntity); |
| | | |
| | | return new FebsResponse().success(); |
| | | } |
| | | |
| | | @Override |
| | | public List<DappMemberFund> memberFundList(RecordInPageDto recordInPageDto) { |
| | | DappMemberEntity member = LoginUserUtil.getAppUser(); |
| | | Page<DappMemberFund> page = new Page<>(recordInPageDto.getPageNum(), recordInPageDto.getPageSize()); |
| | | DappMemberFund dappMemberFund = new DappMemberFund(); |
| | | dappMemberFund.setMemberId(member.getId()); |
| | | IPage<DappMemberFund> records = dappFundFlowDao.memberFundList(page, dappMemberFund); |
| | | return records.getRecords(); |
| | | } |
| | | } |