From 58aa9ff8da187d28afc6934bb06d1fe7cc78c987 Mon Sep 17 00:00:00 2001
From: Helius <wangdoubleone@gmail.com>
Date: Thu, 12 Nov 2020 11:54:55 +0800
Subject: [PATCH] modify
---
src/main/java/com/xcong/excoin/modules/coin/controller/Trc20Controller.java | 70 +++++++++++++++++++++++++++++++++++
src/main/java/com/xcong/excoin/modules/coin/parameter/dto/TrcWithdrawDto.java | 39 +++++++++++++++++++
2 files changed, 109 insertions(+), 0 deletions(-)
diff --git a/src/main/java/com/xcong/excoin/modules/coin/controller/Trc20Controller.java b/src/main/java/com/xcong/excoin/modules/coin/controller/Trc20Controller.java
index 4dc7faf..5ed9f32 100644
--- a/src/main/java/com/xcong/excoin/modules/coin/controller/Trc20Controller.java
+++ b/src/main/java/com/xcong/excoin/modules/coin/controller/Trc20Controller.java
@@ -1,5 +1,6 @@
package com.xcong.excoin.modules.coin.controller;
+import cn.hutool.core.collection.CollUtil;
import cn.hutool.crypto.SecureUtil;
import com.xcong.excoin.common.enumerates.CoinTypeEnum;
import com.xcong.excoin.common.response.Result;
@@ -8,9 +9,12 @@
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.coin.parameter.dto.TrcWithdrawDto;
import com.xcong.excoin.modules.member.dao.MemberCoinChargeDao;
+import com.xcong.excoin.modules.member.dao.MemberCoinWithdrawDao;
import com.xcong.excoin.modules.member.dao.MemberWalletCoinDao;
import com.xcong.excoin.modules.member.entity.MemberCoinChargeEntity;
+import com.xcong.excoin.modules.member.entity.MemberCoinWithdrawEntity;
import com.xcong.excoin.modules.member.entity.MemberWalletCoinEntity;
import com.xcong.excoin.utils.TRC20ApiUtils;
import lombok.extern.slf4j.Slf4j;
@@ -21,6 +25,9 @@
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
/**
* @author wzy
@@ -39,6 +46,8 @@
private MemberCoinChargeDao memberCoinChargeDao;
@Resource
private TrcAddressDao trcAddressDao;
+ @Resource
+ private MemberCoinWithdrawDao memberCoinWithdrawDao;
@PostMapping(value = "/rechargeTrcAmount")
@Transactional(rollbackFor = Exception.class)
@@ -78,6 +87,67 @@
return Result.ok("充值成功");
}
+ @PostMapping(value = "/withdrawTrcAmount")
+ public Result withdrawTrcAmount(@RequestBody TrcWithdrawDto trcWithdrawDto) {
+ if (!CoinTypeEnum.USDT.name().equals(trcWithdrawDto.getSymbol())) {
+ return Result.fail("币种错误");
+ }
+
+ if (!TrcWithdrawDto.STATUS_SUCCESS.equals(trcWithdrawDto.getStatus()) && !TrcWithdrawDto.STATUS_FAIL.equals(trcWithdrawDto.getStatus())) {
+ return Result.fail("状态错误");
+ }
+
+ String sign = SecureUtil.md5(trcWithdrawDto.getMemberId() + trcWithdrawDto.getOrderNo() + trcWithdrawDto.getStatus() + trcWithdrawDto.getSymbol());
+ if (!sign.equals(trcWithdrawDto.getKey())) {
+ return Result.fail("参数错误");
+ }
+
+ Map<String, Object> columnMaps = new HashMap<>();
+ columnMaps.put("tag", trcWithdrawDto.getOrderNo());
+ columnMaps.put("member_id", trcWithdrawDto.getMemberId());
+ columnMaps.put("status", 1);
+ List<MemberCoinWithdrawEntity> withdrawEntities = memberCoinWithdrawDao.selectByMap(columnMaps);
+ if (CollUtil.isEmpty(withdrawEntities)) {
+ return Result.fail("该订单不存在");
+ }
+
+ MemberCoinWithdrawEntity withdrawEntity = withdrawEntities.get(0);
+
+ MemberWalletCoinEntity wallet = memberWalletCoinDao.selectWalletCoinBymIdAndCode(withdrawEntity.getMemberId(), CoinTypeEnum.USDT.name());
+ Map<String, Object> changeParam = new HashMap<>();
+ changeParam.put("withdraw_id", withdrawEntity.getId());
+ MemberAccountMoneyChange accountMoneyChanges = memberAccountMoneyChangeDao.selectByMap(changeParam).get(0);
+
+ // 审核成功
+ if (TrcWithdrawDto.STATUS_SUCCESS.equals(trcWithdrawDto.getStatus())) {
+ memberWalletCoinDao.updateWalletBalance(wallet.getId(), null, null, withdrawEntity.getAmount().negate());
+
+ accountMoneyChanges.setStatus(MemberAccountMoneyChange.STATUS_SUCCESS_INTEGER);
+ accountMoneyChanges.setAmount(withdrawEntity.getAmount().negate());
+ memberAccountMoneyChangeDao.updateById(accountMoneyChanges);
+
+ withdrawEntity.setStatus(MemberCoinWithdrawEntity.IS_STATUS_Y);
+ memberCoinWithdrawDao.updateById(withdrawEntity);
+
+ return Result.ok("提币成功");
+ }
+
+ if (TrcWithdrawDto.STATUS_FAIL.equals(trcWithdrawDto.getStatus())) {
+ memberWalletCoinDao.updateWalletBalance(wallet.getId(), withdrawEntity.getAmount(), null, withdrawEntity.getAmount().negate());
+
+ accountMoneyChanges.setStatus(MemberAccountMoneyChange.STATUS_FAIL_INTEGER);
+ accountMoneyChanges.setAmount(withdrawEntity.getAmount());
+ memberAccountMoneyChangeDao.updateById(accountMoneyChanges);
+
+ withdrawEntity.setStatus(MemberCoinWithdrawEntity.IS_STATUS_N);
+ memberCoinWithdrawDao.updateById(withdrawEntity);
+
+ return Result.ok("提币申请驳回成功");
+ }
+
+ return Result.fail("提币失败");
+ }
+
private String generateNo() {
// 生成订单号
Long timestamp = System.currentTimeMillis();
diff --git a/src/main/java/com/xcong/excoin/modules/coin/parameter/dto/TrcWithdrawDto.java b/src/main/java/com/xcong/excoin/modules/coin/parameter/dto/TrcWithdrawDto.java
new file mode 100644
index 0000000..758ec6b
--- /dev/null
+++ b/src/main/java/com/xcong/excoin/modules/coin/parameter/dto/TrcWithdrawDto.java
@@ -0,0 +1,39 @@
+package com.xcong.excoin.modules.coin.parameter.dto;
+
+import lombok.Data;
+
+import javax.validation.constraints.NotBlank;
+import javax.validation.constraints.NotNull;
+
+/**
+ * @author wzy
+ * @date 2020-11-12
+ **/
+@Data
+public class TrcWithdrawDto {
+
+ /**
+ * 审核成功
+ */
+ public static final Integer STATUS_SUCCESS = 1;
+ /**
+ * 审核失败
+ */
+ public static final Integer STATUS_FAIL = 2;
+
+ @NotBlank(message = "用户ID不能为空")
+ private Long memberId;
+
+ @NotBlank(message = "订单号不能为空")
+ private String orderNo;
+
+ @NotNull(message = "审核状态不能为空")
+ private Integer status;
+
+ @NotBlank(message = "币种不能为空")
+ private String symbol;
+
+ // orderNo + status + symbol + 密钥
+ @NotBlank(message = "参数错误")
+ private String key;
+}
--
Gitblit v1.9.1