From da4a4ffde64cdf7303b809e0b4134ef3119fcf6f Mon Sep 17 00:00:00 2001
From: wzy <wzy19931122ai@163.com>
Date: Sun, 07 Aug 2022 13:18:17 +0800
Subject: [PATCH] Merge branch 'TFC' of http://120.27.238.55:7000/r/sys-dapp into TFC
---
src/main/java/cc/mrbird/febs/dapp/service/impl/DappSystemServiceImpl.java | 9 +++
src/main/java/cc/mrbird/febs/dapp/chain/ChainService.java | 11 +++
src/main/resources/i18n/message_zh_CN.properties | 4 +
src/main/resources/mapper/dapp/DappMemberDao.xml | 3
src/main/java/cc/mrbird/febs/common/contants/AppContants.java | 1
src/main/java/cc/mrbird/febs/dapp/service/impl/DappWalletServiceImpl.java | 91 ++++++++++++++++++++----------
src/main/resources/i18n/message_en_US.properties | 5 +
src/main/java/cc/mrbird/febs/dapp/vo/TeamListVo.java | 2
8 files changed, 93 insertions(+), 33 deletions(-)
diff --git a/src/main/java/cc/mrbird/febs/common/contants/AppContants.java b/src/main/java/cc/mrbird/febs/common/contants/AppContants.java
index 4032d93..3da48dc 100644
--- a/src/main/java/cc/mrbird/febs/common/contants/AppContants.java
+++ b/src/main/java/cc/mrbird/febs/common/contants/AppContants.java
@@ -144,6 +144,7 @@
public static final String REDIS_KEY_BLOCK_ETH_INCREMENT_NUM = "BLOCK_ETH_INCREMENT_NUM";
public static final String REDIS_KEY_MAKE_POOL_CNT = "MAKE_POOL_CNT";
+ public static final String REDIS_KEY_IDO_USDT_MAX_BUY_DAILY = "USDT_MAX_BUY_DAILY_";
public static final String DIC_TYPE_DISTRIBUTE_PROP = "DISTRIBUTE_PROP";
diff --git a/src/main/java/cc/mrbird/febs/dapp/chain/ChainService.java b/src/main/java/cc/mrbird/febs/dapp/chain/ChainService.java
index e83c1f0..a771eb9 100644
--- a/src/main/java/cc/mrbird/febs/dapp/chain/ChainService.java
+++ b/src/main/java/cc/mrbird/febs/dapp/chain/ChainService.java
@@ -6,6 +6,7 @@
import com.alibaba.fastjson.JSONObject;
import io.reactivex.Flowable;
import lombok.extern.slf4j.Slf4j;
+import okhttp3.OkHttpClient;
import org.springframework.data.repository.query.ParameterOutOfBoundsException;
import org.web3j.crypto.Credentials;
import org.web3j.protocol.Web3j;
@@ -23,6 +24,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.concurrent.TimeUnit;
/**
* @author
@@ -82,7 +84,14 @@
private static EthUsdtContract contract(String privateKey, String contractAddress, String url) {
Credentials credentials = Credentials.create(privateKey);
- return EthUsdtContract.load(contractAddress, Web3j.build(new HttpService(url)), credentials, new StaticGasProvider(BigInteger.valueOf(4500000L), BigInteger.valueOf(200000L)));
+ return EthUsdtContract.load(contractAddress,
+ Web3j.build(new HttpService(url, new OkHttpClient().newBuilder()
+ .connectTimeout(100, TimeUnit.SECONDS)
+ .writeTimeout(100, TimeUnit.SECONDS)
+ .readTimeout(100, TimeUnit.SECONDS)
+ .build())),
+ credentials,
+ new StaticGasProvider(BigInteger.valueOf(4500000L), BigInteger.valueOf(200000L)));
}
private static EthFilter getFilter(BigInteger startBlock, String contractAddress) {
diff --git a/src/main/java/cc/mrbird/febs/dapp/service/impl/DappSystemServiceImpl.java b/src/main/java/cc/mrbird/febs/dapp/service/impl/DappSystemServiceImpl.java
index 129bc19..ffd30b0 100644
--- a/src/main/java/cc/mrbird/febs/dapp/service/impl/DappSystemServiceImpl.java
+++ b/src/main/java/cc/mrbird/febs/dapp/service/impl/DappSystemServiceImpl.java
@@ -117,6 +117,15 @@
system.setBuyRemain(balance);
system.setBuyTotal(balance);
+
+ Object maxDailyBuy = redisUtils.get(AppContants.REDIS_KEY_IDO_USDT_MAX_BUY_DAILY + member.getAddress());
+ if (maxDailyBuy == null) {
+ DateTime tomorrow = DateUtil.beginOfDay(DateUtil.tomorrow());
+ long time = DateUtil.between(new Date(), tomorrow, DateUnit.SECOND, true);
+
+ redisUtils.set(AppContants.REDIS_KEY_IDO_USDT_MAX_BUY_DAILY + member.getAddress(), new BigDecimal("1000"), time);
+ }
+
return system;
}
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 ec08f1c..0a44401 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
@@ -224,6 +224,10 @@
BigDecimal usdtRemain = (BigDecimal) redisUtils.get(AppContants.REDIS_KEY_USDT_OUT_LIMIT_REMAIN);
// 用户24小时可出售量
BigDecimal saleCoinRemain = (BigDecimal) redisUtils.get(AppContants.REDIS_KEY_COIN_REMAIN + member.getAddress());
+
+ // 用户24小时可购买USDT
+ BigDecimal buyUsdtMax = (BigDecimal) redisUtils.get(AppContants.REDIS_KEY_IDO_USDT_MAX_BUY_DAILY + member.getAddress());
+
BigDecimal buyCoinRemain = (BigDecimal) redisUtils.get(AppContants.REDIS_KEY_TRANSFER_POOL_VOL_REMAIN);
// 铸池中的币的剩余量
BigDecimal makeCoinRemain = (BigDecimal) redisUtils.get(AppContants.REDIS_KEY_MAKE_POOL_CNT);
@@ -251,6 +255,11 @@
// 修改用户24小时可售量
redisUtils.set(AppContants.REDIS_KEY_COIN_REMAIN + member.getAddress(), saleCoinRemain);
} else if (DappFundFlowEntity.TYPE_BUY == transferDto.getType()) {
+ // 购买时,前端传来的amount是USDT,卖出amount是TFC
+ BigDecimal usdtAmount = transferDto.getAmount();
+ BigDecimal coinAmount = transferDto.getAmount().divide(transferDto.getPrice(), 6, RoundingMode.HALF_UP);
+ transferDto.setAmount(coinAmount);
+
if ("start".equals(hasStart)) {
if (transferDto.getAmount().compareTo(buyCoinRemain) > 0) {
throw new FebsException(MessageSourceUtils.getString("transfer_msg_004"));
@@ -261,15 +270,24 @@
redisUtils.set(AppContants.REDIS_KEY_TRANSFER_POOL_VOL_REMAIN, buyCoinRemain);
// 如果系统还没有启动,则判断铸池中的剩余量
} else {
- DataDictionaryCustom dic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(AppContants.DIC_TYPE_SYSTEM_SETTING, AppContants.DIC_VALUE_MAKER_MIN_LIMIT);
- if (transferDto.getAmount().compareTo(new BigDecimal(dic.getValue())) < 0) {
- throw new FebsException(MessageSourceUtils.getString("transfer_msg_005"));
+ // 最少购买
+// DataDictionaryCustom dic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(AppContants.DIC_TYPE_SYSTEM_SETTING, AppContants.DIC_VALUE_MAKER_MIN_LIMIT);
+// if (transferDto.getAmount().compareTo(new BigDecimal(dic.getValue())) < 0) {
+// throw new FebsException(MessageSourceUtils.getString("transfer_msg_005"));
+// }
+
+ if (buyUsdtMax.compareTo(usdtAmount) < 0) {
+ throw new FebsException(MessageSourceUtils.getString("transfer_msg_007"));
}
if (transferDto.getAmount().compareTo(makeCoinRemain) > 0) {
throw new FebsException(MessageSourceUtils.getString("transfer_msg_006"));
}
makeCoinRemain = makeCoinRemain.subtract(transferDto.getAmount());
+ buyUsdtMax = buyUsdtMax.subtract(usdtAmount);
+
+ // 修改每日最大购买USDT量
+ redisUtils.set(AppContants.REDIS_KEY_IDO_USDT_MAX_BUY_DAILY + member.getAddress(), buyUsdtMax);
// 修改铸池量
redisUtils.set(AppContants.REDIS_KEY_MAKE_POOL_CNT, makeCoinRemain);
@@ -291,6 +309,11 @@
DappFundFlowEntity flow = dappFundFlowDao.selectById(transferDto.getId());
if (flow.getStatus() == 1) {
if (DappFundFlowEntity.TYPE_BUY == flow.getType()) {
+ // 购买时,前端传来的amount是USDT,卖出amount是TFC
+ BigDecimal usdtAmount = transferDto.getAmount();
+ BigDecimal coinAmount = transferDto.getAmount().divide(flow.getNewestPrice(), 6, RoundingMode.HALF_UP);
+ transferDto.setAmount(coinAmount);
+
if ("start".equals(hasStart)) {
buyCoinRemain = buyCoinRemain.add(flow.getAmount());
@@ -298,9 +321,11 @@
redisUtils.set(AppContants.REDIS_KEY_TRANSFER_POOL_VOL_REMAIN, buyCoinRemain);
} else {
makeCoinRemain = makeCoinRemain.add(flow.getAmount());
+ buyUsdtMax = buyUsdtMax.add(usdtAmount);
// 修改铸池量
redisUtils.set(AppContants.REDIS_KEY_MAKE_POOL_CNT, makeCoinRemain);
+ redisUtils.set(AppContants.REDIS_KEY_IDO_USDT_MAX_BUY_DAILY + member.getAddress(), buyUsdtMax);
}
} else {
usdtRemain = usdtRemain.add(transferDto.getAmount().multiply(transferDto.getPrice()));
@@ -347,35 +372,39 @@
@Override
public int boxSurprise() {
- DappMemberEntity member = LoginUserUtil.getAppUser();
- DappWalletCoinEntity walletCoin = dappWalletCoinDao.selectByMemberId(member.getId());
- if (walletCoin.getBoxCnt() < 1) {
- throw new FebsException("盲盒数量不足");
- }
+ // 功能升级
+ throw new FebsException(MessageSourceUtils.getString("box_surprise_002"));
- walletCoin.setBoxCnt(walletCoin.getBoxCnt() - 1);
- dappWalletCoinDao.updateById(walletCoin);
-
- BoxUtil.Box box = BoxUtil.openBox();
-
- DappFundFlowEntity boxFundFlow = new DappFundFlowEntity(member.getId(), new BigDecimal(box.getIndex()), 6, 2, BigDecimal.ZERO);
- dappFundFlowDao.insert(boxFundFlow);
-
- new Thread(() -> {
- try {
- int count = box.getIndex();
- while (count > 0) {
- ChainService.getInstance(ChainEnum.BSC_NFT_SDC.name()).safeMintNFT(member.getAddress());
- Thread.sleep(5000);
- count--;
- }
- } catch (Exception e) {
- e.printStackTrace();
- log.error("发放卡牌错误", e);
- }
- }).start();
-
- return box.getIndex();
+// DappMemberEntity member = LoginUserUtil.getAppUser();
+//
+// DappWalletCoinEntity walletCoin = dappWalletCoinDao.selectByMemberId(member.getId());
+// if (walletCoin.getBoxCnt() < 1) {
+// throw new FebsException(MessageSourceUtils.getString("box_surprise_001"));
+// }
+//
+// walletCoin.setBoxCnt(walletCoin.getBoxCnt() - 1);
+// dappWalletCoinDao.updateById(walletCoin);
+//
+// BoxUtil.Box box = BoxUtil.openBox();
+//
+// DappFundFlowEntity boxFundFlow = new DappFundFlowEntity(member.getId(), new BigDecimal(box.getIndex()), 6, 2, BigDecimal.ZERO);
+// dappFundFlowDao.insert(boxFundFlow);
+//
+// new Thread(() -> {
+// try {
+// int count = box.getIndex();
+// while (count > 0) {
+// ChainService.getInstance(ChainEnum.BSC_NFT_SDC.name()).safeMintNFT(member.getAddress());
+// Thread.sleep(5000);
+// count--;
+// }
+// } catch (Exception e) {
+// e.printStackTrace();
+// log.error("发放卡牌错误", e);
+// }
+// }).start();
+//
+// return box.getIndex();
}
}
diff --git a/src/main/java/cc/mrbird/febs/dapp/vo/TeamListVo.java b/src/main/java/cc/mrbird/febs/dapp/vo/TeamListVo.java
index 3bfa2d2..1d2d969 100644
--- a/src/main/java/cc/mrbird/febs/dapp/vo/TeamListVo.java
+++ b/src/main/java/cc/mrbird/febs/dapp/vo/TeamListVo.java
@@ -20,6 +20,8 @@
private BigDecimal coinCount;
+ private BigDecimal selfCoinCount;
+
public BigDecimal getCoinCount() {
return coinCount.setScale(2, RoundingMode.HALF_DOWN);
}
diff --git a/src/main/resources/i18n/message_en_US.properties b/src/main/resources/i18n/message_en_US.properties
index f7f317b..cd03dce 100644
--- a/src/main/resources/i18n/message_en_US.properties
+++ b/src/main/resources/i18n/message_en_US.properties
@@ -6,5 +6,10 @@
transfer_msg_004=Not Enough Coin
transfer_msg_005=Less Than the Minimum Requirement
transfer_msg_006=Not Enough Coin
+transfer_msg_007=Buy up to 1000 per day
+
+box_surprise_001=Not Enough Box
+box_surprise_002=Feature upgrade
+
system_regist_error=Please contact the recommender to recommend registration.
\ No newline at end of file
diff --git a/src/main/resources/i18n/message_zh_CN.properties b/src/main/resources/i18n/message_zh_CN.properties
index 64a1d5f..7cd5d1b 100644
--- a/src/main/resources/i18n/message_zh_CN.properties
+++ b/src/main/resources/i18n/message_zh_CN.properties
@@ -6,5 +6,9 @@
transfer_msg_004=\u0054\u0046\u0043\u5e01\u4e0d\u8db3
transfer_msg_005=\u4f4e\u4e8e\u6700\u5c0f\u8d2d\u4e70\u91cf
transfer_msg_006=\u0054\u0046\u0043\u5e01\u4e0d\u8db3
+transfer_msg_007=\u6bcf\u5929\u6700\u591a\u8d2d\u4e70\u0031\u0030\u0030\u0030\u0055\u0053\u0044\u0054
+
+box_surprise_001=\u76f2\u76d2\u6570\u91cf\u4e0d\u8db3
+box_surprise_002=\u529f\u80fd\u5347\u7ea7\u4e2d
system_regist_error=\u8bf7\u8054\u7cfb\u63a8\u8350\u4eba\u63a8\u8350\u6ce8\u518c
\ No newline at end of file
diff --git a/src/main/resources/mapper/dapp/DappMemberDao.xml b/src/main/resources/mapper/dapp/DappMemberDao.xml
index 9ce8f74..9238821 100644
--- a/src/main/resources/mapper/dapp/DappMemberDao.xml
+++ b/src/main/resources/mapper/dapp/DappMemberDao.xml
@@ -117,7 +117,8 @@
(select count(1) from dapp_member b where find_in_set(a.invite_id, b.fee_profit_ids)
) count,
(select ifnull(sum(c.balance),0) from dapp_member c where find_in_set(a.invite_id, c.fee_profit_ids)
- ) coinCount
+ ) coinCount,
+ a.balance selfCoinCount
from dapp_member a
where a.referer_id=#{record.inviteId}
</select>
--
Gitblit v1.9.1