From 3154a08c8f114291b59ee44074d6af95026eba32 Mon Sep 17 00:00:00 2001
From: Helius <wangdoubleone@gmail.com>
Date: Thu, 11 Aug 2022 18:18:28 +0800
Subject: [PATCH] fix:add active nft
---
src/main/java/cc/mrbird/febs/dapp/service/DappWalletService.java | 2
src/main/java/cc/mrbird/febs/dapp/dto/ActiveDto.java | 4 ++
src/main/java/cc/mrbird/febs/dapp/entity/DappNftActivation.java | 7 +++
src/main/resources/i18n/message_zh_CN.properties | 2
src/main/java/cc/mrbird/febs/dapp/controller/ApiDappMemberController.java | 28 +++++++++-----
src/main/java/cc/mrbird/febs/dapp/service/impl/DappWalletServiceImpl.java | 70 +++++++++++++++++++++++------------
src/main/resources/i18n/message_en_US.properties | 2
src/main/java/cc/mrbird/febs/dapp/vo/ActiveNftListVo.java | 5 ++
8 files changed, 81 insertions(+), 39 deletions(-)
diff --git a/src/main/java/cc/mrbird/febs/dapp/controller/ApiDappMemberController.java b/src/main/java/cc/mrbird/febs/dapp/controller/ApiDappMemberController.java
index 23f34c7..6de282d 100644
--- a/src/main/java/cc/mrbird/febs/dapp/controller/ApiDappMemberController.java
+++ b/src/main/java/cc/mrbird/febs/dapp/controller/ApiDappMemberController.java
@@ -10,6 +10,7 @@
import cc.mrbird.febs.dapp.service.DappMemberService;
import cc.mrbird.febs.dapp.service.DappSystemService;
import cc.mrbird.febs.dapp.service.DappWalletService;
+import cc.mrbird.febs.dapp.vo.ActiveNftListVo;
import cc.mrbird.febs.dapp.vo.TeamListVo;
import cc.mrbird.febs.dapp.vo.WalletInfoVo;
import io.swagger.annotations.Api;
@@ -86,18 +87,14 @@
return new FebsResponse().success().data(dappMemberService.findTeamList(teamListDto));
}
+ @ApiResponses({
+ @ApiResponse(code = 200, message = "success", response = ActiveNftListVo.class)
+ })
@ApiOperation(value = "开盲盒", notes = "开盲盒")
@PostMapping(value = "/boxSurprise")
public FebsResponse boxSurprise() {
- int cnt = dappWalletService.boxSurprise();
- return new FebsResponse().success().data(cnt);
- }
-
- @PostMapping(value = "/logout")
- public FebsResponse logout() {
- DappMemberEntity member = LoginUserUtil.getAppUser();
- redisUtils.hdel(AppContants.REDIS_KEY_SIGN, member.getAddress());
- return new FebsResponse().success();
+ ActiveNftListVo data = dappWalletService.boxSurprise();
+ return new FebsResponse().success().data(data);
}
@ApiOperation(value = "激活卡牌", notes = "激活卡牌")
@@ -107,9 +104,20 @@
return new FebsResponse().success();
}
+ @ApiResponses({
+ @ApiResponse(code = 200, message = "success", response = ActiveNftListVo.class)
+ })
@ApiOperation(value = "卡牌列表", notes = "卡牌列表")
@PostMapping(value = "/findNftList")
public FebsResponse findNftList() {
- return null;
+ return new FebsResponse().success().data(dappWalletService.findUnActiveNftList());
+ }
+
+
+ @PostMapping(value = "/logout")
+ public FebsResponse logout() {
+ DappMemberEntity member = LoginUserUtil.getAppUser();
+ redisUtils.hdel(AppContants.REDIS_KEY_SIGN, member.getAddress());
+ return new FebsResponse().success();
}
}
diff --git a/src/main/java/cc/mrbird/febs/dapp/dto/ActiveDto.java b/src/main/java/cc/mrbird/febs/dapp/dto/ActiveDto.java
index 7b878af..d46a66c 100644
--- a/src/main/java/cc/mrbird/febs/dapp/dto/ActiveDto.java
+++ b/src/main/java/cc/mrbird/febs/dapp/dto/ActiveDto.java
@@ -21,4 +21,8 @@
@NotNull(message = "参数错误")
@ApiModelProperty(value = "交易哈希")
private String txHash;
+
+ @NotNull(message = "参数错误")
+ @ApiModelProperty(value = "激活数量")
+ private Integer count;
}
diff --git a/src/main/java/cc/mrbird/febs/dapp/entity/DappNftActivation.java b/src/main/java/cc/mrbird/febs/dapp/entity/DappNftActivation.java
index 50a988b..8a00535 100644
--- a/src/main/java/cc/mrbird/febs/dapp/entity/DappNftActivation.java
+++ b/src/main/java/cc/mrbird/febs/dapp/entity/DappNftActivation.java
@@ -17,13 +17,18 @@
private Long memberId;
- private Integer tokenId;
+ private Integer count;
private String hash;
private Date openTime;
+ /**
+ * 状态 1-待激活 2-已过期
+ */
private Integer status;
private Long flowId;
+
+ private Date expireTime;
}
diff --git a/src/main/java/cc/mrbird/febs/dapp/service/DappWalletService.java b/src/main/java/cc/mrbird/febs/dapp/service/DappWalletService.java
index 720e581..74f44e6 100644
--- a/src/main/java/cc/mrbird/febs/dapp/service/DappWalletService.java
+++ b/src/main/java/cc/mrbird/febs/dapp/service/DappWalletService.java
@@ -38,7 +38,7 @@
Map<String, BigDecimal> calPrice(PriceDto priceDto);
- int boxSurprise();
+ ActiveNftListVo boxSurprise();
void activeNft(ActiveDto activeDto);
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 be99e2a..d1b6b1e 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
@@ -19,6 +19,7 @@
import cc.mrbird.febs.dapp.vo.ActiveNftListVo;
import cc.mrbird.febs.dapp.vo.WalletInfoVo;
import cn.hutool.core.collection.CollUtil;
+import cn.hutool.core.date.DateField;
import cn.hutool.core.date.DateUnit;
import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
@@ -374,23 +375,19 @@
}
@Override
- public int boxSurprise() {
+ public ActiveNftListVo boxSurprise() {
+ DappMemberEntity member = LoginUserUtil.getAppUser();
- // 功能升级
- throw new FebsException(MessageSourceUtils.getString("box_surprise_002"));
+ DappWalletCoinEntity walletCoin = dappWalletCoinDao.selectByMemberId(member.getId());
+ if (walletCoin.getBoxCnt() < 1) {
+ throw new FebsException(MessageSourceUtils.getString("box_surprise_001"));
+ }
-// 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();
-//
+ 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);
//
@@ -407,25 +404,49 @@
// log.error("发放卡牌错误", e);
// }
// }).start();
-//
-// return box.getIndex();
+
+ Date time = new Date();
+ Date expire = DateUtil.offset(time, DateField.HOUR, 2);
+ DappNftActivation nftActivation = new DappNftActivation();
+ nftActivation.setMemberId(member.getId());
+ nftActivation.setCount(box.getIndex());
+ nftActivation.setOpenTime(time);
+ nftActivation.setExpireTime(expire);
+
+ dappNftActivationDao.insert(nftActivation);
+
+ ActiveNftListVo nft = new ActiveNftListVo();
+ nft.setStatus(3);
+ nft.setCount(box.getIndex());
+ nft.setId(nftActivation.getId());
+ nft.setRemain(DateUtil.between(time, expire, DateUnit.SECOND));
+ return nft;
}
@Override
@Transactional(rollbackFor = Exception.class)
- public void activeNft(ActiveDto activeDto) {
+ public synchronized void activeNft(ActiveDto activeDto) {
DappMemberEntity member = LoginUserUtil.getAppUser();
- DappFundFlowEntity fundFlow = new DappFundFlowEntity(member.getId(), BigDecimal.ONE, 8, 1, BigDecimal.ZERO, activeDto.getTxHash());
- fundFlow.setNewestPrice(AppContants.NFT_ACTIVE_PRICE);
-
- dappFundFlowDao.insert(fundFlow);
DappNftActivation nftActive = dappNftActivationDao.selectById(activeDto.getId());
+ if (nftActive == null) {
+ throw new FebsException("NFT不存在");
+ }
+
+ if (nftActive.getCount() < activeDto.getCount()) {
+ throw new FebsException("NFT不足或者正在激活中");
+ }
+
if (nftActive.getStatus() != 1) {
throw new FebsException(MessageSourceUtils.getString("nft_active_001"));
}
- nftActive.setStatus(2);
+
+ DappFundFlowEntity fundFlow = new DappFundFlowEntity(member.getId(), new BigDecimal(activeDto.getCount()), 8, 1, BigDecimal.ZERO, activeDto.getTxHash());
+ fundFlow.setNewestPrice(AppContants.NFT_ACTIVE_PRICE);
+ dappFundFlowDao.insert(fundFlow);
+
+ nftActive.setCount(nftActive.getCount() - activeDto.getCount());
dappNftActivationDao.updateById(nftActive);
}
@@ -435,7 +456,7 @@
List<ActiveNftListVo> list = new ArrayList<>();
UpdateWrapper<DappNftActivation> query = new UpdateWrapper<>();
- query.eq("status", 3);
+ query.eq("status", 1);
query.eq("member_id", member.getId());
List<DappNftActivation> nftActivations = dappNftActivationDao.selectList(query);
@@ -448,6 +469,7 @@
ActiveNftListVo nftVo = new ActiveNftListVo();
nftVo.setId(nft.getId());
nftVo.setRemain(DateUtil.between(nft.getOpenTime(), now, DateUnit.SECOND, false));
+
list.add(nftVo);
});
diff --git a/src/main/java/cc/mrbird/febs/dapp/vo/ActiveNftListVo.java b/src/main/java/cc/mrbird/febs/dapp/vo/ActiveNftListVo.java
index 4657eb3..8568bc6 100644
--- a/src/main/java/cc/mrbird/febs/dapp/vo/ActiveNftListVo.java
+++ b/src/main/java/cc/mrbird/febs/dapp/vo/ActiveNftListVo.java
@@ -12,9 +12,12 @@
@ApiModel(value = "ActiveNftListVo", description = "卡牌列表")
public class ActiveNftListVo {
- @ApiModelProperty(value = "待激活卡牌ID")
+ @ApiModelProperty(value = "待激活ID")
private Long id;
@ApiModelProperty(value = "倒计时(剩余多少秒)")
private Long remain;
+
+ @ApiModelProperty(value = "剩余张数")
+ private Integer count;
}
diff --git a/src/main/resources/i18n/message_en_US.properties b/src/main/resources/i18n/message_en_US.properties
index 0167e28..5545518 100644
--- a/src/main/resources/i18n/message_en_US.properties
+++ b/src/main/resources/i18n/message_en_US.properties
@@ -14,4 +14,4 @@
system_regist_error=Please contact the recommender to recommend registration.
-nft_active_001=Do Not Repeat Activation
\ No newline at end of file
+nft_active_001=NFT Has Expired
\ 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 c30d30e..7365839 100644
--- a/src/main/resources/i18n/message_zh_CN.properties
+++ b/src/main/resources/i18n/message_zh_CN.properties
@@ -13,4 +13,4 @@
system_regist_error=\u8BF7\u8054\u7CFB\u63A8\u8350\u4EBA\u63A8\u8350\u6CE8\u518C
-nft_active_001=\u8BF7\u52FF\u91CD\u590D\u6FC0\u6D3B
\ No newline at end of file
+nft_active_001=NFT\u5DF2\u8FC7\u671F
\ No newline at end of file
--
Gitblit v1.9.1