xiaoyong931011
2022-02-21 6258b45b69d75325b7d6df7edf2761c22a87369b
20222221
5 files modified
1 files added
98 ■■■■■ changed files
src/main/java/com/xcong/excoin/common/enumerates/CoinTypeEnum.java 2 ●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/common/enumerates/MemberWalletCoinEnum.java 1 ●●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/modules/coin/controller/CoinController.java 13 ●●●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/modules/coin/parameter/dto/UsdtToGusdDto.java 25 ●●●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/modules/coin/service/CoinService.java 1 ●●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/modules/coin/service/impl/CoinServiceImpl.java 56 ●●●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/common/enumerates/CoinTypeEnum.java
@@ -6,5 +6,5 @@
 * @author wzy
 */
public enum CoinTypeEnum {
    USDT, BTC, ETH, LTC, EOS, XRP, BCH, ETC,BEA
    USDT, BTC, ETH, LTC, EOS, XRP, BCH, ETC,BEA,GUSD,GOLDRICE,
}
src/main/java/com/xcong/excoin/common/enumerates/MemberWalletCoinEnum.java
@@ -17,6 +17,7 @@
    CONTENTFROMCONTRACT("0004","由合约账户转入"),
    
    CONTENTFROMAGENT("0005","由代理账户转入"),
    ZHIYATOGUSD("0006","兑换GUSD"),
    
    WALLETCOINCODE("USDT", "USDT"),
    
src/main/java/com/xcong/excoin/modules/coin/controller/CoinController.java
@@ -5,6 +5,7 @@
import javax.annotation.Resource;
import javax.validation.Valid;
import com.xcong.excoin.modules.coin.parameter.dto.UsdtToGusdDto;
import com.xcong.excoin.modules.coin.parameter.vo.AllWalletCoinVo;
import com.xcong.excoin.modules.coin.parameter.vo.MemberAccountMoneyChangeInfoVo;
import com.xcong.excoin.modules.coin.parameter.vo.MemberAgentIntoInfoVo;
@@ -198,5 +199,17 @@
        return coinService.agentTransferToWalletCoin(balance,transfertype);
    }
    
    /**
     * USDT兌換成GUSD
     * @return
     */
    @ApiOperation(value="USDT兌換成GUSD", notes="USDT兌換成GUSD")
    @PostMapping(value="/usdtToGusd")
    public Result  usdtToGusd(@RequestBody @Valid UsdtToGusdDto usdtToGusdDto) {
        BigDecimal balance = usdtToGusdDto.getBalance();
        Integer transfertype = usdtToGusdDto.getTransfertype();
        return coinService.usdtToGusd(balance,transfertype);
    }
}
src/main/java/com/xcong/excoin/modules/coin/parameter/dto/UsdtToGusdDto.java
New file
@@ -0,0 +1,25 @@
package com.xcong.excoin.modules.coin.parameter.dto;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.validation.constraints.NotNull;
import java.math.BigDecimal;
@Data
@ApiModel(value = "UsdtToGusdDto", description = "参数接收类")
public class UsdtToGusdDto {
    @NotNull(message = "划转金额不能为空")
    @ApiModelProperty(value = "划转金额", example = "100")
    private BigDecimal balance;
    @NotNull(message = "币种不能为空")
    @ApiModelProperty(value = "币种", example = "USDT")
    private String symbol;
    @NotNull(message = "账户类型不能为空")
    @ApiModelProperty(value = "转账类型1:转币币,2:转合约", example = "1")
    private Integer transfertype;
}
src/main/java/com/xcong/excoin/modules/coin/service/CoinService.java
@@ -42,4 +42,5 @@
    void updateWalletBalance(@Param("id") Long id, @Param("availableBalance")BigDecimal availableBalance,@Param("totalBalance")BigDecimal totalBalance, @Param("frozenBalance")BigDecimal frozenBalance);
    Result usdtToGusd(BigDecimal balance, Integer transfertype);
}
src/main/java/com/xcong/excoin/modules/coin/service/impl/CoinServiceImpl.java
@@ -596,4 +596,60 @@
        }
    }
    @Override
    public Result usdtToGusd(BigDecimal balance, Integer transfertype) {
        //获取用户ID
        Long memberId = LoginUserUtils.getAppLoginUser().getId();
        if (balance.compareTo(BigDecimal.ZERO) <= 0) {
            return Result.fail(MessageSourceUtils.getString("member_service_0004"));
        }
        // 扣币
        String walletCode = MemberWalletCoinEnum.WALLETCOINCODE.getValue();
        MemberWalletCoinEntity memberWalletCoinEntity = memberWalletCoinDao.selectWalletCoinBymIdAndCode(memberId, walletCode);
        BigDecimal availableBalance = memberWalletCoinEntity.getAvailableBalance();
        BigDecimal totalBalance = memberWalletCoinEntity.getTotalBalance();
        BigDecimal available = availableBalance.subtract(balance);
        if (available.compareTo(BigDecimal.ZERO) < 0) {
            return Result.fail(MessageSourceUtils.getString("member_service_0008"));
        }
        BigDecimal total = totalBalance.subtract(balance);
        if (total.compareTo(BigDecimal.ZERO) < 0) {
            return Result.fail(MessageSourceUtils.getString("member_service_0008"));
        }
        memberWalletCoinEntity.setAvailableBalance(available);
        memberWalletCoinEntity.setTotalBalance(total);
        int i = memberWalletCoinDao.updateById(memberWalletCoinEntity);
        if (i < 1) {
            return Result.fail(MessageSourceUtils.getString("member_service_0095"));
        }
        //添加资金划转历史记录
        MemberAccountMoneyChange memberAccountRecord = new MemberAccountMoneyChange();
        //获取usdt兑换gusd的兑换比例
        String gusdName = CoinTypeEnum.GUSD.name();
        MemberWalletCoinEntity gusdMemberWalletCoinEntity = memberWalletCoinDao.selectWalletCoinBymIdAndCode(memberId, gusdName);
        BigDecimal gusdAvailableBalance = gusdMemberWalletCoinEntity.getAvailableBalance();
        BigDecimal gusdTotalBalance = gusdMemberWalletCoinEntity.getTotalBalance();
        gusdMemberWalletCoinEntity.setAvailableBalance(gusdAvailableBalance.add(balance));
        gusdMemberWalletCoinEntity.setTotalBalance(gusdTotalBalance.add(balance));
        int updateById = memberWalletCoinDao.updateById(gusdMemberWalletCoinEntity);
        if (updateById < 1) {
            return Result.fail(MessageSourceUtils.getString("member_service_0095"));
        }
        //添加资金划转历史记录
        memberAccountRecord.setMemberId(memberId);
        memberAccountRecord.setStatus(MemberAccountMoneyChange.STATUS_SUCCESS_INTEGER);
        memberAccountRecord.setSymbol(walletCode);
        memberAccountRecord.setContent(MemberWalletCoinEnum.ZHIYATOGUSD.getValue());
        memberAccountRecord.setType(MemberAccountMoneyChange.TYPE_WALLET_COIN);
        memberAccountRecord.setAmount(balance);
        memberAccountMoneyChangeDao.insert(memberAccountRecord);
        return Result.ok(MessageSourceUtils.getString("member_service_0006"));
    }
}