充币、法币交易后台实现

pull/3/head
unclekh 4 years ago
parent 2298799078
commit aeec182834
  1. 22
      blockchain-server/blockchain-server-btc/src/main/java/com/blockchain/server/btc/feign/YyyyfMoneyFeign.java
  2. 18
      blockchain-server/blockchain-server-btc/src/main/java/com/blockchain/server/btc/service/impl/BtcWalletServiceImpl.java
  3. 9
      blockchain-server/blockchain-server-currency/src/main/java/com/blockchain/server/currency/inner/CurrencyMarketInnerController.java
  4. 6
      blockchain-server/blockchain-server-currency/src/main/java/com/blockchain/server/currency/inner/api/CurrencyMarketInnerApi.java
  5. 2
      blockchain-server/blockchain-server-eos/src/main/java/com/blockchain/server/eos/common/enums/EosWalletEnums.java
  6. 22
      blockchain-server/blockchain-server-eos/src/main/java/com/blockchain/server/eos/feign/YyyyfMoneyFeign.java
  7. 21
      blockchain-server/blockchain-server-eos/src/main/java/com/blockchain/server/eos/service/impl/EosWalletServiceImpl.java
  8. 22
      blockchain-server/blockchain-server-eth/src/main/java/com/blockchain/server/eth/feign/YyyyfMoneyFeign.java
  9. 20
      blockchain-server/blockchain-server-eth/src/main/java/com/blockchain/server/eth/service/impl/EthWalletServiceImpl.java
  10. 2
      blockchain-server/blockchain-server-otc/src/main/java/com/blockchain/server/otc/common/enums/OtcEnums.java
  11. 24
      blockchain-server/blockchain-server-otc/src/main/java/com/blockchain/server/otc/feign/YyyyfMoneyFeign.java
  12. 31
      blockchain-server/blockchain-server-otc/src/main/java/com/blockchain/server/otc/service/impl/OrderServiceImpl.java
  13. 4
      blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/feign/CurrencyFeign.java
  14. 27
      blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/service/YyyfMoneyService.java
  15. 203
      blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/service/impl/YyyfMoneyServiceImpl.java

@ -0,0 +1,22 @@
package com.blockchain.server.btc.feign;
import com.blockchain.common.base.dto.ResultDTO;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import java.math.BigDecimal;
/**
* @author zijie
* @version 1.0
* @className YyyyfMoneyFeign
* @description
* @date 2020-07-07 20:31
*/
@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);
}

@ -1,5 +1,8 @@
package com.blockchain.server.btc.service.impl;
import com.blockchain.common.base.dto.ResultDTO;
import com.blockchain.common.base.dto.YyyfUserDto;
import com.blockchain.common.base.util.YyyfUserDtoUtils;
import com.blockchain.server.btc.common.constants.BtcTransferConstans;
import com.blockchain.server.btc.common.enums.BtcEnums;
import com.blockchain.server.btc.common.exception.BtcException;
@ -10,6 +13,7 @@ import com.blockchain.server.btc.entity.BtcToken;
import com.blockchain.server.btc.entity.BtcWallet;
import com.blockchain.server.btc.entity.BtcWalletTransfer;
import com.blockchain.server.btc.entity.WalletInitConfig;
import com.blockchain.server.btc.feign.YyyyfMoneyFeign;
import com.blockchain.server.btc.mapper.BtcWalletMapper;
import com.blockchain.server.btc.mapper.WalletInitConfigMapper;
import com.blockchain.server.btc.service.BtcApplicationService;
@ -17,6 +21,7 @@ import com.blockchain.server.btc.service.BtcTokenService;
import com.blockchain.server.btc.service.BtcWalletService;
import com.blockchain.server.btc.service.BtcWalletTransferService;
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;
@ -43,6 +48,12 @@ public class BtcWalletServiceImpl<psvm> implements BtcWalletService {
@Autowired
private WalletInitConfigMapper walletInitConfigMapper;
@Autowired
private YyyyfMoneyFeign yyyyfMoneyFeign;
@Autowired
private RedisTemplate redisTemplate;
@Override
@Transactional
public Integer insertWallet(String userOpenId) {
@ -204,7 +215,14 @@ public class BtcWalletServiceImpl<psvm> implements BtcWalletService {
if (config == null || config.getBalance() == null) {
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()));
if(resultDTO.getCode()==200 && resultDTO.getData().booleanValue()){
btcWalletMapper.updateWalletBalanceByUserOpenId(config.getBalance(), userOpenId, tokenId, walletType, new Date());
}else {
throw new BtcException(BtcEnums.FREEBALANCE_NOT_ENOUGH);
}
return 1;
}

@ -13,7 +13,6 @@ import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
@Api(CurrencyMarketInnerApi.MARKET_CONTROLLER_API)
@ -43,4 +42,12 @@ public class CurrencyMarketInnerController {
return currencyMarketService.getList();
}
@ApiOperation(value = CurrencyMarketInnerApi.Get.METHOD_API_NAME,
notes = CurrencyMarketInnerApi.Get.METHOD_API_NOTE)
@RequestMapping(value = "/get", method = RequestMethod.GET)
public CurrencyMarketDTO get(
@ApiParam(CurrencyMarketInnerApi.Get.METHOD_API_CURRENCY_PAIR) String currencyPair) {
return currencyMarketService.get(currencyPair);
}
}

@ -14,4 +14,10 @@ public class CurrencyMarketInnerApi {
public static final String METHOD_API_TRADINGTYPE = "成交类型";
}
public static class Get {
public static final String METHOD_API_NAME = "最新行情";
public static final String METHOD_API_NOTE = "获取数字货币最新行情";
public static final String METHOD_API_CURRENCY_PAIR = "数字货币对";
}
}

@ -19,7 +19,7 @@ public enum EosWalletEnums {
CURRENCY_FAILURE_ERROR(7008, "出币失败", "Currency failure.", "出幣失敗"),
INEXISTENCE_TX(12500, "该记录未找到", "The record was not found", "該記錄未找到"),
INEXISTENCE_WALLET(7017, "该钱包不存在", "The wallet does not exist.", "該錢包不存在"),
FREEBALANCE_NOT_ENOUGH(7009, "钱包可用余额不足", "Insufficient balance available in wallet.", "錢包可用餘額不足")
;

@ -0,0 +1,22 @@
package com.blockchain.server.eos.feign;
import com.blockchain.common.base.dto.ResultDTO;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import java.math.BigDecimal;
/**
* @author
* @version 1.0
* @className YyyyfMoneyFeign
* @description
* @date 2020-07-07 20:31
*/
@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);
}

@ -1,12 +1,10 @@
package com.blockchain.server.eos.service.impl;
import com.blockchain.common.base.constant.BaseConstant;
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.common.base.dto.*;
import com.blockchain.common.base.exception.RPCException;
import com.blockchain.common.base.util.ExceptionPreconditionUtils;
import com.blockchain.common.base.util.YyyfUserDtoUtils;
import com.blockchain.server.eos.common.constant.EosConstant;
import com.blockchain.server.eos.common.enums.EosWalletEnums;
import com.blockchain.server.eos.common.exception.EosWalletException;
@ -14,11 +12,13 @@ import com.blockchain.server.eos.dto.WalletDTO;
import com.blockchain.server.eos.entity.*;
import com.blockchain.server.eos.feign.UserServerFegin;
import com.blockchain.server.eos.feign.WalletTransferFegin;
import com.blockchain.server.eos.feign.YyyyfMoneyFeign;
import com.blockchain.server.eos.mapper.WalletInitConfigMapper;
import com.blockchain.server.eos.mapper.WalletMapper;
import com.blockchain.server.eos.service.*;
import com.codingapi.tx.annotation.ITxTransaction;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
@ -55,6 +55,11 @@ public class EosWalletServiceImpl implements EosWalletService, ITxTransaction {
@Autowired
private WalletInitConfigMapper walletInitConfigMapper;
@Autowired
private YyyyfMoneyFeign yyyyfMoneyFeign;
@Autowired
private RedisTemplate redisTemplate;
/**
* 用户充值修改钱包金额
*
@ -387,8 +392,16 @@ public class EosWalletServiceImpl implements EosWalletService, ITxTransaction {
if (config == null || config.getBalance() == null) {
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()));
if(resultDTO.getCode()==200 && resultDTO.getData().booleanValue()){
// 修改钱包插入充值记录
walletMapper.updateWalletBalanceByUserOpenId(config.getBalance(), userOpenId, tokenId, walletType, new Date());
}else {
throw new EosWalletException(EosWalletEnums.FREEBALANCE_NOT_ENOUGH);
}
}
}

@ -0,0 +1,22 @@
package com.blockchain.server.eth.feign;
import com.blockchain.common.base.dto.ResultDTO;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import java.math.BigDecimal;
/**
* @author
* @version 1.0
* @className YyyyfMoneyFeign
* @description
* @date 2020-07-07 20:31
*/
@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);
}

@ -2,12 +2,10 @@ package com.blockchain.server.eth.service.impl;
import com.blockchain.common.base.constant.BaseConstant;
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.common.base.dto.*;
import com.blockchain.common.base.exception.RPCException;
import com.blockchain.common.base.util.ExceptionPreconditionUtils;
import com.blockchain.common.base.util.YyyfUserDtoUtils;
import com.blockchain.server.eth.common.constants.EthWalletConstants;
import com.blockchain.server.eth.common.enums.EthWalletEnums;
import com.blockchain.server.eth.common.exception.EthWalletException;
@ -18,6 +16,7 @@ import com.blockchain.server.eth.dto.EthWalletDTO;
import com.blockchain.server.eth.dto.Web3jTransferDTO;
import com.blockchain.server.eth.entity.*;
import com.blockchain.server.eth.feign.UserFeign;
import com.blockchain.server.eth.feign.YyyyfMoneyFeign;
import com.blockchain.server.eth.mapper.EthWalletMapper;
import com.blockchain.server.eth.mapper.WalletInitConfigMapper;
import com.blockchain.server.eth.service.*;
@ -62,6 +61,10 @@ public class EthWalletServiceImpl implements IEthWalletService, ITxTransaction {
IWalletWeb3j walletWeb3j;
@Autowired
RedisTemplate redisTemplate;
@Autowired
private YyyyfMoneyFeign yyyyfMoneyFeign;
@Autowired
private WalletInitConfigMapper walletInitConfigMapper;
@ -435,7 +438,16 @@ public class EthWalletServiceImpl implements IEthWalletService, ITxTransaction {
if(config==null || config.getBalance()==null){
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()));
if(resultDTO.getCode()==200 && resultDTO.getData().booleanValue()){
ethWalletMapper.updateWalletBalanceByUserOpenId(config.getBalance(),userOpenId,tokenId,walletType,new Date());
}else {
throw new EthWalletException(EthWalletEnums.FREEBALANCE_NOT_ENOUGH);
}
}

@ -3,6 +3,8 @@ package com.blockchain.server.otc.common.enums;
import lombok.Getter;
public enum OtcEnums {
FREEBALANCE_NOT_ENOUGH(7009, "钱包可用余额不足", "Insufficient balance available in wallet."),
ERROR_IN_WALLET_CALL(7010, "钱包调用出错,钱包余额不足或者系统错误", "Wallet call error, insufficient wallet balance or system error"),
PASS_NULL(8701, "请输入密码!", "Please enter password!"),
USERID_NULL(8702, "用户id为空!", "User id is empty!"),
PUBLISH_AD_COIN_NULL(8703, "请选择交易货币!", "Please select the currency of exchange!"),

@ -0,0 +1,24 @@
package com.blockchain.server.otc.feign;
import com.blockchain.common.base.dto.ResultDTO;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import java.math.BigDecimal;
/**
* @author
* @version 1.0
* @className YyyyfMoneyFeign
* @description
* @date 2020-07-07 20:31
*/
@FeignClient("dapp-yyyf-server")
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);
}

@ -2,7 +2,9 @@ package com.blockchain.server.otc.service.impl;
import com.blockchain.common.base.constant.PushConstants;
import com.blockchain.common.base.dto.ResultDTO;
import com.blockchain.common.base.dto.YyyfUserDto;
import com.blockchain.common.base.enums.PushEnums;
import com.blockchain.common.base.util.YyyfUserDtoUtils;
import com.blockchain.server.otc.common.constant.*;
import com.blockchain.server.otc.common.enums.*;
import com.blockchain.server.otc.common.exception.OtcException;
@ -13,6 +15,7 @@ import com.blockchain.server.otc.dto.user.UserBaseDTO;
import com.blockchain.server.otc.entity.*;
import com.blockchain.server.otc.feign.PushFeign;
import com.blockchain.server.otc.feign.UserFeign;
import com.blockchain.server.otc.feign.YyyyfMoneyFeign;
import com.blockchain.server.otc.mapper.OrderMapper;
import com.blockchain.server.otc.redis.OrderCache;
import com.blockchain.server.otc.service.*;
@ -21,6 +24,7 @@ import com.codingapi.tx.annotation.TxTransaction;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
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;
@ -60,6 +64,10 @@ public class OrderServiceImpl implements OrderService, ITxTransaction {
private ImUtil imUtil;
@Autowired
private OrderCache orderCache;
@Autowired
private YyyyfMoneyFeign yyyyfMoneyFeign;
@Autowired
private RedisTemplate redisTemplate;
private static final BigDecimal DECIMAL_DISH = new BigDecimal("0.1"); //下单金额计算的偏差值
@ -278,6 +286,13 @@ public class OrderServiceImpl implements OrderService, ITxTransaction {
checkPayTypeIsAdPayType(payType, ad.getAdPay());
//确认支付时,设置订单支付信息
order.setOrderPayType(payType);
YyyfUserDto yyyfUserDto = YyyfUserDtoUtils.getYyyfUserDtoByUserId(userId, redisTemplate);
ResultDTO<Boolean> resultDTO = yyyyfMoneyFeign.resetWallet(yyyfUserDto.getAssessUserId(), order.getCoinName(),order.getAmount(),payType,BigDecimal.ZERO.subtract(order.getTurnover()));
if(resultDTO.getCode()==200 && resultDTO.getData().booleanValue()) {
//更新订单状态
receiptOrPayUpdateOrder(order, UserHandleConstants.PAY);
//记录用户操作
@ -287,6 +302,11 @@ public class OrderServiceImpl implements OrderService, ITxTransaction {
order.getSellUserId(), order.getBuyUserId(), order.getId());
//发送手机消息通知
pushToSingle(order.getSellUserId(), order.getId(), PushEnums.OTC_ORDER_PAY.getPushType());
}else{
throw new OtcException(OtcEnums.FREEBALANCE_NOT_ENOUGH);
}
}
@Override
@ -303,6 +323,14 @@ public class OrderServiceImpl implements OrderService, ITxTransaction {
checkOrderNull(order);
//检查订单能否确认收款
checkOrderCanHandle(order, userId, UserHandleConstants.RECEIPT);
YyyfUserDto yyyfUserDto = YyyfUserDtoUtils.getYyyfUserDtoByUserId(userId, redisTemplate);
ResultDTO<Boolean> resultDTO = yyyyfMoneyFeign.resetWallet(yyyfUserDto.getAssessUserId(), order.getCoinName(),BigDecimal.ZERO.subtract(order.getAmount()),order.getOrderPayType(),order.getTurnover());
if(resultDTO.getCode()==200 && resultDTO.getData().booleanValue()) {
//更新订单状态
receiptOrPayUpdateOrder(order, UserHandleConstants.RECEIPT);
//记录用户操作
@ -318,6 +346,9 @@ public class OrderServiceImpl implements OrderService, ITxTransaction {
order.getSellUserId(), order.getBuyUserId(), order.getId());
//发送手机消息通知
pushToSingle(order.getBuyUserId(), order.getId(), PushEnums.OTC_ORDER_RECEIPT.getPushType());
}else{
throw new OtcException(OtcEnums.ERROR_IN_WALLET_CALL);
}
}
@Override

@ -3,6 +3,7 @@ package com.blockchain.server.yyyf.feign;
import com.blockchain.server.yyyf.feign.dto.CurrencyMarketDTO;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import java.util.List;
@ -10,4 +11,7 @@ import java.util.List;
public interface CurrencyFeign {
@GetMapping("/inner/market/getList")
List<CurrencyMarketDTO> getList();
@GetMapping("/inner/market/get")
CurrencyMarketDTO get(@RequestParam("currencyPair") String currencyPair);
}

@ -8,7 +8,7 @@ import java.math.BigDecimal;
public interface YyyfMoneyService {
/**
* @description 交易转账
* @author Mr.Xu
* @author zijie
* @date 2020-05-26 21:51:15
* @param [assessUserId, out, in, amount]
* @return com.blockchain.server.yyyf.dto.TransactResultDto
@ -18,7 +18,7 @@ public interface YyyfMoneyService {
/**
* @description 插入
* @author Mr.Xu
* @author zijie
* @date 2020-05-26 22:48:08
* @param [yyyfMoney]
* @return void
@ -27,10 +27,31 @@ public interface YyyfMoneyService {
/**
* @description 更新
* @author Mr.Xu
* @author zijie
* @date 2020-05-26 22:48:19
* @param [yyyfMoney]
* @return void
**/
void update(YyyfMoney yyyfMoney);
/**
* @description 充币提币
* @author zijie
* @date 2020-07-12 22:45:43
* @param [assessUserId, coinName, balance]
* @return boolean
**/
boolean resetDigitWallet(String assessUserId, String coinName, BigDecimal balance);
/**
* @description 法币交易
* @author zijie
* @date 2020-07-12 22:46:21
* @param [assessUserId, coinName, balance, payType, payMoney]
* @return boolean
**/
boolean resetWallet(String assessUserId, String coinName, BigDecimal balance, String payType, BigDecimal payMoney);
}

@ -7,15 +7,18 @@ import com.blockchain.server.yyyf.exceprion.YyyfException;
import com.blockchain.server.yyyf.mapper.YyyfMoneyMapper;
import com.blockchain.server.yyyf.service.YyyfMoneyService;
import lombok.SneakyThrows;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.lang.reflect.Method;
import java.math.BigDecimal;
import java.util.Date;
/**
* @author Mr.Xu
* @author zijie
* @version 1.0
* @className YyyfMoneyServiceImpl
* @description
@ -25,10 +28,13 @@ import java.math.BigDecimal;
@Service
public class YyyfMoneyServiceImpl implements YyyfMoneyService {
private Logger logger = LoggerFactory.getLogger(YyyfMoneyServiceImpl.class);
@Autowired
private YyyfMoneyMapper yyyfMoneyMapper;
/* @Autowired
private CurrencyFeign currencyFeign;*/
@SneakyThrows
@Override
@ -58,11 +64,11 @@ public class YyyfMoneyServiceImpl implements YyyfMoneyService {
//转入币种后的余额
BigDecimal inSurplus = inOriginal.add(amount);
Method outSetMethod = aClass.getMethod("set".concat(outField),BigDecimal.class);
Method inSetMethod = aClass.getMethod("set".concat(inField),BigDecimal.class);
Method outSetMethod = aClass.getMethod("set".concat(outField), BigDecimal.class);
Method inSetMethod = aClass.getMethod("set".concat(inField), BigDecimal.class);
outSetMethod.invoke(yyyfMoney,outSurplus);
inSetMethod.invoke(yyyfMoney,inSurplus);
outSetMethod.invoke(yyyfMoney, outSurplus);
inSetMethod.invoke(yyyfMoney, inSurplus);
this.yyyfMoneyMapper.updateByPrimaryKeySelective(yyyfMoney);
@ -89,4 +95,191 @@ public class YyyfMoneyServiceImpl implements YyyfMoneyService {
public void update(YyyfMoney yyyfMoney) {
this.yyyfMoneyMapper.updateByPrimaryKeySelective(yyyfMoney);
}
@Override
public boolean resetDigitWallet(String assessUserId, String coinName, BigDecimal balance) {
YyyfMoney yyyfMoney = this.yyyfMoneyMapper.selectByPrimaryKey(assessUserId);
BigDecimal add =BigDecimal.ZERO;
switch (coinName) {
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;
}
case "btc": {
add = yyyfMoney.getBtc().add(balance);
yyyfMoney.setBtc(add);
break;
}
case "usdt": {
add = yyyfMoney.getUsdt().add(balance);
yyyfMoney.setUsdt(add);
break;
}
case "eth": {
add = yyyfMoney.getEth().add(balance);
yyyfMoney.setEth(add);
break;
}
case "eos": {
add = yyyfMoney.getEos().add(balance);
yyyfMoney.setEos(add);
break;
}
default:
add=BigDecimal.ZERO.subtract(BigDecimal.ONE);
}
if(add.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, 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;
}*/
}

Loading…
Cancel
Save