|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //回报率 | 
|---|
|  |  |  | BigDecimal returnRate = profitLossPrice.divide((order.getPrePaymentAmount().subtract(contractOrderEntity.getOpeningFeeAmount())), 8, BigDecimal.ROUND_DOWN); | 
|---|
|  |  |  | BigDecimal returnRate = profitLossPrice.divide((order.getBondAmount().subtract(contractOrderEntity.getOpeningFeeAmount())), 8, BigDecimal.ROUND_DOWN); | 
|---|
|  |  |  | contractOrderEntity.setRewardAmount(profitLossPrice); | 
|---|
|  |  |  | contractOrderEntity.setRewardRatio(returnRate); | 
|---|
|  |  |  | contractOrderEntity.setClosingFeeAmount(order.getOpeningFeeAmount()); | 
|---|
|  |  |  | contractOrderEntity.setClosingPrice(closePrice); | 
|---|
|  |  |  | contractOrderEntity.setClosingType(6); | 
|---|
|  |  |  | contractOrderEntity.setOrderType(ContractOrderEntity.ORDER_TYPE_CLOSE_MORE); | 
|---|
|  |  |  | BigDecimal totalReturn = BigDecimal.ZERO; | 
|---|
|  |  |  | contractOrderService.save(contractOrderEntity); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | contractEntrustOrderService.removeById(order.getId()); | 
|---|
|  |  |  | contractHoldOrderService.removeById(order.getId()); | 
|---|
|  |  |  | // 将需要退回的减去手续费 | 
|---|
|  |  |  | BigDecimal needReturn = prePrice.add(profitLossPrice); | 
|---|
|  |  |  | //总退回金额=保证金+收益-手续费 | 
|---|
|  |  |  | totalReturn = needReturn.subtract(contractOrderEntity.getClosingFeeAmount()); | 
|---|
|  |  |  | // 总的是收益-平仓手续费 | 
|---|
|  |  |  | BigDecimal totalBalance = profitLossPrice.subtract(contractOrderEntity.getClosingFeeAmount()); | 
|---|
|  |  |  | memberWalletContractService.increaseWalletContractBalanceById(totalBalance, totalReturn, null, wallet.getId()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | memberWalletContractService.increaseWalletContractBalanceById(totalReturn, totalBalance, null, wallet.getId()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 流水记录 TODO 531e | 
|---|
|  |  |  | insertAccountFlow(order, wallet, profitLossPrice, "止盈平仓"); | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //回报率 | 
|---|
|  |  |  | BigDecimal returnRate = profitLossPrice.divide((order.getPrePaymentAmount().subtract(contractOrderEntity.getOpeningFeeAmount())), 8, BigDecimal.ROUND_DOWN); | 
|---|
|  |  |  | BigDecimal returnRate = profitLossPrice.divide((order.getBondAmount().subtract(contractOrderEntity.getOpeningFeeAmount())), 8, BigDecimal.ROUND_DOWN); | 
|---|
|  |  |  | contractOrderEntity.setRewardAmount(profitLossPrice); | 
|---|
|  |  |  | contractOrderEntity.setRewardRatio(returnRate); | 
|---|
|  |  |  | contractOrderEntity.setClosingFeeAmount(order.getOpeningFeeAmount()); | 
|---|
|  |  |  | contractOrderEntity.setClosingPrice(closePrice); | 
|---|
|  |  |  | contractOrderEntity.setClosingType(7); | 
|---|
|  |  |  | contractOrderEntity.setOrderType(ContractOrderEntity.ORDER_TYPE_CLOSE_MORE); | 
|---|
|  |  |  | BigDecimal totalReturn = BigDecimal.ZERO; | 
|---|
|  |  |  | contractOrderService.save(contractOrderEntity); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | // 更新钱包 | 
|---|
|  |  |  | // 总的是收益-平仓手续费 | 
|---|
|  |  |  | BigDecimal totalBalance = profitLossPrice.subtract(contractOrderEntity.getClosingFeeAmount()); | 
|---|
|  |  |  | memberWalletContractService.increaseWalletContractBalanceById(totalBalance, totalReturn, null, wallet.getId()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | memberWalletContractService.increaseWalletContractBalanceById(totalReturn, totalBalance, null, wallet.getId()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | insertAccountFlow(order, wallet, profitLossPrice, "止盈平仓"); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //回报率 | 
|---|
|  |  |  | BigDecimal returnRate = profitLossPrice.divide((order.getPrePaymentAmount().subtract(contractOrderEntity.getOpeningFeeAmount())), 8, BigDecimal.ROUND_DOWN); | 
|---|
|  |  |  | BigDecimal returnRate = profitLossPrice.divide((order.getBondAmount().subtract(contractOrderEntity.getOpeningFeeAmount())), 8, BigDecimal.ROUND_DOWN); | 
|---|
|  |  |  | contractOrderEntity.setRewardAmount(profitLossPrice); | 
|---|
|  |  |  | contractOrderEntity.setRewardRatio(returnRate); | 
|---|
|  |  |  | contractOrderEntity.setClosingFeeAmount(order.getOpeningFeeAmount()); | 
|---|
|  |  |  | contractOrderEntity.setClosingPrice(closePrice); | 
|---|
|  |  |  | contractOrderEntity.setOrderType(ContractOrderEntity.ORDER_TYPE_CLOSE_MORE); | 
|---|
|  |  |  | contractOrderEntity.setClosingType(8); | 
|---|
|  |  |  | BigDecimal totalReturn = BigDecimal.ZERO; | 
|---|
|  |  |  | contractOrderService.save(contractOrderEntity); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | contractHoldOrderService.removeById(order.getId()); | 
|---|
|  |  |  | // 将需要退回的减去手续费 | 
|---|
|  |  |  | BigDecimal needReturn = prePrice.add(profitLossPrice); | 
|---|
|  |  |  | //总退回金额=保证金+收益-手续费 | 
|---|
|  |  |  | 
|---|
|  |  |  | // 更新钱包 | 
|---|
|  |  |  | // 总的是收益-平仓手续费 | 
|---|
|  |  |  | BigDecimal totalBalance = profitLossPrice.subtract(contractOrderEntity.getClosingFeeAmount()); | 
|---|
|  |  |  | memberWalletContractService.increaseWalletContractBalanceById(totalBalance, totalReturn, null, wallet.getId()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | memberWalletContractService.increaseWalletContractBalanceById(totalReturn, totalBalance, null, wallet.getId()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | insertAccountFlow(order, wallet, profitLossPrice, "开多止损平仓"); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | String symbol = order.getSymbol(); | 
|---|
|  |  |  | Long memberId = order.getMemberId(); | 
|---|
|  |  |  | // 本次需要退回的预付款 | 
|---|
|  |  |  | BigDecimal prePrice = order.getPrePaymentAmount(); | 
|---|
|  |  |  | BigDecimal prePrice = order.getBondAmount(); | 
|---|
|  |  |  | MemberWalletContractEntity wallet = memberWalletContractService.findWalletContractByMemberIdAndSymbol(memberId, "USDT"); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (wallet != null) { | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //回报率 | 
|---|
|  |  |  | BigDecimal returnRate = profitLossPrice.divide((order.getPrePaymentAmount().subtract(contractOrderEntity.getClosingFeeAmount())), 8, BigDecimal.ROUND_DOWN); | 
|---|
|  |  |  | BigDecimal returnRate = profitLossPrice.divide((order.getBondAmount().subtract(contractOrderEntity.getOpeningFeeAmount())), 8, BigDecimal.ROUND_DOWN); | 
|---|
|  |  |  | contractOrderEntity.setRewardAmount(profitLossPrice); | 
|---|
|  |  |  | contractOrderEntity.setRewardRatio(returnRate); | 
|---|
|  |  |  | contractOrderEntity.setClosingFeeAmount(order.getOpeningFeeAmount()); | 
|---|
|  |  |  | contractOrderEntity.setClosingPrice(closePrice); | 
|---|
|  |  |  | contractOrderEntity.setClosingType(9); | 
|---|
|  |  |  | contractOrderEntity.setOrderType(ContractOrderEntity.ORDER_TYPE_CLOSE_LESS); | 
|---|
|  |  |  | BigDecimal totalReturn = BigDecimal.ZERO; | 
|---|
|  |  |  | contractOrderService.save(contractOrderEntity); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | contractHoldOrderService.removeById(order.getId()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 将需要退回的减去手续费 | 
|---|
|  |  |  | BigDecimal needReturn = prePrice.add(profitLossPrice); | 
|---|
|  |  |  | //总退回金额=保证金+收益-手续费 | 
|---|
|  |  |  | 
|---|
|  |  |  | // 更新钱包 | 
|---|
|  |  |  | // 总的是收益-平仓手续费 | 
|---|
|  |  |  | BigDecimal totalBalance = profitLossPrice.subtract(contractOrderEntity.getClosingFeeAmount()); | 
|---|
|  |  |  | memberWalletContractService.increaseWalletContractBalanceById(totalBalance, totalReturn, null, wallet.getId()); | 
|---|
|  |  |  | memberWalletContractService.increaseWalletContractBalanceById(totalReturn, totalBalance, null, wallet.getId()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | insertAccountFlow(order, wallet, profitLossPrice, "开空止损平仓"); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | contractOrderEntity.setEntrustOpeningPrice(coinsCoinsOrder.getEntrustPrice()); | 
|---|
|  |  |  | contractOrderEntity.setEntrustTime(coinsCoinsOrder.getCreateTime()); | 
|---|
|  |  |  | contractOrderEntity.setOpeningTime(new Date()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | contractOrderEntity.setId(null); | 
|---|
|  |  |  | contractOrderService.save(contractOrderEntity); | 
|---|
|  |  |  | // 发送爆仓的队列 | 
|---|
|  |  |  | 
|---|
|  |  |  | // 扣除手续费 | 
|---|
|  |  |  | BigDecimal totalBalance = openFeePrice.negate(); | 
|---|
|  |  |  | contractEntrustOrderService.removeById(coinsCoinsOrder.getId()); | 
|---|
|  |  |  | memberWalletContractService.increaseWalletContractBalanceById(null, totalBalance, null, wallet.getId()); | 
|---|
|  |  |  | memberWalletContractService.increaseWalletContractBalanceById(null, totalBalance, coinsCoinsOrder.getBondAmount().negate(), wallet.getId()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //返佣 | 
|---|
|  |  |  | ThreadPoolUtils.calReturnMoney(memberEntity.getId(), openFeePrice, contractOrderEntity, AgentReturnEntity.ORDER_TYPE_OPEN); | 
|---|
|  |  |  | 
|---|
|  |  |  | if (isDone) { | 
|---|
|  |  |  | //删除次仓订单 | 
|---|
|  |  |  | contractHoldOrderService.removeById(orderId); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 订单状态转换 | 
|---|
|  |  |  | if (ContractOrderEntity.ORDER_TYPE_OPEN_MORE == contractOrderEntity.getOrderType()) { | 
|---|
|  |  |  | contractOrderEntity.setOrderType(ContractOrderEntity.ORDER_TYPE_CLOSE_MORE); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | contractOrderEntity.setOrderType(ContractOrderEntity.ORDER_TYPE_CLOSE_LESS); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //更新主表订单状态位为“已平仓” | 
|---|
|  |  |  | contractOrderEntity.setId(null); | 
|---|
|  |  |  | contractOrderEntity.setClosingPrice(BigDecimal.ZERO); | 
|---|
|  |  |  | contractOrderEntity.setClosingPrice(nowPrice); | 
|---|
|  |  |  | contractOrderEntity.setClosingTime(new Date()); | 
|---|
|  |  |  | contractOrderEntity.setRewardAmount(coinsOrder.getPrePaymentAmount().negate()); | 
|---|
|  |  |  | contractOrderEntity.setClosingFeeAmount(coinsOrder.getOpeningFeeAmount()); | 
|---|
|  |  |  | contractOrderEntity.setRewardAmount(coinsOrder.getBondAmount().subtract(contractOrderEntity.getOpeningFeeAmount()).negate()); | 
|---|
|  |  |  | contractOrderService.save(contractOrderEntity); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //更新用户钱包数据 | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 减去的时候用负数 | 
|---|
|  |  |  | BigDecimal totalPrice = coinsOrder.getBondAmount().negate(); | 
|---|
|  |  |  | memberWalletContractService.increaseWalletContractBalanceById(null, totalPrice, totalPrice, usdt.getId()); | 
|---|
|  |  |  | memberWalletContractService.increaseWalletContractBalanceById(null, totalPrice, null, usdt.getId()); | 
|---|
|  |  |  | // 流水记录 TODO | 
|---|
|  |  |  | MemberAccountFlowEntity record = new MemberAccountFlowEntity(); | 
|---|
|  |  |  | record.setCreateTime(new Date()); | 
|---|