zyy
2025-07-18 96e443a77b1d425d3e536c288fc271fe182f1496
src/main/java/com/nq/service/impl/UserStockSubscribeServiceImpl.java
@@ -5,6 +5,7 @@
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.nq.Repository.ExchangeRateRepository;
import com.nq.common.ResponseCode;
import com.nq.common.ServerResponse;
import com.nq.dao.StockSubscribeMapper;
@@ -69,6 +70,9 @@
    @Autowired
    UserAssetsMapper userAssetsMapper;
    @Autowired
    ExchangeRateRepository exchangeRateRepository;
    /**
     * 用户新股申购
@@ -148,7 +152,6 @@
                }else{
                    bound =  new BigDecimal(model.getApplyNums()).multiply(stockSubscribe.getPrice());
                }
                if(stockSubscribe.getType() == 1){
                    model.setUserId(user.getId());
                    model.setNewName(stockSubscribe.getName());
@@ -165,6 +168,10 @@
                    userStockSubscribe.setNewStockId(stockSubscribe.getNewlistId());
                    ret = userStockSubscribeMapper.insert(userStockSubscribe);
                    //如果不是墨西哥币需要转换金额
                    if (!stockSubscribe.getStockType().equals(EStockType.MX.getCode())) {
                        bound = iUserAssetsServices.exchangeAmountByRate(stockSubscribe.getStockType(), bound);
                    }
                    BigDecimal subtract = userAssets.getAvailableBalance().subtract(bound);
                    if(subtract.compareTo(BigDecimal.ZERO) >= 0){
                        userAssets.setFreezeMoney(userAssets.getFreezeMoney().add(bound));
@@ -268,12 +275,20 @@
                        if(applyNumber > 0){
                            //需要退回的资金
                            BigDecimal refundPrice = userStockSubscribe.getBuyPrice().multiply(new BigDecimal(applyNumber));
                            //如果不是墨西哥币需要转换金额
                            if (!stockSubscribe.getStockType().equals(EStockType.MX.getCode())) {
                                refundPrice = iUserAssetsServices.exchangeAmountByRate(stockSubscribe.getStockType(), refundPrice);
                            }
                            userAssets.setAvailableBalance(userAssets.getAvailableBalance().add(refundPrice));
                            userAssets.setFreezeMoney(userAssets.getFreezeMoney().subtract(refundPrice));
                        }
                    }else{
                        if(applyNumber > 0){
                            BigDecimal refundPrice = userStockSubscribe.getBuyPrice().multiply(new BigDecimal(applyNumber));
                            //如果不是墨西哥币需要转换金额
                            if (!stockSubscribe.getStockType().equals(EStockType.MX.getCode())) {
                                refundPrice = iUserAssetsServices.exchangeAmountByRate(stockSubscribe.getStockType(), refundPrice);
                            }
                            BigDecimal subtract = refundPrice.subtract(userAssets.getAmountToBeCovered());
                            if(subtract.compareTo(BigDecimal.ZERO) <= 0){//如果退回的资金不足补足待补则直接减
                                userAssets.setAmountToBeCovered(userAssets.getAmountToBeCovered().subtract(refundPrice));