From ac5051ef7aa0ea4410d32760a200e2dc31ef870e Mon Sep 17 00:00:00 2001 From: Helius <wangdoubleone@gmail.com> Date: Thu, 19 Nov 2020 16:55:39 +0800 Subject: [PATCH] modify --- src/main/java/com/xcong/excoin/modules/member/mapper/TrcAddressDao.java | 18 ++++ src/main/resources/mapper/modules/TrcAddressDao.xml | 16 ++++ src/main/java/com/xcong/excoin/modules/member/service/impl/MemberServiceImpl.java | 148 ++++++++++++++++++++++++------------- src/main/resources/mapper/modules/MemberWalletCoinMapper.xml | 6 + src/main/java/com/xcong/excoin/modules/member/entity/TrcAddressEntity.java | 30 +++++++ src/main/java/com/xcong/excoin/modules/member/mapper/MemberWalletCoinMapper.java | 1 src/main/resources/application-dev.yml | 14 +- 7 files changed, 174 insertions(+), 59 deletions(-) diff --git a/src/main/java/com/xcong/excoin/modules/member/entity/TrcAddressEntity.java b/src/main/java/com/xcong/excoin/modules/member/entity/TrcAddressEntity.java new file mode 100644 index 0000000..b351297 --- /dev/null +++ b/src/main/java/com/xcong/excoin/modules/member/entity/TrcAddressEntity.java @@ -0,0 +1,30 @@ +package com.xcong.excoin.modules.member.entity; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; + +/** + * @author wzy + * @date 2020-11-09 + **/ +@Data +@TableName("trc_address") +public class TrcAddressEntity { + + public static final Integer SYSTEM_FLAG_YJS = 1; + public static final Integer SYSTEM_FLAG_SL = 2; + + + @TableId(type = IdType.AUTO) + private Long id; + + private String address; + + private int isUse; + + private Long memberId; + + private Integer systemFlag; +} diff --git a/src/main/java/com/xcong/excoin/modules/member/mapper/MemberWalletCoinMapper.java b/src/main/java/com/xcong/excoin/modules/member/mapper/MemberWalletCoinMapper.java index 88c78cd..d994ac7 100644 --- a/src/main/java/com/xcong/excoin/modules/member/mapper/MemberWalletCoinMapper.java +++ b/src/main/java/com/xcong/excoin/modules/member/mapper/MemberWalletCoinMapper.java @@ -16,6 +16,7 @@ TdCoinWallet selectTdCoinWalletByAddress(@Param("address") String address, @Param("symbol") String symbol); int updateTdCoinWalletAvaliable(@Param("money") BigDecimal money, @Param("address") String address); + int updateTdCoinWalletTrc20(@Param("money") BigDecimal money, @Param("memberId") Long memberId); HashMap<String, Object> selectMemberWalletCoinByMemberId(@Param("memberId") Long memberId); } diff --git a/src/main/java/com/xcong/excoin/modules/member/mapper/TrcAddressDao.java b/src/main/java/com/xcong/excoin/modules/member/mapper/TrcAddressDao.java new file mode 100644 index 0000000..0f27fe6 --- /dev/null +++ b/src/main/java/com/xcong/excoin/modules/member/mapper/TrcAddressDao.java @@ -0,0 +1,18 @@ +package com.xcong.excoin.modules.member.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.xcong.excoin.modules.member.entity.TrcAddressEntity; +import org.apache.ibatis.annotations.Param; + +/** + * @author wzy + * @date 2020-11-09 + **/ +public interface TrcAddressDao extends BaseMapper<TrcAddressEntity> { + + TrcAddressEntity selectSrcAddressByMemberId(@Param("memberId") Long memberId); + + TrcAddressEntity selectOneSrcAddressUnUse(); + + TrcAddressEntity selectTrcAddressByAddress(@Param("address") String address); +} diff --git a/src/main/java/com/xcong/excoin/modules/member/service/impl/MemberServiceImpl.java b/src/main/java/com/xcong/excoin/modules/member/service/impl/MemberServiceImpl.java index edf2822..02b733b 100644 --- a/src/main/java/com/xcong/excoin/modules/member/service/impl/MemberServiceImpl.java +++ b/src/main/java/com/xcong/excoin/modules/member/service/impl/MemberServiceImpl.java @@ -77,6 +77,8 @@ private final TdFinancialReordDao tdFinancialReordDao; private final RedisUtils redisUtils; + + private final TrcAddressDao trcAddressDao; @Override public IPage<AgentFriendRelationEntity> findAgentInfoListInPage(AgentFriendRelationEntity agentFriendRelationEntity, @@ -488,50 +490,91 @@ if ("Y".equals(selectById.getIsInside())) { // 查询算力系统中是否存在该地址 TdCoinWallet tdCoinWallet = memberWalletCoinMapper.selectTdCoinWalletByAddress(address, "USDT"); - if (tdCoinWallet != null) { - // 更新算力系统中用户钱包余额 - memberWalletCoinMapper.updateTdCoinWalletAvaliable(amount, address); + TrcAddressEntity trcAddressEntity = trcAddressDao.selectTrcAddressByAddress(address); + // 判断是否为TRC20地址 + if (trcAddressEntity == null) { + if (tdCoinWallet != null) { + // 更新算力系统中用户钱包余额 + memberWalletCoinMapper.updateTdCoinWalletAvaliable(amount, address); - TdFinancialReord tdFinancialReord = new TdFinancialReord(); - tdFinancialReord.setAmount(amount); - tdFinancialReord.setCreateTime(new Date()); - tdFinancialReord.setMemId(tdCoinWallet.getMemId()); - tdFinancialReord.setSymbol("USDT"); - tdFinancialReord.setTitle("USDT交易所转账"); - tdFinancialReord.setContent("USDT交易所转账"); - // 插入算力系统中财务记录 - tdFinancialReordDao.insert(tdFinancialReord); - } else { - Map<String, Object> columnMap = new HashMap<>(); - columnMap.put("symbol", symbol); - columnMap.put("address", address); - // 如果是内部转账 则需要将币加到内部地址 - List<MemberCoinAddressEntity> selectByMap = memberCoinAddressMapper.selectByMap(columnMap); - if (selectByMap == null || selectByMap.isEmpty()) { - return new FebsResponse().fail().message("地址有误,请拒绝!"); + TdFinancialReord tdFinancialReord = new TdFinancialReord(); + tdFinancialReord.setAmount(amount); + tdFinancialReord.setCreateTime(new Date()); + tdFinancialReord.setMemId(tdCoinWallet.getMemId()); + tdFinancialReord.setSymbol("USDT"); + tdFinancialReord.setTitle("USDT交易所转账"); + tdFinancialReord.setContent("USDT交易所转账"); + // 插入算力系统中财务记录 + tdFinancialReordDao.insert(tdFinancialReord); + } else { + Map<String, Object> columnMap = new HashMap<>(); + columnMap.put("symbol", symbol); + columnMap.put("address", address); + // 如果是内部转账 则需要将币加到内部地址 + List<MemberCoinAddressEntity> selectByMap = memberCoinAddressMapper.selectByMap(columnMap); + if (selectByMap == null || selectByMap.isEmpty()) { + return new FebsResponse().fail().message("地址有误,请拒绝!"); + } + Long aimMemberId = selectByMap.get(0).getMemberId(); + MemberWalletCoinEntity aimWalletCoin = memberWalletCoinMapper.findWalletCoinByMemberIdAndWalletCode(aimMemberId, symbol); + + BigDecimal addTotal = aimWalletCoin.getTotalBalance().add(amount); + BigDecimal addAvailable = aimWalletCoin.getAvailableBalance().add(amount); + aimWalletCoin.setTotalBalance(addTotal); + aimWalletCoin.setAvailableBalance(addAvailable); + + memberWalletCoinMapper.updateById(aimWalletCoin); + + MemberAccountMoneyChangeEntity memberAccountMoneyChangeEntity = new MemberAccountMoneyChangeEntity(); + memberAccountMoneyChangeEntity.setContent("收款"); + memberAccountMoneyChangeEntity.setMemberId(aimMemberId); + memberAccountMoneyChangeEntity.setAmount(amount); + memberAccountMoneyChangeEntity.setStatus(MemberAccountMoneyChangeEntity.STATUS_SUCCESS_INTEGER); + memberAccountMoneyChangeEntity.setSymbol(selectById.getSymbol()); + memberAccountMoneyChangeEntity.setType(MemberAccountMoneyChangeEntity.TYPE_WALLET_COIN); + memberAccountMoneyChangeEntity.setCreateBy(selectById.getCreateBy()); + memberAccountMoneyChangeEntity.setCreateTime(new Date()); + memberAccountMoneyChangeEntity.setUpdateBy(selectById.getCreateBy()); + memberAccountMoneyChangeEntity.setUpdateTime(new Date()); + memberAccountMoneyChangeMapper.insert(memberAccountMoneyChangeEntity); } - Long aimMemberId = selectByMap.get(0).getMemberId(); - MemberWalletCoinEntity aimWalletCoin = memberWalletCoinMapper.findWalletCoinByMemberIdAndWalletCode(aimMemberId, symbol); + } else { + if (trcAddressEntity.getSystemFlag().equals(TrcAddressEntity.SYSTEM_FLAG_SL)) { + memberWalletCoinMapper.updateTdCoinWalletTrc20(amount, trcAddressEntity.getMemberId()); - BigDecimal addTotal = aimWalletCoin.getTotalBalance().add(amount); - BigDecimal addAvailable = aimWalletCoin.getAvailableBalance().add(amount); - aimWalletCoin.setTotalBalance(addTotal); - aimWalletCoin.setAvailableBalance(addAvailable); + TdFinancialReord tdFinancialReord = new TdFinancialReord(); + tdFinancialReord.setAmount(amount); + tdFinancialReord.setCreateTime(new Date()); + tdFinancialReord.setMemId(trcAddressEntity.getMemberId()); + tdFinancialReord.setSymbol("USDT"); + tdFinancialReord.setTitle("USDT交易所转账"); + tdFinancialReord.setContent("USDT交易所转账"); + // 插入算力系统中财务记录 + tdFinancialReordDao.insert(tdFinancialReord); + } else { + Long aimMemberId = trcAddressEntity.getMemberId(); + MemberWalletCoinEntity aimWalletCoin = memberWalletCoinMapper.findWalletCoinByMemberIdAndWalletCode(aimMemberId, symbol); - memberWalletCoinMapper.updateById(aimWalletCoin); + BigDecimal addTotal = aimWalletCoin.getTotalBalance().add(amount); + BigDecimal addAvailable = aimWalletCoin.getAvailableBalance().add(amount); + aimWalletCoin.setTotalBalance(addTotal); + aimWalletCoin.setAvailableBalance(addAvailable); - MemberAccountMoneyChangeEntity memberAccountMoneyChangeEntity = new MemberAccountMoneyChangeEntity(); - memberAccountMoneyChangeEntity.setContent("收款"); - memberAccountMoneyChangeEntity.setMemberId(aimMemberId); - memberAccountMoneyChangeEntity.setAmount(amount); - memberAccountMoneyChangeEntity.setStatus(MemberAccountMoneyChangeEntity.STATUS_SUCCESS_INTEGER); - memberAccountMoneyChangeEntity.setSymbol(selectById.getSymbol()); - memberAccountMoneyChangeEntity.setType(MemberAccountMoneyChangeEntity.TYPE_WALLET_COIN); - memberAccountMoneyChangeEntity.setCreateBy(selectById.getCreateBy()); - memberAccountMoneyChangeEntity.setCreateTime(new Date()); - memberAccountMoneyChangeEntity.setUpdateBy(selectById.getCreateBy()); - memberAccountMoneyChangeEntity.setUpdateTime(new Date()); - memberAccountMoneyChangeMapper.insert(memberAccountMoneyChangeEntity); + memberWalletCoinMapper.updateById(aimWalletCoin); + + MemberAccountMoneyChangeEntity memberAccountMoneyChangeEntity = new MemberAccountMoneyChangeEntity(); + memberAccountMoneyChangeEntity.setContent("收款"); + memberAccountMoneyChangeEntity.setMemberId(aimMemberId); + memberAccountMoneyChangeEntity.setAmount(amount); + memberAccountMoneyChangeEntity.setStatus(MemberAccountMoneyChangeEntity.STATUS_SUCCESS_INTEGER); + memberAccountMoneyChangeEntity.setSymbol(selectById.getSymbol()); + memberAccountMoneyChangeEntity.setType(MemberAccountMoneyChangeEntity.TYPE_WALLET_COIN); + memberAccountMoneyChangeEntity.setCreateBy(selectById.getCreateBy()); + memberAccountMoneyChangeEntity.setCreateTime(new Date()); + memberAccountMoneyChangeEntity.setUpdateBy(selectById.getCreateBy()); + memberAccountMoneyChangeEntity.setUpdateTime(new Date()); + memberAccountMoneyChangeMapper.insert(memberAccountMoneyChangeEntity); + } } } @@ -547,18 +590,20 @@ selectById.setStatus(MemberCoinWithdrawEntity.IS_STATUS_Y); memberCoinWithdrawMapper.updateById(selectById); - if ("TRC20".equals(selectById.getLabel())) { - Thread thread = new Thread(new Runnable() { - @Override - public void run() { - log.info("远程调用TRC执行:{}", selectById.getId()); - String orderNo = generateOrderNo(memberId); - TRC20ApiUtils.coinApply(orderNo, memberId.toString(), selectById.getSymbol(), selectById.getAmount().toPlainString(), selectById.getAddress()); - selectById.setTag(orderNo); - memberCoinWithdrawMapper.updateById(selectById); - } - }); - thread.start(); + if (!"Y".equals(selectById.getIsInside())) { + if ("TRC20".equals(selectById.getLabel())) { + Thread thread = new Thread(new Runnable() { + @Override + public void run() { + log.info("远程调用TRC执行:{}", selectById.getId()); + String orderNo = generateOrderNo(memberId); + TRC20ApiUtils.coinApply(orderNo, memberId.toString(), selectById.getSymbol(), selectById.getAmount().subtract(selectById.getFeeAmount()).toPlainString(), selectById.getAddress()); + selectById.setTag(orderNo); + memberCoinWithdrawMapper.updateById(selectById); + } + }); + thread.start(); + } } MemberEntity memberEntity = memberMapper.selectById(memberId); @@ -567,7 +612,6 @@ SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm"); String time = format.format(new Date()); // 将当前时间袼式化为指定的格式 - log.info("---->{}", phone); if(StrUtil.isNotBlank(phone)) { Sms106Send.sendWithdrawalCoinMsg(phone, time); } diff --git a/src/main/resources/application-dev.yml b/src/main/resources/application-dev.yml index 70f014a..f2ad66d 100644 --- a/src/main/resources/application-dev.yml +++ b/src/main/resources/application-dev.yml @@ -18,17 +18,17 @@ username: ct_test password: 123456 driver-class-name: com.mysql.cj.jdbc.Driver - url: jdbc:mysql://120.27.238.55:3306/kss_framework?useUnicode=true&characterEncoding=UTF-8&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=GMT%2b8 + url: jdbc:mysql://120.27.238.55:3306/pilot_test?useUnicode=true&characterEncoding=UTF-8&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=GMT%2b8 redis: # Redis数据库索引(默认为 0) - database: 1 - # Redis服务器地址 - host: 47.114.114.219 - # Redis服务器连接端口 + database: 0 + ## Redis服务器地址 + host: 180.215.221.145 + ## Redis服务器连接端口 port: 6379 - # Redis 密码 - password: biyi123 + ## Redis服务器连接密码(默认为空) + password: pilot123!@# lettuce: pool: # 连接池中的最小空闲连接 diff --git a/src/main/resources/mapper/modules/MemberWalletCoinMapper.xml b/src/main/resources/mapper/modules/MemberWalletCoinMapper.xml index 24d9634..def3d3d 100644 --- a/src/main/resources/mapper/modules/MemberWalletCoinMapper.xml +++ b/src/main/resources/mapper/modules/MemberWalletCoinMapper.xml @@ -18,6 +18,12 @@ where address=#{address} </update> + <update id="updateTdCoinWalletTrc20"> + update td_coin_wallet + set available_balance=available_balance+#{money} + where mem_id=#{memberId} and symbol ='USDT' + </update> + <select id="selectMemberWalletCoinByMemberId" resultType="java.util.HashMap"> select member_id, diff --git a/src/main/resources/mapper/modules/TrcAddressDao.xml b/src/main/resources/mapper/modules/TrcAddressDao.xml new file mode 100644 index 0000000..2e7663f --- /dev/null +++ b/src/main/resources/mapper/modules/TrcAddressDao.xml @@ -0,0 +1,16 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" > +<mapper namespace="com.xcong.excoin.modules.member.mapper.TrcAddressDao"> + + <select id="selectSrcAddressByMemberId" resultType="com.xcong.excoin.modules.member.entity.TrcAddressEntity"> + select * from trc_address where member_id=#{memberId} and is_use=1 and system_flag = 1 + </select> + + <select id="selectOneSrcAddressUnUse" resultType="com.xcong.excoin.modules.member.entity.TrcAddressEntity"> + select * from trc_address where is_use=2 limit 1 + </select> + + <select id="selectTrcAddressByAddress" resultType="com.xcong.excoin.modules.member.entity.TrcAddressEntity"> + select * from trc_address where address = #{address} + </select> +</mapper> \ No newline at end of file -- Gitblit v1.9.1