| | |
| | | import com.yami.trading.common.domain.Result; |
| | | import com.yami.trading.common.exception.BusinessException; |
| | | import com.yami.trading.common.exception.YamiShopBindException; |
| | | import com.yami.trading.common.util.Arith; |
| | | import com.yami.trading.dao.loan.LoanParamMapper; |
| | | import com.yami.trading.service.MoneyLogService; |
| | | import com.yami.trading.service.WalletService; |
| | |
| | | stateMap.put(3, "驳回"); |
| | | stateMap.put(4, "已逾期"); |
| | | stateMap.put(5, "已还款"); |
| | | stateMap.put(6, "提交还款申请"); |
| | | |
| | | repayments.put(1,"到期还本息"); |
| | | repayments.put(2,"到期还本金"); |
| | |
| | | System.out.println(update); |
| | | |
| | | return true; |
| | | } |
| | | |
| | | @Override |
| | | public Boolean refundLoanOrder(String orderNo, String userId) { |
| | | try { |
| | | if(null==orderNo || (orderNo=orderNo.trim()).isEmpty()) { |
| | | throw new BusinessException("申请单ID不能为空!"); |
| | | } |
| | | SimpleLoanOrder loanOrder = getLoanOrder(null, orderNo); |
| | | if(loanOrder == null) { |
| | | throw new BusinessException("找不到订单!"); |
| | | } |
| | | |
| | | //利息 |
| | | double interest = loanOrder.getQuota().multiply(loanOrder.getDailyRate()).doubleValue(); |
| | | //还款金额 |
| | | double amt = loanOrder.getQuota().doubleValue() + interest; |
| | | BigDecimal amtBD = new BigDecimal(amt).negate(); |
| | | if (!loanOrder.getSymbol().equalsIgnoreCase("usdt")) { |
| | | ExchangeRate exchangeRate = exchangeRateService.findBy(ExchangeRate.IN, loanOrder.getSymbol().toUpperCase()); |
| | | if (exchangeRate == null) { |
| | | throw new YamiShopBindException("汇率未设置"); |
| | | } |
| | | BigDecimal money = BigDecimal.valueOf(amt).divide(exchangeRate.getRata(), 8, RoundingMode.HALF_UP); |
| | | amt = money.doubleValue(); |
| | | } |
| | | |
| | | //通过 |
| | | Wallet wallet = this.walletService.saveWalletByPartyId(loanOrder.getPartyId()); |
| | | if (wallet.getMoney().compareTo(BigDecimal.valueOf(amt)) < 0) { |
| | | throw new YamiShopBindException("余额不足!"); |
| | | } |
| | | |
| | | double amountBefore = wallet.getMoney().doubleValue(); |
| | | this.walletService.update(wallet.getUserId(), Arith.sub(0, amt)); |
| | | MoneyLog log = new MoneyLog(); |
| | | log.setCategory(Constants.MONEYLOG_CATEGORY_LOAN); |
| | | log.setAmountBefore(new BigDecimal(amountBefore)); |
| | | log.setAmount(amtBD); |
| | | log.setAmountAfter(BigDecimal.valueOf(amountBefore - amt)); |
| | | log.setLog("借贷还款,订单号[" + loanOrder.getUuid() + "]"); |
| | | log.setUserId(loanOrder.getPartyId()); |
| | | log.setWalletType(loanOrder.getSymbol().toUpperCase()); |
| | | log.setContentType(Constants.MONEYLOG_CONTENT_LOAN_REPAY); |
| | | moneyLogService.save(log); |
| | | |
| | | int count = jdbcTemplate.update("UPDATE T_SIMPLE_LOAN_ORDER SET state=? WHERE UUID=?",6, orderNo); |
| | | if(1!=count) { |
| | | return false; |
| | | } |
| | | return true; |
| | | } catch (Exception e) { |
| | | log.error(e.getMessage()); |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | @Override |
| | |
| | | } |
| | | |
| | | int state=Integer.parseInt(status); |
| | | if (state==2) { |
| | | if (state==2) { //放款 |
| | | SimpleLoanOrder loanOrder = getLoanOrder(null, orderId); |
| | | if(loanOrder == null) { |
| | | throw new BusinessException("找不到订单!"); |
| | |
| | | log.setWalletType(loanOrder.getSymbol().toUpperCase()); |
| | | log.setContentType(Constants.MONEYLOG_CONTENT_LOAN_ADD); |
| | | moneyLogService.save(log); |
| | | } else if (state==7) { //拒绝还款 |
| | | SimpleLoanOrder loanOrder = getLoanOrder(null, orderId); |
| | | if(loanOrder == null) { |
| | | throw new BusinessException("找不到订单!"); |
| | | } |
| | | |
| | | //利息 |
| | | double interest = loanOrder.getQuota().multiply(loanOrder.getDailyRate()).doubleValue(); |
| | | //退回金额 |
| | | double amt = loanOrder.getQuota().doubleValue() + interest; |
| | | BigDecimal amtBD = new BigDecimal(amt); |
| | | if (!loanOrder.getSymbol().equalsIgnoreCase("usdt")) { |
| | | ExchangeRate exchangeRate = exchangeRateService.findBy(ExchangeRate.IN, loanOrder.getSymbol().toUpperCase()); |
| | | if (exchangeRate == null) { |
| | | throw new YamiShopBindException("汇率未设置"); |
| | | } |
| | | BigDecimal money = BigDecimal.valueOf(amt).divide(exchangeRate.getRata(), 8, RoundingMode.HALF_UP); |
| | | amt = money.doubleValue(); |
| | | } |
| | | |
| | | //通过 |
| | | Wallet wallet = this.walletService.saveWalletByPartyId(loanOrder.getPartyId()); |
| | | double amountBefore = wallet.getMoney().doubleValue(); |
| | | this.walletService.update(wallet.getUserId(), amt); |
| | | MoneyLog log = new MoneyLog(); |
| | | log.setCategory(Constants.MONEYLOG_CATEGORY_LOAN); |
| | | log.setAmountBefore(new BigDecimal(amountBefore)); |
| | | log.setAmount(amtBD); |
| | | log.setAmountAfter(BigDecimal.valueOf(amountBefore + amt)); |
| | | log.setLog("借贷还款退回,订单号[" + loanOrder.getUuid() + "]"); |
| | | log.setUserId(loanOrder.getPartyId()); |
| | | log.setWalletType(loanOrder.getSymbol().toUpperCase()); |
| | | log.setContentType(Constants.MONEYLOG_CONTENT_LOAN_REPAY_RETURN); |
| | | moneyLogService.save(log); |
| | | |
| | | state=2; //状态退回待还款 |
| | | } |
| | | |
| | | |