| | |
| | | import cc.mrbird.febs.common.entity.FebsResponse; |
| | | import cc.mrbird.febs.common.entity.QueryRequest; |
| | | import cc.mrbird.febs.common.enumerates.DataDicEnum; |
| | | import cc.mrbird.febs.common.enumerates.FlowTypeEnum; |
| | | import cc.mrbird.febs.common.exception.FebsException; |
| | | import cc.mrbird.febs.common.utils.RedisUtils; |
| | | import cc.mrbird.febs.dapp.dto.ZhiyaAddDto; |
| | | import cc.mrbird.febs.dapp.entity.*; |
| | | import cc.mrbird.febs.dapp.mapper.*; |
| | | import cc.mrbird.febs.dapp.service.AsyncCjService; |
| | | import cc.mrbird.febs.dapp.service.DappWalletService; |
| | | import cc.mrbird.febs.dapp.service.IAdminBannerService; |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import cn.hutool.core.date.DateTime; |
| | |
| | | private final AsyncCjService asyncCjService; |
| | | private final DappMemberDao dappMemberDao; |
| | | private final DappAchieveMapper dappAchieveMapper; |
| | | private final DappWalletService dappWalletService; |
| | | private final DappFundFlowDao dappFundFlowDao; |
| | | private final RedisUtils redisUtils; |
| | | |
| | | @Override |
| | | public IPage<PlatformBanner> findPlatformBannerInPage(PlatformBanner platformBannerEntity, |
| | |
| | | objectQueryWrapper.eq("state",1); |
| | | List<DappAchieve> dappAchieves = dappAchieveMapper.selectList(objectQueryWrapper); |
| | | if(CollUtil.isNotEmpty(dappAchieves)){ |
| | | BigDecimal teamAchieveMemberSum = dappAchieves.stream().map(DappAchieve::getAmount).reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | BigDecimal teamAchieveMemberSum = dappAchieves.stream().map(item-> item.getAmount().multiply(item.getPrice())).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(2,BigDecimal.ROUND_DOWN); |
| | | memberEntity.setZhiYaAmount(teamAchieveMemberSum); |
| | | } |
| | | } |
| | | } |
| | | return dappMemberEntityIPage; |
| | | } |
| | | |
| | | @Override |
| | | public FebsResponse zhiyaAdd(ZhiyaAddDto zhiyaAddDto) { |
| | | String address = zhiyaAddDto.getAddress(); |
| | | String hash = zhiyaAddDto.getZyHash(); |
| | | BigDecimal amount = new BigDecimal(zhiyaAddDto.getAmount()).setScale(2,BigDecimal.ROUND_DOWN); |
| | | |
| | | DappMemberEntity dappMemberEntity = dappMemberDao.selectByAddress(address, null); |
| | | if(ObjectUtil.isEmpty(dappMemberEntity)){ |
| | | throw new FebsException("地址不存在"); |
| | | } |
| | | if(BigDecimal.ZERO.compareTo(amount) >= 0){ |
| | | throw new FebsException("金额不正确"); |
| | | } |
| | | |
| | | QueryWrapper<DappFundFlowEntity> queryWrapper = new QueryWrapper<>(); |
| | | queryWrapper.eq("from_hash",hash); |
| | | List<DappFundFlowEntity> dappFundFlowEntities = dappFundFlowDao.selectList(queryWrapper); |
| | | if(CollUtil.isNotEmpty(dappFundFlowEntities)){ |
| | | throw new FebsException("HASH已经产生了质押记录"); |
| | | } |
| | | |
| | | DappFundFlowEntity fundFlow = new DappFundFlowEntity( |
| | | dappMemberEntity.getId(), |
| | | amount.negate(), |
| | | FlowTypeEnum.ZHI_YA.getValue(), |
| | | DappFundFlowEntity.WITHDRAW_STATUS_ING, |
| | | BigDecimal.ZERO, |
| | | null); |
| | | dappFundFlowDao.insert(fundFlow); |
| | | |
| | | fundFlow.setFromHash(hash); |
| | | fundFlow.setStatus(DappFundFlowEntity.WITHDRAW_STATUS_AGREE); |
| | | fundFlow.setContent(FlowTypeEnum.ZHI_YA.getDescrition()); |
| | | dappFundFlowDao.updateById(fundFlow); |
| | | |
| | | //用户质押代币数量 |
| | | Long memberId = fundFlow.getMemberId(); |
| | | DappAchieve dappAchieve = new DappAchieve(); |
| | | dappAchieve.setMemberId(memberId); |
| | | DappHdRecord dappHdRecord = dappHdRecordMapper.selectNewRecord(); |
| | | dappAchieve.setPrice(dappHdRecord.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.setAmountDay(achieveReleasePercent.multiply(amount).setScale(2,BigDecimal.ROUND_DOWN)); |
| | | BigDecimal achieveOut = new BigDecimal(redisUtils.getString(DataDicEnum.GFA_ACHIEVE_OUT.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 = dappHdRecord.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); |
| | | //新增一条用户质押记录 |
| | | // DappAchieve dappAchieve = new DappAchieve(); |
| | | // dappAchieve.setMemberId(memberId); |
| | | // dappAchieve.setAmount(amount); |
| | | // BigDecimal achieveReleasePercent = new BigDecimal("0.01").multiply( |
| | | // new BigDecimal(redisUtils.getString(DataDicEnum.GFA_ACHIEVE_RELEASE.getValue())).setScale(2,BigDecimal.ROUND_DOWN) |
| | | // ); |
| | | // DappHdRecord dappHdRecord = dappHdRecordMapper.selectNewRecord(); |
| | | // dappAchieve.setPrice(dappHdRecord.getPrice()); |
| | | // dappAchieve.setAmountDay(achieveReleasePercent.multiply(amount).setScale(2,BigDecimal.ROUND_DOWN)); |
| | | // BigDecimal achieveOut = new BigDecimal(redisUtils.getString(DataDicEnum.GFA_ACHIEVE_OUT.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); |
| | | // dappAchieveMapper.insert(dappAchieve); |
| | | // asyncCjService.insertTeamPerk(fundFlow.getId(), dappAchieve.getId()); |
| | | // asyncCjService.calculateAchieve(dappAchieve); |
| | | return new FebsResponse().success(); |
| | | } |
| | | |
| | | @Override |
| | | public FebsResponse zhiyaAddNew() { |
| | | List<DappFundFlowEntity> dappFundFlowEntities = dappFundFlowDao.selectList( |
| | | new QueryWrapper<DappFundFlowEntity>() |
| | | .ge("id", 7599L) |
| | | .lt("id", 7688L)); |
| | | |
| | | if(CollUtil.isNotEmpty(dappFundFlowEntities)){ |
| | | for(DappFundFlowEntity dappFundFlowEntity : dappFundFlowEntities){ |
| | | Integer type = dappFundFlowEntity.getType(); |
| | | if(FlowTypeEnum.HUA_DIAN_GEREN.getValue() == type || FlowTypeEnum.HUA_DIAN_TUANDUI_USDT.getValue() == type){ |
| | | Long memberId = dappFundFlowEntity.getMemberId(); |
| | | BigDecimal amount = dappFundFlowEntity.getAmount(); |
| | | DappMemberEntity dappMemberEntity = dappMemberDao.selectById(memberId); |
| | | BigDecimal usdtBalance = dappMemberEntity.getUsdtBalance(); |
| | | dappMemberEntity.setUsdtBalance(usdtBalance.subtract(amount)); |
| | | dappMemberDao.updateUsdtBalanceWithVersion(dappMemberEntity); |
| | | log.info("流水处理中。。。。。。"+dappFundFlowEntity.getId()+",处理金额"+amount+",账户余额:"+usdtBalance+",操作后余额:"+dappMemberEntity.getUsdtBalance()); |
| | | dappFundFlowDao.deleteById(dappFundFlowEntity.getId()); |
| | | } |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | } |