| | |
| | | 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; |
| | |
| | | |
| | | @Autowired |
| | | UserAssetsMapper userAssetsMapper; |
| | | |
| | | @Autowired |
| | | ExchangeRateRepository exchangeRateRepository; |
| | | |
| | | /** |
| | | * 用户新股申购 |
| | |
| | | }else{ |
| | | bound = new BigDecimal(model.getApplyNums()).multiply(stockSubscribe.getPrice()); |
| | | } |
| | | |
| | | if(stockSubscribe.getType() == 1){ |
| | | model.setUserId(user.getId()); |
| | | model.setNewName(stockSubscribe.getName()); |
| | |
| | | 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)); |
| | |
| | | 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)); |