| | |
| | | @Transactional |
| | | public Result updateCapitaltWallt(String userId, BigDecimal moneyRevise, int accountType, String coinType) { |
| | | if (accountType == 1 && moneyRevise.compareTo(BigDecimal.ZERO) <= 0) { //充值 |
| | | throw new YamiShopBindException("请输入大于0的数量"); |
| | | throw new YamiShopBindException("Please enter a quantity greater than 0"); |
| | | } |
| | | if (accountType == 2) { |
| | | moneyRevise = moneyRevise.negate(); |
| | |
| | | double amount1 = moneyRevise.doubleValue(); |
| | | CapitaltWallet capitaltWallet = getUserIdWallet(userId); |
| | | if (capitaltWallet == null) { |
| | | throw new YamiShopBindException("账号缺少资金数据"); |
| | | throw new YamiShopBindException("Account is missing fund data"); |
| | | } |
| | | double amount_before = capitaltWallet.getMoney().doubleValue(); |
| | | if (accountType == 2 && capitaltWallet.getMoney().subtract(moneyRevise).compareTo(BigDecimal.ZERO) < 0) { |
| | | throw new YamiShopBindException("账号资金不足"); |
| | | throw new YamiShopBindException("Insufficient account funds"); |
| | | } |
| | | update(capitaltWallet, amount1); |
| | | |
| | |
| | | if (realtimes != null) { |
| | | close = realtimes.get(0).getClose().doubleValue(); |
| | | } else { |
| | | throw new YamiShopBindException("参数错误"); |
| | | throw new YamiShopBindException("Invalid parameters"); |
| | | } |
| | | PurchaseRecord purchaseRecord = purchaseRecordService.getOne(new LambdaQueryWrapper<>(PurchaseRecord.class) |
| | | .eq(PurchaseRecord::getUserId, userId)); |
| | |
| | | } else { |
| | | purchaseRecord.setPurchaseQuantity(purchaseRecord.getPurchaseQuantity().add(new BigDecimal(volume))); |
| | | if (purchaseRecord.getPurchaseQuantity().compareTo(BigDecimal.ZERO) < 0) { |
| | | throw new YamiShopBindException("持仓数量不足"); |
| | | throw new YamiShopBindException("Insufficient position quantity"); |
| | | } |
| | | purchaseRecord.setTotalAmount(purchaseRecord.getTotalAmount().add(amount)); |
| | | //purchaseRecord.setTotalAmount(purchaseRecord.getPurchaseQuantity().multiply(purchaseRecord.getPurchasePrice())); |
| | |
| | | item = itemService.findBySymbol(coinType); |
| | | } |
| | | if (item == null) { |
| | | throw new YamiShopBindException("暂不支持的币种"); |
| | | throw new YamiShopBindException("Unsupported currency"); |
| | | } |
| | | WalletExtend walletExtend = new WalletExtend(); |
| | | walletExtend = walletService.saveExtendByPara(userId, coinType); |
| | |
| | | double amount_before = walletExtend.getAmount(); |
| | | |
| | | if (accountType == 2 && Arith.sub(amount_before, volume) < 0) { |
| | | throw new YamiShopBindException("账号资金不足"); |
| | | throw new YamiShopBindException("Insufficient account funds"); |
| | | } |
| | | |
| | | // walletExtend = walletService.saveWalletExtendByParaAndUpdate(String.valueOf(recharge.getPartyId()), recharge.getSymbol(), volume); |
| | |
| | | public void update(CapitaltWallet capitaltWallet, double amount1) { |
| | | capitaltWallet.setMoney(new BigDecimal(Arith.add(capitaltWallet.getMoney().doubleValue(), amount1))); |
| | | if (!updateById(capitaltWallet)) { |
| | | throw new YamiShopBindException("操作钱包失败!"); |
| | | throw new YamiShopBindException("Wallet operation failed!"); |
| | | } |
| | | } |
| | | } |