From 579177ac64462d0fec885eb10af3097245134f80 Mon Sep 17 00:00:00 2001
From: zj <1772600164@qq.com>
Date: Tue, 02 Jun 2026 10:28:11 +0800
Subject: [PATCH] 1
---
trading-order-admin/src/main/java/com/yami/trading/api/controller/ApiWithdrawController.java | 93 ++++++++++++++++++++++++++--------------------
1 files changed, 53 insertions(+), 40 deletions(-)
diff --git a/trading-order-admin/src/main/java/com/yami/trading/api/controller/ApiWithdrawController.java b/trading-order-admin/src/main/java/com/yami/trading/api/controller/ApiWithdrawController.java
index 5137adc..ac5d4a2 100644
--- a/trading-order-admin/src/main/java/com/yami/trading/api/controller/ApiWithdrawController.java
+++ b/trading-order-admin/src/main/java/com/yami/trading/api/controller/ApiWithdrawController.java
@@ -7,6 +7,7 @@
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.yami.trading.api.UD.*;
+import com.yami.trading.api.util.ServletUtil;
import com.yami.trading.bean.model.CapitaltWallet;
import com.yami.trading.bean.model.RechargeBlockchainOrder;
import com.yami.trading.bean.model.Withdraw;
@@ -89,8 +90,8 @@
@ApiOperation("提现申请")
@PostMapping("apply")
public Result apply(String session_token, String safeword,
- String amount, String from, String currency,
- String channel){
+ String amount, String from, String currency,
+ String channel, String language) {
Result resultObject=new Result();
try {
String partyId = SecurityUtils.getUser().getUserId();
@@ -99,34 +100,24 @@
throw new YamiShopBindException(error);
}
double amount_double = Double.valueOf(amount).doubleValue();
-
// 交易所提现是否需要资金密码
String exchange_withdraw_need_safeword = this.sysparaService.find("exchange_withdraw_need_safeword").getSvalue();
- if(StringUtils.isEmptyString(exchange_withdraw_need_safeword)) {
- throw new YamiShopBindException("系统参数错误");
+ if (StringUtils.isEmptyString(exchange_withdraw_need_safeword)) {
+ throw new YamiShopBindException("System parameter error");
}
-
-// if ("true".equals(exchange_withdraw_need_safeword)) {
-//
-// if (StringUtils.isEmptyString(safeword)) {
-// throw new YamiShopBindException("资金密码不能为空");
-// }
-//
-// if (safeword.length() < 6 || safeword.length() > 12) {
-// throw new YamiShopBindException("资金密码必须6-12位");
-// }
-// if (!userService.checkLoginSafeword(SecurityUtils.getUser().getUserId(),safeword)){
-// throw new YamiShopBindException("资金密码错误");
-// }
-// }
-
- // 获取资金账户(capital)
- CapitaltWallet capitaltWallet = capitaltWalletService.getOne(new LambdaQueryWrapper<>(CapitaltWallet.class)
- .eq(CapitaltWallet::getUserId, partyId).last(" limit 1 "));
- if(capitaltWallet.getMoney().compareTo(new BigDecimal(amount)) < 0){
- throw new YamiShopBindException("Insufficient available balance for withdrawal!");
+ // 开关打开,则验证
+ if ("true".equals(exchange_withdraw_need_safeword)) {
+ // 资金密码验证
+ if (StringUtils.isEmptyString(safeword)) {
+ throw new YamiShopBindException("Fund password is required");
+ }
+ if (safeword.length() < 6 || safeword.length() > 12) {
+ throw new YamiShopBindException("Fund password must be 6-12 characters");
+ }
+ if (!userService.checkLoginSafeword(SecurityUtils.getUser().getUserId(), safeword)) {
+ throw new YamiShopBindException("Incorrect fund password");
+ }
}
-
this.sessionTokenService.del(session_token);
Withdraw withdraw = new Withdraw();
withdraw.setUserId(partyId);
@@ -135,14 +126,25 @@
withdraw.setCurrency(currency);
withdraw.setTx("");
+
//获取商户支持币种
List<Coin> coinList = udunClient.listSupportCoin(false);
- Coin coin = coinList.stream().filter(x -> x.getName().equals(channel)).findFirst().orElse(null);
- if (coin == null) {
- throw new YamiShopBindException("不支持的提现币种");
+ String channelName ;
+ if (channel.toUpperCase().contains("USDC")) {
+ channelName = "USDC";
+ } else {
+ channelName = channel.replace("_", "");
}
+ Coin coin = coinList.stream().filter(x -> x.getName().replace("-","").equals(channelName)).findFirst().orElse(null);
+ if (coin == null) {
+ throw new YamiShopBindException("Unsupported withdrawal currency");
+ }
+ if (!udunClient.checkAddress(coin.getMainCoinType(), from)) {
+ throw new YamiShopBindException("The withdrawal address is abnormal.");
+ }
+
// 保存
- this.withdrawService.saveApply(withdraw, channel, null);
+ this.withdrawService.saveApply(withdraw, channel, language);
ResultMsg resultMsg = udunClient.withdraw(from, withdraw.getVolume(), coin.getMainCoinType(),
coin.getCoinType(), withdraw.getOrderNo(), null);
if (resultMsg.getCode() != HttpStatus.HTTP_OK) {
@@ -150,14 +152,19 @@
throw new UdunException(resultMsg.getCode(), resultMsg.getMessage());
}
resultObject.setCode(0);
+ } catch (YamiShopBindException e) { // 1. 显式捕获业务异常,优先处理
+ resultObject.setCode(1);
+ resultObject.setMsg("失败");
+ log.error("业务异常: {}", e.getMessage());
+ throw e;
} catch (UdunException e) {
resultObject.setCode(1);
- resultObject.setMsg(e.getMessage());
- log.error("error:" + e.getMessage());
+ resultObject.setMsg("失败");
+ log.error("Withdraw ud error:{}", e.getMessage());
throw e;
} catch (Throwable t) {
resultObject.setCode(1);
- resultObject.setMsg(t.getMessage());
+ resultObject.setMsg("失败");
log.error("error: {}", t.getMessage());
throw new RuntimeException(t);
}
@@ -173,6 +180,7 @@
ResultMsg resultMsg = new ResultMsg();
try{
+ log.info("===withdrawCallback===:{}", body);
boolean flag = udunClient.checkSign(timestamp, nonce, body, sign);
log.info("===withdrawCallback===sign:{}", flag);
@@ -193,7 +201,12 @@
resultMsg.setCode(200);
return resultMsg;
}
- withdrawService.examineOk(order_no, Long.valueOf(withdraw.getUserId()));
+ Integer status = Integer.valueOf(map.get("status").toString());
+ if (status == 3) { //交易成功
+ withdrawService.examineOk(withdraw.getUuid(), null);
+ } else if(status == 2) { //驳回
+ withdrawService.reject(withdraw.getUuid(), "订单失败:" + status, "withdrawCallback");
+ }
resultMsg.setCode(200);
}catch (Exception e){
resultMsg.setCode(500);
@@ -213,7 +226,7 @@
public Result get(@RequestParam String order_no) throws IOException {
Withdraw withdraw = this.withdrawService.findByOrderNo(order_no);
if (withdraw==null){
- throw new YamiShopBindException("订单不存在!");
+ throw new YamiShopBindException("Order does not exist");
}
Map<String, Object> map = new HashMap<String, Object>();
map.put("order_no", withdraw.getOrderNo());
@@ -243,10 +256,10 @@
page_no = "1";
}
if (!StringUtils.isInteger(page_no)) {
- throw new YamiShopBindException("页码不是整数");
+ throw new YamiShopBindException("Page number must be an integer");
}
if (Integer.valueOf(page_no).intValue() <= 0) {
- throw new YamiShopBindException("页码不能小于等于0");
+ throw new YamiShopBindException("Page number must be greater than 0");
}
int page_no_int = Integer.valueOf(page_no).intValue();
List<Map<String, Object>> data = this.walletLogService.pagedQueryWithdraw(page_no_int, 10, SecurityUtils.getUser().getUserId(), "1").getRecords();
@@ -352,13 +365,13 @@
private String verif(String amount) {
if (StringUtils.isNullOrEmpty(amount)) {
- return "提币数量必填";
+ return "Withdrawal amount is required";
}
if (!StringUtils.isDouble(amount)) {
- return "提币数量输入错误,请输入浮点数";
+ return "Invalid withdrawal amount, please enter a number";
}
if (Double.valueOf(amount).doubleValue() <= 0) {
- return "提币数量不能小于等于0";
+ return "Withdrawal amount must be greater than 0";
}
return null;
}
--
Gitblit v1.9.3