From 9cadad100ba1d3c18966f9df7e1c3213abc0d214 Mon Sep 17 00:00:00 2001
From: zyy <zyy@email.com>
Date: Tue, 26 Aug 2025 18:34:24 +0800
Subject: [PATCH] ico新增预支付
---
trading-order-service/src/main/java/com/yami/trading/service/ico/IcoService.java | 125 +++++++++++++++++++++++------------------
1 files changed, 70 insertions(+), 55 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 4084f60..6fd54b0 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
@@ -1,10 +1,7 @@
package com.yami.trading.service.ico;
-import cn.hutool.core.convert.Convert;
import cn.hutool.core.date.DateTime;
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
-import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yami.trading.bean.ico.domain.Ico;
import com.yami.trading.bean.ico.domain.UserSubscription;
@@ -22,16 +19,12 @@
import com.yami.trading.service.MoneyLogService;
import com.yami.trading.service.WalletService;
import com.yami.trading.service.user.UserService;
-import com.yami.trading.service.user.WalletExtendService;
-import io.swagger.v3.oas.annotations.parameters.RequestBody;
import lombok.extern.slf4j.Slf4j;
-import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
-import javax.validation.Valid;
import java.math.BigDecimal;
import java.util.Date;
@@ -56,13 +49,8 @@
@Autowired
MoneyLogService moneyLogService;
- @Autowired
- WalletExtendService walletExtendService;
-
/**
* 新币申购
- * @param model
- * @return
*/
public Result<String> subscribe(UserSubscription model) {
try {
@@ -91,10 +79,6 @@
}
//购买金额
BigDecimal amount = ico.getUnitAmount().multiply(new BigDecimal(model.getSubscribeNums()));
- /*Wallet wallet = walletService.saveWalletByPartyId(partyId);
- if (amount.compareTo(wallet.getMoney()) > 0) {
- throw new YamiShopBindException("余额不足");
- }*/
if(amount.compareTo(ico.getMinContribution()) < 0 ){
throw new YamiShopBindException("最低投资额: " + ico.getMinContribution());
}
@@ -114,21 +98,29 @@
if (model.getSubscriptionType() == null) { //默认自主申购
model.setSubscriptionType(1);
}
- userSubscriptionService.save(model);
- /*walletService.update(partyId, Arith.sub(0, amount.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.setUserId(partyId);
- moneylog.setSymbol(ico.getSymbol());
- moneylog.setWalletType(ico.getSymbol());
- moneylog.setContentType(Constants.MONEYLOG_CONTENT_NEW_COIN_OPEN);
- moneyLogService.save(moneylog);*/
+ //需要先支付
+ if (ico.getIsPayDown() !=null && ico.getIsPayDown() == 1) {
+ Wallet wallet = walletService.saveWalletByPartyId(partyId);
+ if (amount.compareTo(wallet.getMoney()) > 0) {
+ throw new YamiShopBindException("余额不足");
+ }
+ walletService.update(partyId, Arith.sub(0, amount.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.setUserId(partyId);
+ moneylog.setSymbol(ico.getSymbol());
+ moneylog.setWalletType(ico.getSymbol());
+ moneylog.setContentType(Constants.MONEYLOG_CONTENT_NEW_COIN_BUY);
+ moneyLogService.save(moneylog);
+ }
+ userSubscriptionService.save(model);
return Result.ok("申请成功" );
} catch (Exception e) {
throw new RuntimeException(e);
@@ -155,6 +147,7 @@
throw new YamiShopBindException("不能更改申购状态");
}
Ico ico = this.getById(model.getIcoProjectId());
+ String userId = userSubscription.getUserId();
if (model.getStatus() == 3 || model.getStatus() == 5) {
if(model.getBallotNumber() == null || model.getBallotNumber() == 0){
throw new YamiShopBindException("中签数量不能小于0");
@@ -166,40 +159,62 @@
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(userSubscription.getUserId());
- 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("操作钱包失败!");
+ //已经预支付
+ if(ico.getIsPayDown() !=null && ico.getIsPayDown() == 1) {
+ if(applyNumber > 0) {
+ //退回资金
+ BigDecimal refundPrice = ico.getUnitAmount().multiply(new BigDecimal(applyNumber));
+ walletService.update(userId, refundPrice.doubleValue());
+
+ //保存 资金日志
+ 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.setUserId(userId);
+ moneylog.setSymbol(ico.getSymbol());
+ moneylog.setWalletType(ico.getSymbol());
+ moneylog.setContentType(Constants.MONEYLOG_CONTENT_NEW_COIN_RT_BUY);
+ moneyLogService.save(moneylog);
}
} else {
- //扣除资金
- walletService.update(userSubscription.getUserId(), amount.negate().doubleValue());
+ 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());
+ }
+ //保存 资金日志
+ 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.setUserId(userId);
+ moneylog.setSymbol(ico.getSymbol());
+ moneylog.setWalletType(ico.getSymbol());
+ moneylog.setContentType(Constants.MONEYLOG_CONTENT_NEW_COIN_BUY);
+ moneyLogService.save(moneylog);
}
- //保存 资金日志
- 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.setUserId(userSubscription.getUserId());
- moneylog.setSymbol(ico.getSymbol());
- moneylog.setWalletType(ico.getSymbol());
- moneylog.setContentType(Constants.MONEYLOG_CONTENT_NEW_COIN_OPEN);
- moneyLogService.save(moneylog);
userSubscription.setStatus(5);
}
if (model.getStatus() == 3 || model.getStatus() == 5) { //转入账户
//获取币账户
- WalletExtend walletExtend = walletService.saveExtendByPara(userSubscription.getUserId(), ico.getSymbol());
- walletService.updateExtend(userSubscription.getUserId(), walletExtend.getWallettype(), model.getBallotNumber());
+ WalletExtend walletExtend = walletService.saveExtendByPara(userId, ico.getSymbol());
+ walletService.updateExtend(userId, walletExtend.getWallettype(), model.getBallotNumber());
}
userSubscriptionService.save(userSubscription);
return Result.ok ( "操作成功" );
--
Gitblit v1.9.3