From 1ea6fad18342c1a06901552784de38bfad06c808 Mon Sep 17 00:00:00 2001
From: Helius <wangdoubleone@gmail.com>
Date: Fri, 15 Jul 2022 10:39:58 +0800
Subject: [PATCH] fix
---
src/main/java/cc/mrbird/febs/dapp/service/impl/DappWalletServiceImpl.java | 103 +++++++++++++++++++++++++++++++++++++++------------
1 files changed, 79 insertions(+), 24 deletions(-)
diff --git a/src/main/java/cc/mrbird/febs/dapp/service/impl/DappWalletServiceImpl.java b/src/main/java/cc/mrbird/febs/dapp/service/impl/DappWalletServiceImpl.java
index 92ae21b..c9ae7d1 100644
--- a/src/main/java/cc/mrbird/febs/dapp/service/impl/DappWalletServiceImpl.java
+++ b/src/main/java/cc/mrbird/febs/dapp/service/impl/DappWalletServiceImpl.java
@@ -1,5 +1,6 @@
package cc.mrbird.febs.dapp.service.impl;
+import cc.mrbird.febs.common.configure.i18n.MessageSourceUtils;
import cc.mrbird.febs.common.contants.AppContants;
import cc.mrbird.febs.common.entity.QueryRequest;
import cc.mrbird.febs.common.exception.FebsException;
@@ -9,12 +10,14 @@
import cc.mrbird.febs.dapp.chain.ChainEnum;
import cc.mrbird.febs.dapp.chain.ChainService;
import cc.mrbird.febs.dapp.chain.ContractChainService;
+import cc.mrbird.febs.dapp.dto.PriceDto;
import cc.mrbird.febs.dapp.dto.RecordInPageDto;
import cc.mrbird.febs.dapp.dto.TransferDto;
import cc.mrbird.febs.dapp.dto.WalletOperateDto;
import cc.mrbird.febs.dapp.entity.*;
import cc.mrbird.febs.dapp.mapper.*;
import cc.mrbird.febs.dapp.service.DappWalletService;
+import cc.mrbird.febs.dapp.utils.BoxUtil;
import cc.mrbird.febs.dapp.vo.WalletInfoVo;
import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
@@ -31,7 +34,7 @@
import java.util.Map;
/**
- * @author
+ * @author
* @date 2022-03-18
**/
@Slf4j
@@ -42,24 +45,22 @@
private final DappMemberDao dappMemberDao;
private final DappWalletMineDao dappWalletMineDao;
private final DappWalletCoinDao dappWalletCoinDao;
+ private final DappIdoAssetsDao dappIdoAssetsDao;
private final DappFundFlowDao dappFundFlowDao;
private final DappAccountMoneyChangeDao dappAccountMoneyChangeDao;
private final RedisUtils redisUtils;
+ private final DataDictionaryCustomMapper dataDictionaryCustomMapper;
@Override
public WalletInfoVo walletInfo() {
-// DappMemberEntity member = LoginUserUtil.getAppUser();
-// DappWalletCoinEntity walletCoin = dappWalletCoinDao.selectByMemberId(member.getId());
-// DappWalletMineEntity walletMine = dappWalletMineDao.selectByMemberId(member.getId());
+ DappMemberEntity member = LoginUserUtil.getAppUser();
+ DappIdoAssetsEntity idoAssets = dappIdoAssetsDao.selectByMemberId(member.getId());
WalletInfoVo walletInfo = new WalletInfoVo();
-// walletInfo.setInviteId(member.getInviteId());
-// walletInfo.setTotalMine(walletMine.getTotalAmount());
-// walletInfo.setAvailableMine(walletMine.getAvailableAmount());
-// walletInfo.setAvailableWallet(walletCoin.getAvailableAmount());
-
- walletInfo.setTotalChild(10000);
- walletInfo.setTotalChild(41451);
+ walletInfo.setBoxCnt(idoAssets.getBoxCnt());
+ walletInfo.setCoinAmount(idoAssets.getCoinAmount());
+ walletInfo.setUsdtAmount(idoAssets.getUsdtAmount());
+ walletInfo.setInviteId(member.getInviteId());
return walletInfo;
}
@@ -136,8 +137,12 @@
DappMemberEntity member = LoginUserUtil.getAppUser();
DappFundFlowEntity dappFundFlowEntity = new DappFundFlowEntity();
- dappFundFlowEntity.setType(recordInPageDto.getType());
+ if (recordInPageDto.getType() != null && recordInPageDto.getType() != 0) {
+ dappFundFlowEntity.setType(recordInPageDto.getType());
+ }
dappFundFlowEntity.setMemberId(member.getId());
+ dappFundFlowEntity.setStatus(2);
+
IPage<DappFundFlowEntity> records = dappFundFlowDao.selectInPage(page, dappFundFlowEntity);
return records.getRecords();
}
@@ -198,20 +203,41 @@
}
@Override
- public void transfer(TransferDto transferDto) {
+ public Long transfer(TransferDto transferDto) {
DappMemberEntity member = LoginUserUtil.getAppUser();
-// ChainService.getInstance(ChainEnum.BSC_USDT_SOURCE.name()).balanceOf(member.getAddress());
-// ChainService.getInstance(ChainEnum.BSC_TFC_SOURCE.name()).balanceOf(member.getAddress());
+ if (transferDto.getId() == null) {
+ DappFundFlowEntity fundFlow = new DappFundFlowEntity(member.getId(), transferDto.getAmount(), transferDto.getType(), 1, transferDto.getFee(), transferDto.getTxHash());
+ fundFlow.setNewestPrice(transferDto.getPrice());
+ dappFundFlowDao.insert(fundFlow);
+ return fundFlow.getId();
+ }
- DappFundFlowEntity fundFlow = new DappFundFlowEntity(member.getId(), transferDto.getAmount(), transferDto.getType(), 1, transferDto.getFee(), transferDto.getTxHash());
- fundFlow.setNewestPrice(transferDto.getPrice());
- dappFundFlowDao.insert(fundFlow);
+ if ("success".equals(transferDto.getFlag())) {
+ DappFundFlowEntity flow = dappFundFlowDao.selectById(transferDto.getId());
+
+ flow.setFromHash(transferDto.getTxHash());
+ dappFundFlowDao.updateById(flow);
+ } else {
+ DappFundFlowEntity flow = dappFundFlowDao.selectById(transferDto.getId());
+ if (flow.getStatus() == 1) {
+ dappFundFlowDao.deleteById(transferDto.getId());
+ }
+ }
+ return null;
}
@Override
- public Map<String, BigDecimal> calPrice() {
+ public Map<String, BigDecimal> calPrice(PriceDto priceDto) {
DappMemberEntity member = LoginUserUtil.getAppUser();
+
+ String hasStart = redisUtils.getString(AppContants.SYSTEM_START_FLAG);
+ if (!"start".equals(hasStart)) {
+ HashMap<String, BigDecimal> map = new HashMap<>();
+ map.put("x", new BigDecimal("0.075"));
+ map.put("y", new BigDecimal("100000"));
+ return map;
+ }
ContractChainService tfcInstance = ChainService.getInstance(ChainEnum.BSC_TFC.name());
// u剩余数量
@@ -219,13 +245,42 @@
// 源池代币剩余数量
BigDecimal sourceCoin = tfcInstance.balanceOf(ChainEnum.BSC_USDT_SOURCE.getAddress());
// 用户代币剩余数量
- BigDecimal coin = tfcInstance.balanceOf(member.getAddress());
- BigDecimal x = sourceU.divide(sourceCoin, tfcInstance.decimals(), RoundingMode.HALF_DOWN);
- BigDecimal y = sourceU.divide(sourceCoin.add(coin), tfcInstance.decimals(), RoundingMode.HALF_DOWN);
+ BigDecimal coin = priceDto.getAmount();
+ BigDecimal x = sourceU.divide(sourceCoin, tfcInstance.decimals(), RoundingMode.HALF_UP);
+ BigDecimal y = sourceU.divide(sourceCoin.add(coin), tfcInstance.decimals(), RoundingMode.HALF_UP);
+ log.info("购买价格:{}, 出卖价格:{}", x, y);
HashMap<String, BigDecimal> map = new HashMap<>();
- map.put("x", BigDecimal.ONE);
- map.put("y", BigDecimal.valueOf(0.8D));
+ map.put("x", x);
+ map.put("y", y);
return map;
}
+
+ @Override
+ public int boxSurprise() {
+ DappMemberEntity member = LoginUserUtil.getAppUser();
+
+ DappIdoAssetsEntity idoAssets = dappIdoAssetsDao.selectByMemberId(member.getId());
+ if (idoAssets.getBoxCnt() < 1) {
+ throw new FebsException("盲盒数量不足");
+ }
+
+ idoAssets.setBoxCnt(idoAssets.getBoxCnt() - 1);
+ dappIdoAssetsDao.updateById(idoAssets);
+
+ BoxUtil.Box box = BoxUtil.openBox();
+
+ DappFundFlowEntity boxFundFlow = new DappFundFlowEntity(member.getId(), new BigDecimal(box.getIndex()), 6, 2, BigDecimal.ZERO);
+ dappFundFlowDao.insert(boxFundFlow);
+
+ new Thread(() -> {
+ int count = box.getIndex();
+ while(count > 0) {
+ ChainService.getInstance(ChainEnum.BSC_NFT_SDC.name()).safeMintNFT(member.getAddress());
+ count--;
+ }
+ }).start();
+
+ return box.getIndex();
+ }
}
--
Gitblit v1.9.1