| | |
| | | |
| | | import java.io.Serializable; |
| | | import java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | import java.sql.Timestamp; |
| | | import java.util.*; |
| | | import java.util.regex.Pattern; |
| | |
| | | import com.yami.trading.bean.model.MoneyLog; |
| | | import com.yami.trading.bean.model.User; |
| | | import com.yami.trading.bean.model.Wallet; |
| | | import com.yami.trading.bean.rate.domain.ExchangeRate; |
| | | import com.yami.trading.common.constants.Constants; |
| | | 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; |
| | | import com.yami.trading.service.rate.ExchangeRateService; |
| | | import com.yami.trading.service.user.UserService; |
| | | import lombok.Getter; |
| | | import lombok.extern.slf4j.Slf4j; |
| | |
| | | |
| | | @Autowired |
| | | LoanParamMapper loanParamMapper; |
| | | |
| | | @Autowired |
| | | ExchangeRateService exchangeRateService; |
| | | |
| | | @Getter |
| | | HashMap<String,Object> paramMap = new HashMap<>(); |
| | |
| | | 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("找不到订单!"); |
| | | } |
| | | //到账金额 |
| | | double amt = loanOrder.getQuota().doubleValue(); |
| | | 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(); |
| | | } |
| | | |
| | | User user = userService.getById(loanOrder.getPartyId()); |
| | | double remainLoanLimit = user.getLoanLimit() - amt; |
| | | user.setLoanLimit(remainLoanLimit < 0 ? 0 : remainLoanLimit); |
| | | double remainLoanLimit = user.getLoanLimit() - amt < 0 ? 0 : user.getLoanLimit() - amt; |
| | | BigDecimal loanLimit = BigDecimal.valueOf(remainLoanLimit).setScale(2, RoundingMode.HALF_UP); |
| | | user.setLoanLimit(loanLimit.doubleValue()); |
| | | userService.updateById(user); |
| | | |
| | | //通过 |
| | |
| | | MoneyLog log = new MoneyLog(); |
| | | log.setCategory(Constants.MONEYLOG_CATEGORY_LOAN); |
| | | log.setAmountBefore(new BigDecimal(amountBefore)); |
| | | log.setAmount(new BigDecimal(amt)); |
| | | log.setAmountAfter(wallet.getMoney().add(BigDecimal.valueOf(amt))); |
| | | log.setAmount(loanOrder.getQuota()); |
| | | log.setAmountAfter(BigDecimal.valueOf(amountBefore + amt)); |
| | | log.setLog("借贷放款,订单号[" + loanOrder.getUuid() + "]"); |
| | | log.setUserId(loanOrder.getPartyId()); |
| | | log.setWalletType(Constants.WALLET); |
| | | 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; //状态退回待还款 |
| | | } |
| | | |
| | | |