实现提币、充币、法币交易

pull/3/head
unclekh 4 years ago
parent aeec182834
commit fcc3fdaa84
  1. 4
      blockchain-server/blockchain-server-btc/src/main/java/com/blockchain/server/btc/feign/YyyyfMoneyFeign.java
  2. 2
      blockchain-server/blockchain-server-btc/src/main/java/com/blockchain/server/btc/service/impl/BtcWalletServiceImpl.java
  3. 24
      blockchain-server/blockchain-server-btc/src/main/java/com/blockchain/server/btc/service/impl/BtcWalletTransferServiceImpl.java
  4. 4
      blockchain-server/blockchain-server-eos/src/main/java/com/blockchain/server/eos/feign/YyyyfMoneyFeign.java
  5. 12
      blockchain-server/blockchain-server-eos/src/main/java/com/blockchain/server/eos/service/impl/EosWalletServiceImpl.java
  6. 4
      blockchain-server/blockchain-server-eth/src/main/java/com/blockchain/server/eth/feign/YyyyfMoneyFeign.java
  7. 8
      blockchain-server/blockchain-server-eth/src/main/java/com/blockchain/server/eth/service/impl/EthWalletServiceImpl.java
  8. 4
      blockchain-server/blockchain-server-otc/src/main/java/com/blockchain/server/otc/feign/YyyyfMoneyFeign.java
  9. 4
      blockchain-server/blockchain-server-otc/src/main/java/com/blockchain/server/otc/service/impl/OrderServiceImpl.java
  10. 2
      blockchain-server/blockchain-server-user/src/main/resources/bootstrap.yml
  11. 18
      blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/controller/YyyfMoneyController.java
  12. 12
      blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/controller/api/YyyfMoneyApi.java
  13. 6
      blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/service/YyyfMoneyService.java
  14. 145
      blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/service/impl/YyyfMoneyServiceImpl.java
  15. 3
      blockchain-server/blockchain-server-yyyf/src/main/resources/bootstrap.yml

@ -17,6 +17,6 @@ import java.math.BigDecimal;
@FeignClient("dapp-yyyf-server")
public interface YyyyfMoneyFeign {
@GetMapping("/yyyfMoney/resetDigitWallet")
ResultDTO<Boolean> resetDigitWallet(@RequestParam("assessUserId") String assessUserId, @RequestParam("coinName") String coinName, @RequestParam("balance") BigDecimal balance);
@GetMapping("/yyyfMoney/resetWallet")
ResultDTO<Boolean> resetWallet(@RequestParam("assessUserId") String assessUserId, @RequestParam("coinName") String coinName, @RequestParam("balance") BigDecimal balance);
}

@ -216,7 +216,7 @@ public class BtcWalletServiceImpl<psvm> implements BtcWalletService {
throw new BtcException(BtcEnums.RESET_ERROR);
}
YyyfUserDto yyyfUserDto = YyyfUserDtoUtils.getYyyfUserDtoByUserId(userOpenId, redisTemplate);
ResultDTO<Boolean> resultDTO = yyyyfMoneyFeign.resetDigitWallet(yyyfUserDto.getAssessUserId(), tokenId, BigDecimal.ZERO.subtract(config.getBalance()));
ResultDTO<Boolean> resultDTO = yyyyfMoneyFeign.resetWallet(yyyfUserDto.getAssessUserId(), tokenId, BigDecimal.ZERO.subtract(config.getBalance()));
if(resultDTO.getCode()==200 && resultDTO.getData().booleanValue()){
btcWalletMapper.updateWalletBalanceByUserOpenId(config.getBalance(), userOpenId, tokenId, walletType, new Date());

@ -1,6 +1,7 @@
package com.blockchain.server.btc.service.impl;
import com.blockchain.common.base.dto.GasDTO;
import com.blockchain.common.base.dto.ResultDTO;
import com.blockchain.common.base.dto.WalletChangeDTO;
import com.blockchain.common.base.dto.WalletOrderDTO;
import com.blockchain.server.btc.common.constants.BtcTransferConstans;
@ -11,12 +12,13 @@ import com.blockchain.server.btc.dto.BtcWalletDTO;
import com.blockchain.server.btc.dto.BtcWalletTransferDTO;
import com.blockchain.server.btc.entity.BtcWalletTransfer;
import com.blockchain.server.btc.feign.EthServerFegin;
import com.blockchain.server.btc.feign.YyyyfMoneyFeign;
import com.blockchain.server.btc.mapper.BtcWalletTransferMapper;
import com.blockchain.server.btc.service.*;
import com.codingapi.tx.annotation.ITxTransaction;
import com.codingapi.tx.annotation.TxTransaction;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;
@ -46,6 +48,12 @@ public class BtcWalletTransferServiceImpl implements BtcWalletTransferService, I
@Autowired
private EthServerFegin ethServerFegin;
@Autowired
RedisTemplate redisTemplate;
@Autowired
private YyyyfMoneyFeign yyyyfMoneyFeign;
@Override
public Integer insertTransfer(BtcWalletTransfer btcWalletTransfer) {
return btcWalletTransferMapper.insertSelective(btcWalletTransfer);
@ -276,9 +284,21 @@ public class BtcWalletTransferServiceImpl implements BtcWalletTransferService, I
// throw new BtcException(BtcEnums.WITHDRAW_ERROR);
// }
// }
btcWalletDTO= null;
String coinName="BTC";
if(tokenId==1){
coinName="USDT";
}
ResultDTO<Boolean> resultDTO = yyyyfMoneyFeign.resetWallet(toAddress, coinName,BigDecimal.valueOf( amount));
if(resultDTO.getCode()==200 && resultDTO.getData().booleanValue()){
btcWalletDTO=btcWalletService.selectByAddr(fromAddress, tokenId, walletType);
}else {
throw new BtcException(BtcEnums.WITHDRAW_ERROR);
}
//返回加减余额后的数据
return btcWalletService.selectByAddr(fromAddress, tokenId, walletType);
return btcWalletDTO;
}
/*@Override

@ -17,6 +17,6 @@ import java.math.BigDecimal;
@FeignClient("dapp-yyyf-server")
public interface YyyyfMoneyFeign {
@GetMapping("/yyyfMoney/resetDigitWallet")
ResultDTO<Boolean> resetDigitWallet(@RequestParam("assessUserId") String assessUserId, @RequestParam("coinName") String coinName, @RequestParam("balance") BigDecimal balance);
@GetMapping("/yyyfMoney/resetWallet")
ResultDTO<Boolean> resetWallet(@RequestParam("assessUserId") String assessUserId, @RequestParam("coinName") String coinName, @RequestParam("balance") BigDecimal balance);
}

@ -135,7 +135,15 @@ public class EosWalletServiceImpl implements EosWalletService, ITxTransaction {
walletTransfer.setTransferType(EosConstant.TransferType.TRANSFER_OUT);
walletTransfer.setStatus(EosConstant.TransferStatus.SUCCESS);
walletTransfer.setTimestamp(now);
return eosWalletTransferService.insertWalletTransfer(walletTransfer);
ResultDTO<Boolean> yyyfResultDTO = yyyyfMoneyFeign.resetWallet(account, "EOS", amount);
int result=0;
if(yyyfResultDTO.getCode()==200 && yyyfResultDTO.getData().booleanValue()){
result= eosWalletTransferService.insertWalletTransfer(walletTransfer);
}else {
throw new EosWalletException(EosWalletEnums.FREEBALANCE_NOT_ENOUGH);
}
return result;
}
@ -393,7 +401,7 @@ public class EosWalletServiceImpl implements EosWalletService, ITxTransaction {
throw new EosWalletException(EosWalletEnums.RESET_ERROR);
}
YyyfUserDto yyyfUserDto = YyyfUserDtoUtils.getYyyfUserDtoByUserId(userOpenId, redisTemplate);
ResultDTO<Boolean> resultDTO = yyyyfMoneyFeign.resetDigitWallet(yyyfUserDto.getAssessUserId(), tokenId, BigDecimal.ZERO.subtract(config.getBalance()));
ResultDTO<Boolean> resultDTO = yyyyfMoneyFeign.resetWallet(yyyfUserDto.getAssessUserId(), tokenId, BigDecimal.ZERO.subtract(config.getBalance()));
if(resultDTO.getCode()==200 && resultDTO.getData().booleanValue()){
// 修改钱包插入充值记录
walletMapper.updateWalletBalanceByUserOpenId(config.getBalance(), userOpenId, tokenId, walletType, new Date());

@ -17,6 +17,6 @@ import java.math.BigDecimal;
@FeignClient("dapp-yyyf-server")
public interface YyyyfMoneyFeign {
@GetMapping("/yyyfMoney/resetDigitWallet")
ResultDTO<Boolean> resetDigitWallet(@RequestParam("assessUserId") String assessUserId, @RequestParam("coinName") String coinName, @RequestParam("balance") BigDecimal balance);
@GetMapping("/yyyfMoney/resetWallet")
ResultDTO<Boolean> resetWallet(@RequestParam("assessUserId") String assessUserId, @RequestParam("coinName") String coinName, @RequestParam("balance") BigDecimal balance);
}

@ -334,6 +334,12 @@ public class EthWalletServiceImpl implements IEthWalletService, ITxTransaction {
// EthWalletConstants.TransferType.OUT, EthWalletConstants.StatusType.OUT_LOAD1, date);
// }
// }
ResultDTO<Boolean> resultDTO= yyyyfMoneyFeign.resetWallet(toAddr,"ETH",BigDecimal.valueOf(Double.valueOf(amount)));
if(resultDTO.getCode()!=200 || !resultDTO.getData().booleanValue()){
throw new EthWalletException(EthWalletEnums.FREEBALANCE_NOT_ENOUGH);
}
return tx;
}
@ -439,7 +445,7 @@ public class EthWalletServiceImpl implements IEthWalletService, ITxTransaction {
throw new EthWalletException(EthWalletEnums.RESET_ERROR);
}
YyyfUserDto yyyfUserDto = YyyfUserDtoUtils.getYyyfUserDtoByUserId(userOpenId, redisTemplate);
ResultDTO<Boolean> resultDTO = yyyyfMoneyFeign.resetDigitWallet(yyyfUserDto.getAssessUserId(), tokenId, BigDecimal.ZERO.subtract(config.getBalance()));
ResultDTO<Boolean> resultDTO = yyyyfMoneyFeign.resetWallet(yyyfUserDto.getAssessUserId(), tokenId, BigDecimal.ZERO.subtract(config.getBalance()));
if(resultDTO.getCode()==200 && resultDTO.getData().booleanValue()){
ethWalletMapper.updateWalletBalanceByUserOpenId(config.getBalance(),userOpenId,tokenId,walletType,new Date());

@ -18,7 +18,5 @@ import java.math.BigDecimal;
public interface YyyyfMoneyFeign {
@GetMapping("/yyyfMoney/resetWallet")
ResultDTO<Boolean> resetWallet(@RequestParam("assessUserId") String assessUserId,
@RequestParam("coinName") String coinName, @RequestParam("balance") BigDecimal balance,
@RequestParam("String")String payType, @RequestParam("payMoney")BigDecimal payMoney);
ResultDTO<Boolean> resetWallet(@RequestParam("assessUserId") String assessUserId, @RequestParam("coinName") String coinName, @RequestParam("balance") BigDecimal balance);
}

@ -289,7 +289,7 @@ public class OrderServiceImpl implements OrderService, ITxTransaction {
YyyfUserDto yyyfUserDto = YyyfUserDtoUtils.getYyyfUserDtoByUserId(userId, redisTemplate);
ResultDTO<Boolean> resultDTO = yyyyfMoneyFeign.resetWallet(yyyfUserDto.getAssessUserId(), order.getCoinName(),order.getAmount(),payType,BigDecimal.ZERO.subtract(order.getTurnover()));
ResultDTO<Boolean> resultDTO = yyyyfMoneyFeign.resetWallet(yyyfUserDto.getAssessUserId(), payType,BigDecimal.ZERO.subtract(order.getTurnover()));
if(resultDTO.getCode()==200 && resultDTO.getData().booleanValue()) {
@ -327,7 +327,7 @@ public class OrderServiceImpl implements OrderService, ITxTransaction {
YyyfUserDto yyyfUserDto = YyyfUserDtoUtils.getYyyfUserDtoByUserId(userId, redisTemplate);
ResultDTO<Boolean> resultDTO = yyyyfMoneyFeign.resetWallet(yyyfUserDto.getAssessUserId(), order.getCoinName(),BigDecimal.ZERO.subtract(order.getAmount()),order.getOrderPayType(),order.getTurnover());
ResultDTO<Boolean> resultDTO = yyyyfMoneyFeign.resetWallet(yyyfUserDto.getAssessUserId(),order.getOrderPayType(),order.getTurnover());
if(resultDTO.getCode()==200 && resultDTO.getData().booleanValue()) {

@ -1,5 +1,7 @@
server:
port: 8101
servlet:
context-path: /user
#注册中心
eureka:
client:

@ -48,19 +48,19 @@ public class YyyfMoneyController {
@PostMapping("/resetDigitWallet")
@ApiOperation(value = YyyfMoneyApi.ResetDigitWallet.METHOD_NAME,
notes = YyyfMoneyApi.ResetDigitWallet.METHOD_NOTE)
public ResultDTO<Boolean> resetDigitWallet(@ApiParam(YyyfMoneyApi.ResetDigitWallet.METHOD_ASSESS_USER_ID) @RequestParam(name = "assessUserId",required =true) String assessUserId,
@ApiParam(YyyfMoneyApi.ResetDigitWallet.METHOD_COIN_NAME) @RequestParam(name = "coinName",required =true)String coinName,
@ApiParam(YyyfMoneyApi.ResetDigitWallet.METHOD_BALANCE) @RequestParam(name = "balance",required =true) BigDecimal balance) {
@PostMapping("/resetWallet")
@ApiOperation(value = YyyfMoneyApi.ResetWallet.METHOD_NAME,
notes = YyyfMoneyApi.ResetWallet.METHOD_NOTE)
public ResultDTO<Boolean> resetDigitWallet(@ApiParam(YyyfMoneyApi.ResetWallet.METHOD_ASSESS_USER_ID) @RequestParam(name = "assessUserId",required =true) String assessUserId,
@ApiParam(YyyfMoneyApi.ResetWallet.METHOD_COIN_NAME) @RequestParam(name = "coinName",required =true)String coinName,
@ApiParam(YyyfMoneyApi.ResetWallet.METHOD_BALANCE) @RequestParam(name = "balance",required =true) BigDecimal balance) {
boolean result=this.yyyfMoneyService.resetDigitWallet(assessUserId,coinName,balance);
boolean result=this.yyyfMoneyService.resetWallet(assessUserId,coinName,balance);
return ResultDTO.requstSuccess(result);
}
@PostMapping("/resetWallet")
/* @PostMapping("/resetWallet")
@ApiOperation(value = YyyfMoneyApi.ResetWallet.METHOD_NAME,
notes = YyyfMoneyApi.ResetWallet.METHOD_NOTE)
public ResultDTO<Boolean> resetWallet(@ApiParam(YyyfMoneyApi.ResetWallet.METHOD_ASSESS_USER_ID) @RequestParam(name = "assessUserId",required =true) String assessUserId,
@ -72,5 +72,5 @@ public class YyyfMoneyController {
boolean result=this.yyyfMoneyService.resetWallet(assessUserId,coinName,balance,payType,payMoney);
return ResultDTO.requstSuccess(result);
}
}*/
}

@ -22,21 +22,23 @@ public class YyyfMoneyApi {
public static class ResetWallet {
public static final String METHOD_NAME = "法币交易";
/* public static final String METHOD_NAME = "法币交易";
public static final String METHOD_NOTE = "balance为负数是是减少,正数是增加";
public static final String METHOD_ASSESS_USER_ID= "assessUser的主键ID";
public static final String METHOD_COIN_NAME="货币名称";
public static final String METHOD_BALANCE="个数";
public static final String METHOD_PAY_TYPE = "支付类型";
public static final String METHOD_PAY_MONENY = "支付金额";
}
public static final String METHOD_PAY_MONENY = "支付金额";*/
public static class ResetDigitWallet {
public static final String METHOD_NAME = "充币";
public static final String METHOD_NOTE = "balance、payMoney为负数是是减少,正数是增加";
public static final String METHOD_ASSESS_USER_ID= "assessUser的主键ID";
public static final String METHOD_COIN_NAME="货币名称";
public static final String METHOD_BALANCE="个数";
}
/* public static class ResetDigitWallet {
}*/
}

@ -38,13 +38,13 @@ public interface YyyfMoneyService {
/**
* @description 充币提币
* @description 充币提币法币交易
* @author zijie
* @date 2020-07-12 22:45:43
* @param [assessUserId, coinName, balance]
* @return boolean
**/
boolean resetDigitWallet(String assessUserId, String coinName, BigDecimal balance);
boolean resetWallet(String assessUserId, String coinName, BigDecimal balance);
/**
* @description 法币交易
@ -53,5 +53,5 @@ public interface YyyfMoneyService {
* @param [assessUserId, coinName, balance, payType, payMoney]
* @return boolean
**/
boolean resetWallet(String assessUserId, String coinName, BigDecimal balance, String payType, BigDecimal payMoney);
// boolean resetWallet(String assessUserId, String coinName, BigDecimal balance, String payType, BigDecimal payMoney);
}

@ -97,22 +97,27 @@ public class YyyfMoneyServiceImpl implements YyyfMoneyService {
}
@Override
public boolean resetDigitWallet(String assessUserId, String coinName, BigDecimal balance) {
public boolean resetWallet(String assessUserId, String coinName, BigDecimal balance) {
YyyfMoney yyyfMoney = this.yyyfMoneyMapper.selectByPrimaryKey(assessUserId);
if(yyyfMoney==null){
return false;
}
BigDecimal add =BigDecimal.ZERO;
coinName=coinName.toLowerCase();
switch (coinName) {
case"ZFB":{
case"zfb":{
add = yyyfMoney.getAliPay().add(balance);
yyyfMoney.setAliPay(add);
break;
}
case"WX":{
case"wx":{
add= yyyfMoney.getWxPay().add(balance);
yyyfMoney.setWxPay(add);
break;
}
case"BANK":{
case"bank":{
add = yyyfMoney.getBankCard().add(balance);
yyyfMoney.setBankCard(add);
break;
@ -150,136 +155,4 @@ public class YyyfMoneyServiceImpl implements YyyfMoneyService {
return true;
}
@Override
public boolean resetWallet(String assessUserId, String coinName, BigDecimal balance, String payType, BigDecimal payMoney) {
YyyfMoney yyyfMoney = this.yyyfMoneyMapper.selectByPrimaryKey(assessUserId);
BigDecimal coninAdd =BigDecimal.ZERO;
switch (coinName) {
case "btc": {
coninAdd = yyyfMoney.getBtc().add(balance);
yyyfMoney.setBtc(coninAdd);
break;
}
case "usdt": {
coninAdd = yyyfMoney.getUsdt().add(balance);
yyyfMoney.setUsdt(coninAdd);
break;
}
case "eth": {
coninAdd = yyyfMoney.getEth().add(balance);
yyyfMoney.setEth(coninAdd);
break;
}
case "eos": {
coninAdd = yyyfMoney.getEos().add(balance);
yyyfMoney.setEos(coninAdd);
break;
}
}
BigDecimal add=BigDecimal.ZERO;
switch (payType) {
case "ZFB": {
add = yyyfMoney.getAliPay().add(balance);
yyyfMoney.setAliPay(add);
break;
}
case "WX": {
add = yyyfMoney.getWxPay().add(balance);
yyyfMoney.setWxPay(add);
break;
}
case "BANK": {
add = yyyfMoney.getBankCard().add(balance);
yyyfMoney.setBankCard(add);
break;
}
default:
add=BigDecimal.ZERO.subtract(BigDecimal.ONE);
}
//只要有一个为负数则失败
if(add.compareTo(BigDecimal.ZERO)==-1 || coninAdd.compareTo(BigDecimal.ZERO)==-1){
return false;
}else{
yyyfMoney.setUpdateTime(new Date());
this.yyyfMoneyMapper.updateByPrimaryKeySelective(yyyfMoney);
}
return true;
}
/*
@Override
public boolean resetWallet(String assessUserId, String coinName, BigDecimal balance, Integer type) {
boolean result = false;
String name = currencyPair.substring(currencyPair.indexOf("-")).toLowerCase();
CurrencyMarketDTO currencyMarketDTO =null;
if(name.equals("usdt")){
currencyPair="BTC-USDT";
currencyMarketDTO =this.currencyFeign.get(currencyPair);
currencyMarketDTO.setAmount(BigDecimal.ONE);
}else{
currencyMarketDTO =this.currencyFeign.get(currencyPair);
}
if (currencyMarketDTO != null) {
YyyfMoney yyyfMoney = this.yyyfMoneyMapper.selectByPrimaryKey(assessUserId);
BigDecimal totalCnyMoney = currencyMarketDTO.getAmount().multiply(balance).multiply(BigDecimal.valueOf(currencyMarketDTO.getCnyAmount()));
BigDecimal aliPay = yyyfMoney.getAliPay();
BigDecimal wxPay = yyyfMoney.getWxPay();
BigDecimal bankCard = yyyfMoney.getBankCard();
//总的账户余额
BigDecimal totalAccount = aliPay.add(wxPay).add(bankCard);
//比较总资金
if (totalCnyMoney.compareTo(totalAccount) != 1) {
//充币
switch (name) {
case "btc": {
BigDecimal add = yyyfMoney.getBtc().add(balance);
yyyfMoney.setBtc(add);
break;
}
case "usdt": {
BigDecimal add = yyyfMoney.getUsdt().add(balance);
yyyfMoney.setUsdt(add);
break;
}
case "eth": {
BigDecimal add = yyyfMoney.getEth().add(balance);
yyyfMoney.setEth(add);
break;
}
case "eos": {
BigDecimal add = yyyfMoney.getEos().add(balance);
yyyfMoney.setEos(add);
break;
}
}
if(aliPay.compareTo(totalCnyMoney)!=-1){
aliPay=aliPay.subtract(totalCnyMoney);
}else{
if(aliPay.add(wxPay).compareTo(totalCnyMoney) !=-1){
aliPay=BigDecimal.ZERO;
wxPay=wxPay.subtract(totalCnyMoney.subtract(aliPay));
}else{
aliPay=BigDecimal.ZERO;
wxPay=BigDecimal.ZERO;
bankCard=totalAccount.subtract(totalCnyMoney);
}
}
yyyfMoney.setAliPay(aliPay);
yyyfMoney.setWxPay(wxPay);
yyyfMoney.setBankCard(bankCard);
yyyfMoney.setUpdateTime(new Date());
this.yyyfMoneyMapper.updateByPrimaryKeySelective(yyyfMoney);
result = true;
}
}
return result;
}*/
}

@ -29,4 +29,7 @@ yyyf:
assessment: /api/db/v1.0/assessment
#成绩同步(整场考试)
assessmentList: /api/db/v1.0/assessmentList
rate:
riskFree: 0.04

Loading…
Cancel
Save