| | |
| | | package com.xcong.excoin.modules.coin.controller;/** |
| | | * |
| | | package com.xcong.excoin.modules.coin.controller; |
| | | |
| | | import cn.hutool.crypto.SecureUtil; |
| | | import com.xcong.excoin.common.enumerates.CoinTypeEnum; |
| | | import com.xcong.excoin.common.response.Result; |
| | | import com.xcong.excoin.modules.coin.dao.MemberAccountMoneyChangeDao; |
| | | import com.xcong.excoin.modules.coin.dao.TrcAddressDao; |
| | | import com.xcong.excoin.modules.coin.entity.MemberAccountMoneyChange; |
| | | import com.xcong.excoin.modules.coin.entity.TrcAddressEntity; |
| | | import com.xcong.excoin.modules.coin.parameter.dto.TrcRechargeDto; |
| | | import com.xcong.excoin.modules.member.dao.MemberCoinChargeDao; |
| | | import com.xcong.excoin.modules.member.dao.MemberWalletCoinDao; |
| | | import com.xcong.excoin.modules.member.entity.MemberCoinChargeEntity; |
| | | import com.xcong.excoin.modules.member.entity.MemberWalletCoinEntity; |
| | | import com.xcong.excoin.utils.TRC20ApiUtils; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | | import org.springframework.web.bind.annotation.RequestBody; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | |
| | | import javax.annotation.Resource; |
| | | |
| | | /** |
| | | * @author wzy |
| | | * @date 2020-11-10 |
| | | **/ |
| | | @Slf4j |
| | | @RestController |
| | | @RequestMapping(value = "/trc") |
| | | public class Trc20Controller { |
| | | |
| | | @Resource |
| | | private MemberWalletCoinDao memberWalletCoinDao; |
| | | @Resource |
| | | private MemberAccountMoneyChangeDao memberAccountMoneyChangeDao; |
| | | @Resource |
| | | private MemberCoinChargeDao memberCoinChargeDao; |
| | | @Resource |
| | | private TrcAddressDao trcAddressDao; |
| | | |
| | | @PostMapping(value = "/rechargeTrcAmount") |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public Result rechargeTrcAmount(@RequestBody TrcRechargeDto trcRechargeDto) { |
| | | log.info("传入参数 : {}", trcRechargeDto); |
| | | String sign = SecureUtil.md5(trcRechargeDto.getNum() + trcRechargeDto.getNum().toPlainString() + CoinTypeEnum.USDT.name() + trcRechargeDto.getType() + TRC20ApiUtils.SIGN_STR); |
| | | if (!sign.equals(trcRechargeDto.getKey())) { |
| | | return Result.fail("参数错误"); |
| | | } |
| | | Long memberId = Long.parseLong(trcRechargeDto.getUid()); |
| | | |
| | | MemberWalletCoinEntity wallet = memberWalletCoinDao.selectWalletCoinBymIdAndCode(memberId, CoinTypeEnum.USDT.name()); |
| | | memberWalletCoinDao.updateWalletBalance(wallet.getId(), trcRechargeDto.getNum(), null, null); |
| | | |
| | | TrcAddressEntity trcAddress = trcAddressDao.selectSrcAddressByMemberId(memberId); |
| | | MemberCoinChargeEntity charge = new MemberCoinChargeEntity(); |
| | | charge.setAddress(trcAddress.getAddress()); |
| | | charge.setAmount(trcRechargeDto.getNum()); |
| | | charge.setMemberId(memberId); |
| | | charge.setSymbol(CoinTypeEnum.USDT.name()); |
| | | charge.setStatus(1); |
| | | charge.setTag("TRC20"); |
| | | charge.setLastAmount(trcRechargeDto.getNum()); |
| | | String orderNo = generateNo(); |
| | | charge.setOrderCode(orderNo); |
| | | memberCoinChargeDao.insert(charge); |
| | | |
| | | MemberAccountMoneyChange change = new MemberAccountMoneyChange(); |
| | | change.setAmount(trcRechargeDto.getNum()); |
| | | change.setContent("转入"); |
| | | change.setSymbol(CoinTypeEnum.USDT.name()); |
| | | change.setStatus(1); |
| | | change.setType(1); |
| | | change.setMemberId(memberId); |
| | | |
| | | memberAccountMoneyChangeDao.insert(change); |
| | | return Result.ok("充值成功"); |
| | | } |
| | | |
| | | private String generateNo() { |
| | | // 生成订单号 |
| | | Long timestamp = System.currentTimeMillis(); |
| | | // 随机数 |
| | | int random = (int) (Math.random() * 10); |
| | | return String.valueOf(timestamp).substring(2) + random; |
| | | } |
| | | } |