| | |
| | | import cc.mrbird.febs.common.exception.FebsException; |
| | | import cc.mrbird.febs.common.utils.LoginUserUtil; |
| | | import cc.mrbird.febs.common.utils.RedisUtils; |
| | | import cc.mrbird.febs.dapp.chain.ChainEnum; |
| | | import cc.mrbird.febs.dapp.chain.ChainService; |
| | | import cc.mrbird.febs.dapp.dto.*; |
| | | import cc.mrbird.febs.dapp.entity.*; |
| | | import cc.mrbird.febs.dapp.enumerate.DataDictionaryEnum; |
| | |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | |
| | | |
| | | @Override |
| | | public BigDecimal calPrice(PriceDto priceDto) { |
| | | // String priceStr = redisUtils.getString(AppContants.REDIS_KEY_TFC_NEW_PRICE); |
| | | DataDictionaryCustom symbolPrice = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(DataDictionaryEnum.SYMBOL_PRICE.getType(), DataDictionaryEnum.SYMBOL_PRICE.getCode()); |
| | | DataDictionaryCustom serviceFeeDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(DataDictionaryEnum.WITHDRAW_SERVICE_FEE.getType(), DataDictionaryEnum.WITHDRAW_SERVICE_FEE.getCode()); |
| | | |
| | | BigDecimal amount = priceDto.getAmount(); |
| | | if (priceDto.getAmount() == null) { |
| | | amount = BigDecimal.ZERO; |
| | | DappMemberEntity member = LoginUserUtil.getAppUser(); |
| | | //手续费率 |
| | | DataDictionaryCustom feePercentDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode( |
| | | DataDictionaryEnum.CHARGE_FEE_PERCENT.getType(), |
| | | DataDictionaryEnum.CHARGE_FEE_PERCENT.getCode()); |
| | | BigDecimal feePercent = new BigDecimal(feePercentDic.getValue()).multiply(new BigDecimal("0.01")); |
| | | //提现金额 |
| | | BigDecimal withdrawCnt = BigDecimal.ZERO; |
| | | if (ObjectUtil.isEmpty(priceDto.getWithdrawCnt())) { |
| | | withdrawCnt = BigDecimal.ZERO; |
| | | }else{ |
| | | withdrawCnt = priceDto.getWithdrawCnt(); |
| | | } |
| | | return amount.multiply(new BigDecimal(serviceFeeDic.getValue()).divide(BigDecimal.valueOf(100), 8, RoundingMode.HALF_DOWN)).divide(new BigDecimal(symbolPrice.getValue()), 2, RoundingMode.HALF_UP); |
| | | if(BigDecimal.ZERO.compareTo(withdrawCnt) >= 0){ |
| | | throw new FebsException("请输入正确的金额"); |
| | | } |
| | | DappWalletCoinEntity walletCoin = dappWalletCoinDao.selectByMemberId(member.getId()); |
| | | if (priceDto.getWithdrawCnt().compareTo(walletCoin.getAvailableAmount()) > 0) { |
| | | throw new FebsException("可提现不足"); |
| | | } |
| | | BigDecimal feeUsdt = withdrawCnt.multiply(feePercent).setScale(2, BigDecimal.ROUND_DOWN); |
| | | |
| | | return feeUsdt.divide(priceDto.getAmount(), 2, BigDecimal.ROUND_DOWN); |
| | | } |
| | | |
| | | @Override |
| | |
| | | |
| | | DappWalletMineEntity walletMine = dappWalletMineDao.selectByMemberId(member.getId()); |
| | | if (walletMine.getAvailableAmount().compareTo(withdrawDto.getFee()) < 0) { |
| | | throw new FebsException("DMD Not Enough"); |
| | | throw new FebsException("Fee Not Enough"); |
| | | } |
| | | |
| | | updateWalletCoinWithLock(withdrawDto.getAmount(), member.getId(), 2); |
| | | updateWalletMineWithLock(withdrawDto.getFee(), member.getId(), 2); |
| | | |
| | | |
| | | DappFundFlowEntity feeFlow = new DappFundFlowEntity(member.getId(), withdrawDto.getFee().negate(), 7, 2, null, null); |
| | | DappFundFlowEntity feeFlow = new DappFundFlowEntity(member.getId(), withdrawDto.getFee().negate(), 20, 2, null, null); |
| | | dappFundFlowDao.insert(feeFlow); |
| | | |
| | | DappFundFlowEntity fundFlow = new DappFundFlowEntity(member.getId(), withdrawDto.getAmount().negate(), 5, 2, withdrawDto.getFee(), null); |
| | | DappFundFlowEntity fundFlow = new DappFundFlowEntity(member.getId(), withdrawDto.getAmount().negate(), 21, 2, withdrawDto.getFee(), null); |
| | | dappFundFlowDao.insert(fundFlow); |
| | | |
| | | MemberCoinWithdrawEntity memberCoinWithdraw = new MemberCoinWithdrawEntity(); |
| | |
| | | memberCoinWithdraw.setAddress(member.getAddress()); |
| | | memberCoinWithdraw.setAmount(withdrawDto.getAmount()); |
| | | memberCoinWithdraw.setFeeAmount(withdrawDto.getFee()); |
| | | memberCoinWithdraw.setStatus(MemberCoinWithdrawEntity.STATUS_YES); |
| | | memberCoinWithdraw.setStatus(MemberCoinWithdrawEntity.STATUS_DOING); |
| | | memberCoinWithdraw.setSymbol("USDT"); |
| | | memberCoinWithdraw.setFlowId(fundFlow.getId()); |
| | | memberCoinWithdrawDao.insert(memberCoinWithdraw); |
| | | |
| | | String hash = ChainService.getInstance(ChainEnum.BSC_USDT.name()).transfer(member.getAddress(), withdrawDto.getAmount()); |
| | | fundFlow.setToHash(hash); |
| | | dappFundFlowDao.updateById(fundFlow); |
| | | |
| | | chainProducer.sendFeeDistributeMsg(fundFlow.getId()); |
| | | // Map<String, Object> map = new HashMap<>(); |
| | | // map.put("fee", withdrawDto.getFee()); |
| | | // map.put("address", ChainEnum.BSC_TFC_FEE.getAddress()); |
| | | // map.put("flow", feeFlow.getId()); |
| | | // chainProducer.sendTfcFee(JSONObject.toJSONString(map)); |
| | | } |
| | | |
| | | @Override |
| | |
| | | nextWrapper.eq("type", nextNodeType); |
| | | nextWrapper.eq("work_state", DbMemberNode.STATE_ONE); |
| | | List<DbMemberNode> nextNode = dbMemberNodeMapper.selectList(nextWrapper); |
| | | if(CollUtil.isNotEmpty(nextNode)){ |
| | | if(CollUtil.isEmpty(nextNode)){ |
| | | throw new FebsException("请先购买上一星团"); |
| | | } |
| | | } |
| | |
| | | return buildTeamMatrix(dbMemberNode); |
| | | } |
| | | |
| | | @Override |
| | | public Long chargeFee(ChargeFeeDto chargeFeeDto) { |
| | | DappMemberEntity member = LoginUserUtil.getAppUser(); |
| | | |
| | | String upgrade = redisUtils.getString("APP_UPGRADE"); |
| | | if ("upgrade".equals(upgrade)) { |
| | | throw new FebsException("功能升级中"); |
| | | } |
| | | if (ObjectUtil.isEmpty(chargeFeeDto.getId())) {//第一次 |
| | | DappFundFlowEntity fundFlow = new DappFundFlowEntity( |
| | | member.getId(), |
| | | chargeFeeDto.getAmount().negate(), |
| | | 19, |
| | | 1, |
| | | BigDecimal.ZERO, |
| | | chargeFeeDto.getTxHash()); |
| | | dappFundFlowDao.insert(fundFlow); |
| | | return fundFlow.getId(); |
| | | } else {//第二次 |
| | | DappFundFlowEntity flow = dappFundFlowDao.selectById(chargeFeeDto.getId()); |
| | | if(ObjectUtil.isEmpty(flow)){ |
| | | return null; |
| | | } |
| | | if ("success".equals(chargeFeeDto.getFlag())) { |
| | | flow.setFromHash(chargeFeeDto.getTxHash()); |
| | | dappFundFlowDao.updateById(flow); |
| | | } else { |
| | | if (flow.getStatus() == 1) { |
| | | dappFundFlowDao.deleteById(chargeFeeDto.getId()); |
| | | } |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | public MemberNodeVo buildTeamMatrix(DbMemberNode dbMemberNode) { |
| | | Long id = dbMemberNode.getId(); |
| | | |