1
zyy
3 days ago 30c77267af456dce1d1dede3a69b493c7ae8611c
1
1 files modified
80 ■■■■■ changed files
trading-order-admin/src/main/java/com/yami/trading/admin/controller/loan/internal/LoanServiceImpl.java 80 ●●●●● patch | view | raw | blame | history
trading-order-admin/src/main/java/com/yami/trading/admin/controller/loan/internal/LoanServiceImpl.java
@@ -2,6 +2,7 @@
import java.io.Serializable;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.sql.Timestamp;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
@@ -16,11 +17,18 @@
import com.yami.trading.bean.finance.Finance;
import com.yami.trading.bean.loan.LoanParam;
import com.yami.trading.bean.loan.SimpleLoanOrder;
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.user.UserService;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
@@ -52,6 +60,12 @@
    @Autowired
    LoanParamMapper loanParamMapper;
    @Autowired
    WalletService walletService;
    @Autowired
    MoneyLogService moneyLogService;
    @Getter
    HashMap<String,Object> paramMap = new HashMap<>();
@@ -413,12 +427,72 @@
        if(null==orderId || (orderId=orderId.trim()).isEmpty()) {
            throw new BusinessException("申请单ID不能为空!");
        }
        if(null==status || (status=status.trim()).isEmpty()) {
            throw new BusinessException("审核状态不能为空!");
        }
        SimpleLoanOrder loanOrder = getLoanOrder(null, orderId);
        if(loanOrder == null) {
            throw new BusinessException("找不到订单!");
        }
        int state=Integer.parseInt(status);
        if (state==2) {  //放款
            //到账金额
            double amt = loanOrder.getQuota().doubleValue();
            if (!loanOrder.getSymbol().equalsIgnoreCase("usdt")) {
                throw new BusinessException("请贷款usdt!");
            }
            /*User user = userService.getById(loanOrder.getPartyId());
            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);*/
            //通过
            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(loanOrder.getQuota());
            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_ADD);
            moneyLogService.save(log);
        } else if (state==5) {  //还款
            //利息
            double interest = loanOrder.getQuota().multiply(loanOrder.getDailyRate()).doubleValue();
            //还款金额
            double amt = loanOrder.getQuota().doubleValue() + interest;
            BigDecimal amtBD = new BigDecimal(amt).negate();
            //通过
            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=0;
        if(StringUtils.isNotBlank(reason)) {
            count = jdbcTemplate.update("UPDATE T_SIMPLE_LOAN_ORDER SET state=?,REASON=? WHERE UUID=?",state,reason,orderId);
@@ -428,7 +502,7 @@
        if(1!=count) {
            throw new BusinessException("根据申请单ID修改了多条记录,说明申请单ID重复!");
        }
        return true;
    }