Helius
2020-09-13 71b049a8efeb7c887138e51a04259e32e72a8db2
src/main/java/com/xcong/excoin/modules/contract/service/impl/ContractHoldOrderServiceImpl.java
@@ -251,12 +251,12 @@
//                    canAddMaxBond = BigDecimal.ZERO;
//                }
                BigDecimal canReduceMaxBond = holdOrderEntity.getBondAmount().subtract(holdOrderEntity.getPrePaymentAmount());
                if (canReduceMaxBond.compareTo(BigDecimal.ZERO) < 0) {
                    canReduceMaxBond = BigDecimal.ZERO;
                }
                if (rewardRatio.compareTo(BigDecimal.ZERO) < 0) {
                    canReduceMaxBond = canReduceMaxBond.add(rewardRatio);
                }
                if (canReduceMaxBond.compareTo(BigDecimal.ZERO) < 0) {
                    canReduceMaxBond = BigDecimal.ZERO;
                }
                holdOrderListVo.setCanReduceMaxBond(canReduceMaxBond);
@@ -440,6 +440,33 @@
            if (holdOrderEntity.getBondAmount().subtract(holdOrderEntity.getPrePaymentAmount()).subtract(changeBondDto.getAmount()).compareTo(BigDecimal.ZERO) < 0) {
                return Result.fail("超出保证金最大减少金额");
            }
            BigDecimal newPrice = new BigDecimal(redisUtils.getString(CoinTypeConvert.convertToKey(holdOrderEntity.getSymbol())));
            BigDecimal rewardRatio = BigDecimal.ZERO;
            // 开多
            if (ContractHoldOrderEntity.OPENING_TYPE_MORE == holdOrderEntity.getOpeningType()) {
                // (最新价-开仓价)*规格*张数
                rewardRatio = newPrice.subtract(holdOrderEntity.getOpeningPrice()).multiply(holdOrderEntity.getSymbolSku()).multiply(new BigDecimal(holdOrderEntity.getSymbolCnt()));
                // 开空
            } else {
                // (开仓价-最新价)*规格*张数
                rewardRatio = holdOrderEntity.getOpeningPrice().subtract(newPrice).multiply(holdOrderEntity.getSymbolSku()).multiply(new BigDecimal(holdOrderEntity.getSymbolCnt()));
            }
            if (memberEntity.getIsProfit() == MemberEntity.IS_PROFIT_Y) {
                PlatformTradeSettingEntity tradeSettingEntity = cacheSettingUtils.getTradeSetting();
                if (rewardRatio.compareTo(BigDecimal.ZERO) > -1) {
                    rewardRatio = rewardRatio.multiply(BigDecimal.ONE.subtract(tradeSettingEntity.getProfitParam()));
                }
            }
            if (rewardRatio.compareTo(BigDecimal.ZERO) < 0) {
                BigDecimal canReduceMax = holdOrderEntity.getBondAmount().subtract(holdOrderEntity.getPrePaymentAmount()).add(rewardRatio);
                if (canReduceMax.subtract(changeBondDto.getAmount()).compareTo(BigDecimal.ZERO) < 0) {
                    return Result.fail("超出保证金最大减少金额");
                }
            }
            memberWalletContractDao.increaseWalletContractBalanceById(changeBondDto.getAmount(), null, null, walletContract.getId());
            holdOrderEntity.setBondAmount(holdOrderEntity.getBondAmount().subtract(changeBondDto.getAmount()));
        }