From f31fc9f42f78de0808e7f4bdc797c5e622df09e3 Mon Sep 17 00:00:00 2001
From: zj <1772600164@qq.com>
Date: Wed, 10 Jun 2026 11:22:37 +0800
Subject: [PATCH] 1
---
trading-order-service/src/main/java/com/yami/trading/service/ico/IcoService.java | 122 ++++++++++++++++++++++++----------------
1 files changed, 73 insertions(+), 49 deletions(-)
diff --git a/trading-order-service/src/main/java/com/yami/trading/service/ico/IcoService.java b/trading-order-service/src/main/java/com/yami/trading/service/ico/IcoService.java
index 6cebe22..03a2fbb 100644
--- a/trading-order-service/src/main/java/com/yami/trading/service/ico/IcoService.java
+++ b/trading-order-service/src/main/java/com/yami/trading/service/ico/IcoService.java
@@ -54,12 +54,12 @@
*/
public Result<String> subscribe(UserSubscription model) {
if (model == null || model.getIcoProjectId() == null) {
- throw new YamiShopBindException("参数异常");
+ throw new YamiShopBindException("Invalid parameters");
}
String partyId = model.getUserId();
Ico ico = this.getById(model.getIcoProjectId());
if (ico == null) {
- throw new YamiShopBindException("新币不存在");
+ throw new YamiShopBindException("New coin does not exist");
}
User party = userService.getById(partyId);
@@ -67,26 +67,26 @@
throw new YamiShopBindException("User is locked");
}
if (Constants.SECURITY_ROLE_TEST.equals(party.getRoleName())) {
- throw new YamiShopBindException("无权限");
+ throw new YamiShopBindException("Permission denied");
}
if (model.getSubscribeNums() == null || model.getSubscribeNums() == 0) {
- throw new YamiShopBindException("申请数量不能为空");
+ throw new YamiShopBindException("Application quantity cannot be empty");
}
//购买金额
BigDecimal amount = ico.getUnitAmount().multiply(new BigDecimal(model.getSubscribeNums()));
if(amount.compareTo(ico.getMinContribution()) < 0 ){
- throw new YamiShopBindException("最低投资额: " + ico.getMinContribution());
+ throw new YamiShopBindException("Minimum investment: " + ico.getMinContribution());
}
if(amount.compareTo(ico.getMaxContribution()) > 0 ){
- throw new YamiShopBindException("最高投资额: " + ico.getMaxContribution());
+ throw new YamiShopBindException("Maximum investment: " + ico.getMaxContribution());
}
Date currentDate = new Date();
if(currentDate.before(ico.getStartDate())){
- throw new YamiShopBindException("未开售");
+ throw new YamiShopBindException("Not yet on sale");
}
if(currentDate.after(ico.getEndDate())){
- throw new YamiShopBindException("已结束");
+ throw new YamiShopBindException("Already ended");
}
model.setStatus(1);
@@ -95,21 +95,29 @@
model.setSubscriptionType(1);
}
+ Wallet wallet = walletService.saveWalletByPartyId(partyId);
+ if(wallet.getAmountToBeCovered().compareTo(BigDecimal.ZERO) > 0){
+ throw new YamiShopBindException("Please pay outstanding supplementary funds first");
+ }
+
//需要先支付
if (ico.getIsPayDown() !=null && ico.getIsPayDown() == 1) {
- Wallet wallet = walletService.saveWalletByPartyId(partyId);
- if (amount.compareTo(wallet.getMoney()) > 0) {
- throw new YamiShopBindException("余额不足");
+ //手续费
+ BigDecimal fee = ico.getUnitFee().multiply(new BigDecimal(model.getSubscribeNums()));
+ BigDecimal totalAmount = amount.add(fee);
+ if (totalAmount.compareTo(wallet.getMoney()) > 0) {
+ throw new YamiShopBindException("Insufficient balance");
}
- walletService.update(partyId, Arith.sub(0, amount.doubleValue()));
+ BigDecimal before = wallet.getMoney();
+ walletService.update(partyId, totalAmount.negate().doubleValue());
// 保存 资金日志
MoneyLog moneylog = new MoneyLog();
moneylog.setCategory(Constants.MONEYLOG_CONTENT_NEW_COIN);
- moneylog.setAmountBefore(wallet.getMoney());
- moneylog.setAmount(amount);
- moneylog.setAmountAfter(BigDecimal.valueOf(Arith.sub(wallet.getMoney().doubleValue(), amount.doubleValue())));
- moneylog.setLog("新币购买,申购金额[" + amount + "]");
+ moneylog.setAmountBefore(before);
+ moneylog.setAmount(totalAmount.negate());
+ moneylog.setAmountAfter(before.subtract(totalAmount));
+ moneylog.setLog("新币购买,申购金额[" + amount + "]" + "手续费金额[" + fee + "]");
moneylog.setUserId(partyId);
moneylog.setSymbol(ico.getSymbol());
moneylog.setWalletType(ico.getSymbol());
@@ -124,11 +132,11 @@
public Result <String> updateRecord(UserSubscription model) {
try {
if( model.getId() == null || model.getStatus() == null){
- throw new YamiShopBindException("请输入参数");
+ throw new YamiShopBindException("Please enter parameters");
}
UserSubscription userSubscription = userSubscriptionService.getById(model.getId());
if (userSubscription == null) {
- throw new YamiShopBindException("记录不存在");
+ throw new YamiShopBindException("Record does not exist");
}
if (model.getStatus() == 3|| model.getStatus() == 2) {
userSubscription.setEndTime(DateTime.now());
@@ -136,40 +144,63 @@
if (userSubscription.getStatus() == 5) {
throw new YamiShopBindException("It's been converted");
}
- if(userSubscription.getStatus() == 3){
- throw new YamiShopBindException("不能更改申购状态");
+ if(userSubscription.getStatus() == 3 || userSubscription.getStatus() == 2){
+ throw new YamiShopBindException("Subscription status cannot be changed");
}
Ico ico = this.getById(userSubscription.getIcoProjectId());
String userId = userSubscription.getUserId();
if (model.getStatus() == 3 || model.getStatus() == 5) {
if(model.getBallotNumber() == null || model.getBallotNumber() == 0){
- throw new YamiShopBindException("中签数量不能小于0");
+ throw new YamiShopBindException("Allotted quantity cannot be less than 0");
}
if(model.getBallotNumber() > userSubscription.getSubscribeNums()){
- throw new YamiShopBindException("配置中签数量不能超过申请数量");
+ throw new YamiShopBindException("Configured allotted quantity cannot exceed application quantity");
}
}
userSubscription.setStatus(model.getStatus());
userSubscription.setBallotNumber(model.getBallotNumber());
- if (model.getStatus() == 3) { //中签
- //资金账户
- Wallet wallet = walletService.saveWalletByPartyId(userId);
- int applyNumber = userSubscription.getSubscribeNums() - model.getBallotNumber();
- BigDecimal amount = ico.getUnitAmount().multiply(new BigDecimal(applyNumber));
+
+ //资金账户
+ Wallet wallet = walletService.saveWalletByPartyId(userId);
+ BigDecimal before = wallet.getMoney();
+ if (model.getStatus() == 2) { //未中签
+ //预支付退回全部资金
+ if(ico.getIsPayDown() !=null && ico.getIsPayDown() == 1) {
+ BigDecimal refundPrice = ico.getUnitAmount().multiply(new BigDecimal(userSubscription.getSubscribeNums()));
+ BigDecimal fee = ico.getUnitFee().multiply(new BigDecimal(userSubscription.getSubscribeNums()));
+ BigDecimal totalAmount = refundPrice.add(fee);
+ wallet = walletService.updateToBeCovered(wallet, totalAmount, 1);
+ //保存 资金日志
+ MoneyLog moneylog = new MoneyLog();
+ moneylog.setCategory(Constants.MONEYLOG_CONTENT_NEW_COIN);
+ moneylog.setAmountBefore(before);
+ moneylog.setAmount(totalAmount);
+ moneylog.setAmountAfter(wallet.getMoney());
+ moneylog.setLog("新币未中签,退回金额[" + refundPrice + "]" + "退回手续费[" + fee + "]");
+ moneylog.setUserId(userId);
+ moneylog.setSymbol(ico.getSymbol());
+ moneylog.setWalletType(ico.getSymbol());
+ moneylog.setContentType(Constants.MONEYLOG_CONTENT_NEW_COIN_RT_BUY);
+ moneyLogService.save(moneylog);
+ }
+ } else if (model.getStatus() == 3) { //中签
//已经预支付
if(ico.getIsPayDown() !=null && ico.getIsPayDown() == 1) {
+ long applyNumber = userSubscription.getSubscribeNums() - model.getBallotNumber();
if(applyNumber > 0) {
//退回资金
BigDecimal refundPrice = ico.getUnitAmount().multiply(new BigDecimal(applyNumber));
- walletService.update(userId, refundPrice.doubleValue());
+ BigDecimal fee = ico.getUnitFee().multiply(new BigDecimal(applyNumber));
+ BigDecimal totalAmount = refundPrice.add(fee);
+ wallet = walletService.updateToBeCovered(wallet, totalAmount, 1);
//保存 资金日志
MoneyLog moneylog = new MoneyLog();
moneylog.setCategory(Constants.MONEYLOG_CONTENT_NEW_COIN);
- moneylog.setAmountBefore(wallet.getMoney());
- moneylog.setAmount(amount);
- moneylog.setAmountAfter(wallet.getMoney().add(refundPrice));
- moneylog.setLog("新币购买,退回购买金额[" + refundPrice + "]");
+ moneylog.setAmountBefore(before);
+ moneylog.setAmount(totalAmount);
+ moneylog.setAmountAfter(wallet.getMoney());
+ moneylog.setLog("新币购买,退回金额[" + refundPrice + "]" + "退回手续费[" + fee + "]");
moneylog.setUserId(userId);
moneylog.setSymbol(ico.getSymbol());
moneylog.setWalletType(ico.getSymbol());
@@ -177,25 +208,18 @@
moneyLogService.save(moneylog);
}
} else {
- BigDecimal subtract = amount.subtract(wallet.getMoney());
- if (subtract.compareTo(BigDecimal.ZERO) > 0) {
- //放入待补
- wallet.setMoney(BigDecimal.ZERO);
- wallet.setAmountToBeCovered(subtract);
- if (!walletService.updateById(wallet)) {
- throw new YamiShopBindException("操作钱包失败!");
- }
- } else {
- //扣除资金
- walletService.update(userId, amount.negate().doubleValue());
- }
+ BigDecimal amount = ico.getUnitAmount().multiply(new BigDecimal(model.getBallotNumber()));
+ //手续费
+ BigDecimal fee = ico.getUnitFee().multiply(new BigDecimal(model.getBallotNumber()));
+ BigDecimal totalAmount = amount.add(fee);
+ wallet = walletService.updateToBeCovered(wallet, totalAmount, 2);
//保存 资金日志
MoneyLog moneylog = new MoneyLog();
moneylog.setCategory(Constants.MONEYLOG_CONTENT_NEW_COIN);
- moneylog.setAmountBefore(wallet.getMoney());
- moneylog.setAmount(amount);
- moneylog.setAmountAfter(subtract.compareTo(BigDecimal.ZERO) > 0 ? BigDecimal.ZERO : subtract.negate());
- moneylog.setLog("新币购买,申购金额[" + amount + "]");
+ moneylog.setAmountBefore(before);
+ moneylog.setAmount(totalAmount.negate());
+ moneylog.setAmountAfter(wallet.getMoney());
+ moneylog.setLog("新币购买,申购金额[" + amount + "]" + "手续费金额[" + fee + "]");
moneylog.setUserId(userId);
moneylog.setSymbol(ico.getSymbol());
moneylog.setWalletType(ico.getSymbol());
@@ -236,7 +260,7 @@
item.setTradeStatus("1");
item.setQuoteCurrency(ico.getCurrency());
item.setCurrencyType(1); //新币
- item.setStatus(0);
+ item.setStatus(1);
item.setTradeType(ico.getIsContractTrading().toString());
return item;
}
--
Gitblit v1.9.3