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(); } } 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; } 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; } 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); 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); }); 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; } 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 nft_active_001=NFT Has Expired 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 nft_active_001=NFT\u5DF2\u8FC7\u671F