提现修改

pull/1/head
liushaodong 5 years ago
parent d60ff56bfb
commit 101e4afd68
  1. 160
      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. 98
      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));
//验证提现地址是否有效
JSONObject vaObj = null;
try {
vaObj = btcUtils.validateAddress(toAddress);
} catch (Exception e) {
throw new BtcException(BtcEnums.ADDRESS_ERROR);
}
//验证提现地址是否有效
if (!vaObj.getBoolean("isvalid")) {
throw new BtcException(BtcEnums.ADDRESS_ERROR);
}
// JSONObject vaObj = null;
// try {
// vaObj = btcUtils.validateAddress(toAddress);
// } catch (Exception e) {
// throw new BtcException(BtcEnums.ADDRESS_ERROR);
// }
// //验证提现地址是否有效
// if (!vaObj.getBoolean("isvalid")) {
// throw new BtcException(BtcEnums.ADDRESS_ERROR);
// }
//获取钱包余额
BtcWalletDTO btcWalletDTO = btcWalletService.selectByUserOpenId(userOpenId, tokenId, walletType);
@ -237,80 +237,80 @@ public class BtcWalletTransferServiceImpl implements BtcWalletTransferService, I
Date now = new Date();
//判断是否属于节点钱包
if (vaObj.getBoolean("ismine")) {
//*********** 是,快速转账,数据库划转 ***********
//该用户减去提现可用余额、总额
int countUb = btcWalletService.updateBalanceByAddrInRowLock(fromAddress, tokenId, -amount, 0.0, -amount, now);
if (countUb != 1) {
throw new BtcException(BtcEnums.WITHDRAW_ERROR);
}
//接收用户加上可用余额、总额
int countUbR = btcWalletService.updateBalanceByAddrInRowLock(toAddress, tokenId, amount, 0.0, amount, now);
if (countUbR != 1) {
throw new BtcException(BtcEnums.WITHDRAW_ERROR);
}
//*********** 是,快速转账,数据库划转 ***********
//并插入一条提现记录,站内快速转账
BtcWalletTransfer btcWalletTransfer = new BtcWalletTransfer();
btcWalletTransfer.setId(UUID.randomUUID().toString());
//该用户减去提现可用余额、总额
int countUb = btcWalletService.updateBalanceByAddrInRowLock(fromAddress, tokenId, -amount, 0.0, -amount, now);
if (countUb != 1) {
throw new BtcException(BtcEnums.WITHDRAW_ERROR);
}
// //接收用户加上可用余额、总额
// int countUbR = btcWalletService.updateBalanceByAddrInRowLock(toAddress, tokenId, amount, 0.0, amount, now);
// if (countUbR != 1) {
// throw new BtcException(BtcEnums.WITHDRAW_ERROR);
// }
//不走链上,快速到账。
//并插入一条提现记录,站内快速转账
BtcWalletTransfer btcWalletTransfer = new BtcWalletTransfer();
btcWalletTransfer.setId(UUID.randomUUID().toString());
// btcWalletTransfer.setHash(null);
btcWalletTransfer.setFromAddr(fromAddress);
btcWalletTransfer.setToAddr(toAddress);
btcWalletTransfer.setAmount(Math.abs(amount));
btcWalletTransfer.setFromAddr(fromAddress);
btcWalletTransfer.setToAddr(toAddress);
btcWalletTransfer.setAmount(Math.abs(amount));
// btcWalletTransfer.setGasPrice(null);
btcWalletTransfer.setTokenId(tokenId);
btcWalletTransfer.setTokenSymbol(tokenSymbol);
btcWalletTransfer.setTransferType(BtcTransferConstans.TYPE_FAST);
btcWalletTransfer.setStatus(BtcTransferConstans.STATUS_SUCCESS);
btcWalletTransfer.setCreateTime(now);
btcWalletTransfer.setUpdateTime(now);
int countIt = insertTransfer(btcWalletTransfer);
if (countIt != 1) {
throw new BtcException(BtcEnums.WITHDRAW_ERROR);
}
} else {
//*********** 否,区块链转账 ***********
// 查询是否存在提现黑名单中
// 抛出错误表示用户禁止提现
userServerFegin.verifyBanWithdraw(userOpenId);
// 判断用户是否存在提现白名单中
ResultDTO<Boolean> resultDTO = userServerFegin.verifyFreeWithdraw(userOpenId);
if (resultDTO.getCode() != BaseConstant.REQUEST_SUCCESS)
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);
}
//并插入一条提现记录
BtcWalletTransfer btcWalletTransfer = new BtcWalletTransfer();
btcWalletTransfer.setId(UUID.randomUUID().toString());
// btcWalletTransfer.setHash(null);
btcWalletTransfer.setFromAddr(fromAddress);
btcWalletTransfer.setToAddr(toAddress);
btcWalletTransfer.setAmount(Math.abs(amount));
btcWalletTransfer.setTokenId(tokenId);
btcWalletTransfer.setTokenSymbol(tokenSymbol);
//设置手续费
//TODO 扣减不同币种手续费
btcWalletTransfer.setGasPrice(gasDTO.getGasPrice().doubleValue());
btcWalletTransfer.setGasTokenType(gasDTO.getGasTokenType());
btcWalletTransfer.setGasTokenSymbol(gasDTO.getGasTokenSymbol());
btcWalletTransfer.setGasTokenName(gasDTO.getGasTokenName());
btcWalletTransfer.setTransferType(BtcTransferConstans.TYPE_OUT);
btcWalletTransfer.setStatus(BtcTransferConstans.STATUS_FIRST_TRIAL);
btcWalletTransfer.setCreateTime(now);
btcWalletTransfer.setUpdateTime(now);
int countIt = insertTransfer(btcWalletTransfer);
if (countIt != 1) {
throw new BtcException(BtcEnums.WITHDRAW_ERROR);
}
btcWalletTransfer.setTokenId(tokenId);
btcWalletTransfer.setTokenSymbol(tokenSymbol);
btcWalletTransfer.setTransferType(BtcTransferConstans.TYPE_FAST);
btcWalletTransfer.setStatus(BtcTransferConstans.STATUS_SUCCESS);
btcWalletTransfer.setCreateTime(now);
btcWalletTransfer.setUpdateTime(now);
int countIt = insertTransfer(btcWalletTransfer);
if (countIt != 1) {
throw new BtcException(BtcEnums.WITHDRAW_ERROR);
}
//判断是否属于节点钱包
// if (vaObj.getBoolean("ismine")) {
// } else {
// //*********** 否,区块链转账 ***********
// // 查询是否存在提现黑名单中
// // 抛出错误表示用户禁止提现
// userServerFegin.verifyBanWithdraw(userOpenId);
// // 判断用户是否存在提现白名单中
// ResultDTO<Boolean> resultDTO = userServerFegin.verifyFreeWithdraw(userOpenId);
// if (resultDTO.getCode() != BaseConstant.REQUEST_SUCCESS)
// 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);
// }
// //并插入一条提现记录
// BtcWalletTransfer btcWalletTransfer = new BtcWalletTransfer();
// btcWalletTransfer.setId(UUID.randomUUID().toString());
//// btcWalletTransfer.setHash(null);
// btcWalletTransfer.setFromAddr(fromAddress);
// btcWalletTransfer.setToAddr(toAddress);
// btcWalletTransfer.setAmount(Math.abs(amount));
// btcWalletTransfer.setTokenId(tokenId);
// btcWalletTransfer.setTokenSymbol(tokenSymbol);
// //设置手续费
// //TODO 扣减不同币种手续费
// btcWalletTransfer.setGasPrice(gasDTO.getGasPrice().doubleValue());
// btcWalletTransfer.setGasTokenType(gasDTO.getGasTokenType());
// btcWalletTransfer.setGasTokenSymbol(gasDTO.getGasTokenSymbol());
// btcWalletTransfer.setGasTokenName(gasDTO.getGasTokenName());
// btcWalletTransfer.setTransferType(BtcTransferConstans.TYPE_OUT);
// btcWalletTransfer.setStatus(BtcTransferConstans.STATUS_FIRST_TRIAL);
// btcWalletTransfer.setCreateTime(now);
// btcWalletTransfer.setUpdateTime(now);
// int countIt = insertTransfer(btcWalletTransfer);
// if (countIt != 1) {
// throw new BtcException(BtcEnums.WITHDRAW_ERROR);
// }
// }
//返回加减余额后的数据
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);
// 查询是否存在提现黑名单中
// 抛出错误表示用户禁止提现
userServerFegin.verifyBanWithdraw(userOpenId);
// TODO
// userServerFegin.verifyBanWithdraw(userOpenId);
WalletDTO wallet = this.selectWallet(userOpenId, tokenName, walletType);
if (amount.compareTo(wallet.getFreeBalance()) > 0)
throw new EosWalletException(EosWalletEnums.BALANCE_AMOUNT_ERROR);
@ -131,7 +132,7 @@ public class EosWalletServiceImpl implements EosWalletService, ITxTransaction {
Date now = new Date();
int updateRow = walletMapper.updateWalletAllBalanceInRowLock(
BigDecimal.ZERO,
amount.multiply(new BigDecimal(-1)),
amount.negate(),
amount,
userOpenId,
tokenName,
@ -151,7 +152,7 @@ public class EosWalletServiceImpl implements EosWalletService, ITxTransaction {
walletTransfer.setGasTokenType(gasDTO.getGasTokenType());
walletTransfer.setGasTokenSymbol(gasDTO.getGasTokenSymbol());
walletTransfer.setTransferType(EosConstant.TransferType.TRANSFER_OUT);
walletTransfer.setStatus(EosConstant.TransferStatus.FIRST_TRIAL);
walletTransfer.setStatus(EosConstant.TransferStatus.SUCCESS);
walletTransfer.setTimestamp(now);
return eosWalletTransferService.insertWalletTransfer(walletTransfer);
}

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

Loading…
Cancel
Save