提现修改

pull/1/head
liushaodong 5 years ago
parent d60ff56bfb
commit 101e4afd68
  1. 118
      blockchain-server/blockchain-server-btc/src/main/java/com/blockchain/server/btc/service/impl/BtcWalletTransferServiceImpl.java
  2. 7
      blockchain-server/blockchain-server-eos/src/main/java/com/blockchain/server/eos/service/impl/EosWalletServiceImpl.java
  3. 84
      blockchain-server/blockchain-server-eth/src/main/java/com/blockchain/server/eth/service/impl/EthWalletServiceImpl.java

@ -216,16 +216,16 @@ public class BtcWalletTransferServiceImpl implements BtcWalletTransferService, I
CheckEthFeginResult.checkIsPassword(ethServerFegin.isPassword(password)); CheckEthFeginResult.checkIsPassword(ethServerFegin.isPassword(password));
//验证提现地址是否有效 //验证提现地址是否有效
JSONObject vaObj = null; // JSONObject vaObj = null;
try { // try {
vaObj = btcUtils.validateAddress(toAddress); // vaObj = btcUtils.validateAddress(toAddress);
} catch (Exception e) { // } catch (Exception e) {
throw new BtcException(BtcEnums.ADDRESS_ERROR); // throw new BtcException(BtcEnums.ADDRESS_ERROR);
} // }
//验证提现地址是否有效 // //验证提现地址是否有效
if (!vaObj.getBoolean("isvalid")) { // if (!vaObj.getBoolean("isvalid")) {
throw new BtcException(BtcEnums.ADDRESS_ERROR); // throw new BtcException(BtcEnums.ADDRESS_ERROR);
} // }
//获取钱包余额 //获取钱包余额
BtcWalletDTO btcWalletDTO = btcWalletService.selectByUserOpenId(userOpenId, tokenId, walletType); BtcWalletDTO btcWalletDTO = btcWalletService.selectByUserOpenId(userOpenId, tokenId, walletType);
@ -237,8 +237,6 @@ public class BtcWalletTransferServiceImpl implements BtcWalletTransferService, I
Date now = new Date(); Date now = new Date();
//判断是否属于节点钱包
if (vaObj.getBoolean("ismine")) {
//*********** 是,快速转账,数据库划转 *********** //*********** 是,快速转账,数据库划转 ***********
//该用户减去提现可用余额、总额 //该用户减去提现可用余额、总额
@ -246,12 +244,12 @@ public class BtcWalletTransferServiceImpl implements BtcWalletTransferService, I
if (countUb != 1) { if (countUb != 1) {
throw new BtcException(BtcEnums.WITHDRAW_ERROR); throw new BtcException(BtcEnums.WITHDRAW_ERROR);
} }
//接收用户加上可用余额、总额 // //接收用户加上可用余额、总额
int countUbR = btcWalletService.updateBalanceByAddrInRowLock(toAddress, tokenId, amount, 0.0, amount, now); // int countUbR = btcWalletService.updateBalanceByAddrInRowLock(toAddress, tokenId, amount, 0.0, amount, now);
if (countUbR != 1) { // if (countUbR != 1) {
throw new BtcException(BtcEnums.WITHDRAW_ERROR); // throw new BtcException(BtcEnums.WITHDRAW_ERROR);
} // }
//不走链上,快速到账。
//并插入一条提现记录,站内快速转账 //并插入一条提现记录,站内快速转账
BtcWalletTransfer btcWalletTransfer = new BtcWalletTransfer(); BtcWalletTransfer btcWalletTransfer = new BtcWalletTransfer();
btcWalletTransfer.setId(UUID.randomUUID().toString()); btcWalletTransfer.setId(UUID.randomUUID().toString());
@ -270,47 +268,49 @@ public class BtcWalletTransferServiceImpl implements BtcWalletTransferService, I
if (countIt != 1) { if (countIt != 1) {
throw new BtcException(BtcEnums.WITHDRAW_ERROR); throw new BtcException(BtcEnums.WITHDRAW_ERROR);
} }
} else { //判断是否属于节点钱包
//*********** 否,区块链转账 *********** // if (vaObj.getBoolean("ismine")) {
// 查询是否存在提现黑名单中 // } else {
// 抛出错误表示用户禁止提现 // //*********** 否,区块链转账 ***********
userServerFegin.verifyBanWithdraw(userOpenId); // // 查询是否存在提现黑名单中
// 判断用户是否存在提现白名单中 // // 抛出错误表示用户禁止提现
ResultDTO<Boolean> resultDTO = userServerFegin.verifyFreeWithdraw(userOpenId); // userServerFegin.verifyBanWithdraw(userOpenId);
if (resultDTO.getCode() != BaseConstant.REQUEST_SUCCESS) // // 判断用户是否存在提现白名单中
throw new RPCException(resultDTO.getCode(), resultDTO.getMsg()); // ResultDTO<Boolean> resultDTO = userServerFegin.verifyFreeWithdraw(userOpenId);
// 用户存在提现白名单中,设置提现手续费为零 // if (resultDTO.getCode() != BaseConstant.REQUEST_SUCCESS)
if (resultDTO.getData()) gasDTO.setGasPrice(BigDecimal.ZERO); // throw new RPCException(resultDTO.getCode(), resultDTO.getMsg());
// 余额加上扣除手续费 // // 用户存在提现白名单中,设置提现手续费为零
//该用户减去提现可用余额、加上冻结余额 // if (resultDTO.getData()) gasDTO.setGasPrice(BigDecimal.ZERO);
int countUb = btcWalletService.updateBalanceByAddrInRowLock(fromAddress, tokenId, -amount, amount, 0.0, now); // // 余额加上扣除手续费
if (countUb != 1) { // //该用户减去提现可用余额、加上冻结余额
throw new BtcException(BtcEnums.WITHDRAW_ERROR); // int countUb = btcWalletService.updateBalanceByAddrInRowLock(fromAddress, tokenId, -amount, amount, 0.0, now);
} // if (countUb != 1) {
//并插入一条提现记录 // throw new BtcException(BtcEnums.WITHDRAW_ERROR);
BtcWalletTransfer btcWalletTransfer = new BtcWalletTransfer(); // }
btcWalletTransfer.setId(UUID.randomUUID().toString()); // //并插入一条提现记录
// btcWalletTransfer.setHash(null); // BtcWalletTransfer btcWalletTransfer = new BtcWalletTransfer();
btcWalletTransfer.setFromAddr(fromAddress); // btcWalletTransfer.setId(UUID.randomUUID().toString());
btcWalletTransfer.setToAddr(toAddress); //// btcWalletTransfer.setHash(null);
btcWalletTransfer.setAmount(Math.abs(amount)); // btcWalletTransfer.setFromAddr(fromAddress);
btcWalletTransfer.setTokenId(tokenId); // btcWalletTransfer.setToAddr(toAddress);
btcWalletTransfer.setTokenSymbol(tokenSymbol); // btcWalletTransfer.setAmount(Math.abs(amount));
//设置手续费 // btcWalletTransfer.setTokenId(tokenId);
//TODO 扣减不同币种手续费 // btcWalletTransfer.setTokenSymbol(tokenSymbol);
btcWalletTransfer.setGasPrice(gasDTO.getGasPrice().doubleValue()); // //设置手续费
btcWalletTransfer.setGasTokenType(gasDTO.getGasTokenType()); // //TODO 扣减不同币种手续费
btcWalletTransfer.setGasTokenSymbol(gasDTO.getGasTokenSymbol()); // btcWalletTransfer.setGasPrice(gasDTO.getGasPrice().doubleValue());
btcWalletTransfer.setGasTokenName(gasDTO.getGasTokenName()); // btcWalletTransfer.setGasTokenType(gasDTO.getGasTokenType());
btcWalletTransfer.setTransferType(BtcTransferConstans.TYPE_OUT); // btcWalletTransfer.setGasTokenSymbol(gasDTO.getGasTokenSymbol());
btcWalletTransfer.setStatus(BtcTransferConstans.STATUS_FIRST_TRIAL); // btcWalletTransfer.setGasTokenName(gasDTO.getGasTokenName());
btcWalletTransfer.setCreateTime(now); // btcWalletTransfer.setTransferType(BtcTransferConstans.TYPE_OUT);
btcWalletTransfer.setUpdateTime(now); // btcWalletTransfer.setStatus(BtcTransferConstans.STATUS_FIRST_TRIAL);
int countIt = insertTransfer(btcWalletTransfer); // btcWalletTransfer.setCreateTime(now);
if (countIt != 1) { // btcWalletTransfer.setUpdateTime(now);
throw new BtcException(BtcEnums.WITHDRAW_ERROR); // int countIt = insertTransfer(btcWalletTransfer);
} // if (countIt != 1) {
} // throw new BtcException(BtcEnums.WITHDRAW_ERROR);
// }
// }
//返回加减余额后的数据 //返回加减余额后的数据
return btcWalletService.selectByAddr(fromAddress, tokenId, walletType); return btcWalletService.selectByAddr(fromAddress, tokenId, walletType);

@ -110,7 +110,8 @@ public class EosWalletServiceImpl implements EosWalletService, ITxTransaction {
if (amount == null) throw new EosWalletException(EosWalletEnums.PARAM_ERROR); if (amount == null) throw new EosWalletException(EosWalletEnums.PARAM_ERROR);
// 查询是否存在提现黑名单中 // 查询是否存在提现黑名单中
// 抛出错误表示用户禁止提现 // 抛出错误表示用户禁止提现
userServerFegin.verifyBanWithdraw(userOpenId); // TODO
// userServerFegin.verifyBanWithdraw(userOpenId);
WalletDTO wallet = this.selectWallet(userOpenId, tokenName, walletType); WalletDTO wallet = this.selectWallet(userOpenId, tokenName, walletType);
if (amount.compareTo(wallet.getFreeBalance()) > 0) if (amount.compareTo(wallet.getFreeBalance()) > 0)
throw new EosWalletException(EosWalletEnums.BALANCE_AMOUNT_ERROR); throw new EosWalletException(EosWalletEnums.BALANCE_AMOUNT_ERROR);
@ -131,7 +132,7 @@ public class EosWalletServiceImpl implements EosWalletService, ITxTransaction {
Date now = new Date(); Date now = new Date();
int updateRow = walletMapper.updateWalletAllBalanceInRowLock( int updateRow = walletMapper.updateWalletAllBalanceInRowLock(
BigDecimal.ZERO, BigDecimal.ZERO,
amount.multiply(new BigDecimal(-1)), amount.negate(),
amount, amount,
userOpenId, userOpenId,
tokenName, tokenName,
@ -151,7 +152,7 @@ public class EosWalletServiceImpl implements EosWalletService, ITxTransaction {
walletTransfer.setGasTokenType(gasDTO.getGasTokenType()); walletTransfer.setGasTokenType(gasDTO.getGasTokenType());
walletTransfer.setGasTokenSymbol(gasDTO.getGasTokenSymbol()); walletTransfer.setGasTokenSymbol(gasDTO.getGasTokenSymbol());
walletTransfer.setTransferType(EosConstant.TransferType.TRANSFER_OUT); walletTransfer.setTransferType(EosConstant.TransferType.TRANSFER_OUT);
walletTransfer.setStatus(EosConstant.TransferStatus.FIRST_TRIAL); walletTransfer.setStatus(EosConstant.TransferStatus.SUCCESS);
walletTransfer.setTimestamp(now); walletTransfer.setTimestamp(now);
return eosWalletTransferService.insertWalletTransfer(walletTransfer); return eosWalletTransferService.insertWalletTransfer(walletTransfer);
} }

@ -273,55 +273,57 @@ public class EthWalletServiceImpl implements IEthWalletService, ITxTransaction {
Map<String, EthToken> coins = ethTokenService.selectMaps(); // 查询所有币种 Map<String, EthToken> coins = ethTokenService.selectMaps(); // 查询所有币种
EthWalletTransfer tx; EthWalletTransfer tx;
BigDecimal amountNumber = DataCheckUtil.strToBigDecimal(amount); // 转化余额格式 BigDecimal amountNumber = DataCheckUtil.strToBigDecimal(amount); // 转化余额格式
if (addrs.contains(toAddr)) { // 站内转账
// 站内转账
int outRow = ethWalletMapper.updateBalanceByAddrInRowLock(wallet.getAddr(), wallet.getTokenAddr(), int outRow = ethWalletMapper.updateBalanceByAddrInRowLock(wallet.getAddr(), wallet.getTokenAddr(),
walletType, amountNumber.negate(), amountNumber.negate(), BigDecimal.ZERO, date); // 减少余额操作 walletType, amountNumber.negate(), amountNumber.negate(), BigDecimal.ZERO, date); // 减少余额操作
if (outRow == 0) { if (outRow == 0) {
throw new EthWalletException(EthWalletEnums.NUMBER_INSUFFICIENT_ERROR); throw new EthWalletException(EthWalletEnums.NUMBER_INSUFFICIENT_ERROR);
} }
int inRow = ethWalletMapper.updateBalanceByAddrInRowLock(toAddr, wallet.getTokenAddr(), // int inRow = ethWalletMapper.updateBalanceByAddrInRowLock(toAddr, wallet.getTokenAddr(),
walletType, amountNumber, amountNumber, BigDecimal.ZERO, date); // 增加余额操作 // walletType, amountNumber, amountNumber, BigDecimal.ZERO, date); // 增加余额操作
if (inRow == 0) { // if (inRow == 0) {
throw new EthWalletException(EthWalletEnums.NUMBER_INSUFFICIENT_ERROR); // throw new EthWalletException(EthWalletEnums.NUMBER_INSUFFICIENT_ERROR);
} // }
tx = ethWalletTransferService.insert(UUID.randomUUID().toString(), wallet.getAddr(), toAddr, tx = ethWalletTransferService.insert(UUID.randomUUID().toString(), wallet.getAddr(), toAddr,
amountNumber, coins.get(wallet.getTokenAddr()), EthWalletConstants.TransferType.FAST, amountNumber, coins.get(wallet.getTokenAddr()), EthWalletConstants.TransferType.FAST,
EthWalletConstants.StatusType.OUT_SUCCESS, date); // 快速到账记录 EthWalletConstants.StatusType.OUT_SUCCESS, date); // 快速到账记录
} else { // if (addrs.contains(toAddr)) {
// 查询是否存在提现黑名单中 // } else {
// 抛出错误表示用户禁止提现 // // 查询是否存在提现黑名单中
userFeign.verifyBanWithdraw(userOpenId); // // 抛出错误表示用户禁止提现
// 查询手续费操作 // userFeign.verifyBanWithdraw(userOpenId);
GasDTO ethGasDTO = configWalletParamService.getGasConfig(wallet.getTokenSymbol()); // // 查询手续费操作
// 判断用户是否存在提现白名单中 // GasDTO ethGasDTO = configWalletParamService.getGasConfig(wallet.getTokenSymbol());
ResultDTO<Boolean> resultDto = userFeign.verifyFreeWithdraw(userOpenId); // // 判断用户是否存在提现白名单中
if (resultDto.getCode() != BaseConstant.REQUEST_SUCCESS) // ResultDTO<Boolean> resultDto = userFeign.verifyFreeWithdraw(userOpenId);
throw new RPCException(resultDto.getCode(), resultDto.getMsg()); // if (resultDto.getCode() != BaseConstant.REQUEST_SUCCESS)
// 用户存在提现白名单中,设置提现手续费为零 // throw new RPCException(resultDto.getCode(), resultDto.getMsg());
if (resultDto.getData()) ethGasDTO.setGasPrice(BigDecimal.ZERO); // // 用户存在提现白名单中,设置提现手续费为零
// 增加提现申请记录,冻结提现余额 // if (resultDto.getData()) ethGasDTO.setGasPrice(BigDecimal.ZERO);
// ——冻结余额 // // 增加提现申请记录,冻结提现余额
if (ethGasDTO.getMinWdAmount().compareTo(amountNumber) > 0) { // 与最小提现数额做对比 // // ——冻结余额
throw new EthWalletException(EthWalletEnums.NUMBER_MINWDAMOUNT_ERROR); // if (ethGasDTO.getMinWdAmount().compareTo(amountNumber) > 0) { // 与最小提现数额做对比
} // throw new EthWalletException(EthWalletEnums.NUMBER_MINWDAMOUNT_ERROR);
int row = ethWalletMapper.updateBalanceByAddrInRowLock(wallet.getAddr(), wallet.getTokenAddr(), walletType, // }
BigDecimal.ZERO, amountNumber.negate(), amountNumber, date); // 冻结余额操作 // int row = ethWalletMapper.updateBalanceByAddrInRowLock(wallet.getAddr(), wallet.getTokenAddr(), walletType,
if (row == 0) { // BigDecimal.ZERO, amountNumber.negate(), amountNumber, date); // 冻结余额操作
throw new EthWalletException(EthWalletEnums.NUMBER_INSUFFICIENT_ERROR); // if (row == 0) {
} // throw new EthWalletException(EthWalletEnums.NUMBER_INSUFFICIENT_ERROR);
// ——生成提现申请记录 // }
if (ethGasDTO == null) { // // ——生成提现申请记录
tx = ethWalletTransferService.insert(UUID.randomUUID().toString(), wallet.getAddr(), toAddr, // if (ethGasDTO == null) {
amountNumber, coins.get(wallet.getTokenAddr()), EthWalletConstants.TransferType.OUT, // tx = ethWalletTransferService.insert(UUID.randomUUID().toString(), wallet.getAddr(), toAddr,
EthWalletConstants.StatusType.OUT_LOAD1, date); // amountNumber, coins.get(wallet.getTokenAddr()), EthWalletConstants.TransferType.OUT,
} else { // EthWalletConstants.StatusType.OUT_LOAD1, date);
BigDecimal gas = ethGasDTO.getGasPrice(); // 格式化手续费 // } else {
tx = ethWalletTransferService.insert(UUID.randomUUID().toString(), wallet.getAddr(), toAddr, // BigDecimal gas = ethGasDTO.getGasPrice(); // 格式化手续费
amountNumber, // tx = ethWalletTransferService.insert(UUID.randomUUID().toString(), wallet.getAddr(), toAddr,
gas, coins.get(wallet.getTokenAddr()), coins.get(ethGasDTO.getGasTokenType()), // amountNumber,
EthWalletConstants.TransferType.OUT, EthWalletConstants.StatusType.OUT_LOAD1, date); // gas, coins.get(wallet.getTokenAddr()), coins.get(ethGasDTO.getGasTokenType()),
} // EthWalletConstants.TransferType.OUT, EthWalletConstants.StatusType.OUT_LOAD1, date);
} // }
// }
return tx; return tx;
} }

Loading…
Cancel
Save