admin
2020-11-14 5e54f329dfe0220ae6ca878f6502a00ba95c774c
service-goldcorn/src/main/java/com/ks/goldcorn/service/GoldCornBalanceManager.java
@@ -1,7 +1,7 @@
package com.ks.goldcorn.service;
import com.ks.goldcorn.exception.GoldTradeException;
import com.ks.goldcorn.exception.GoldUserException;
import com.ks.goldcorn.mapper.GoldCornAppInfoMapper;
import com.ks.goldcorn.mapper.GoldCornBalanceMapper;
import com.ks.goldcorn.pojo.DO.GoldCornBalance;
import org.springframework.stereotype.Component;
@@ -26,11 +26,16 @@
    @Transactional(rollbackFor = Exception.class)
    public void subMoney(Long appId, String uid, int money) throws GoldUserException {
    public void subMoney(Long appId, String uid, int money) throws GoldUserException, GoldTradeException {
        GoldCornBalance balance = goldCornBalanceMapper.selectByAppIdAndUidForUpdate(appId, uid);
        if (balance == null) {
            throw new GoldUserException(GoldUserException.CODE_NOT_EXIST, "uid is not exist");
        }
        if (balance.getBalance() < money) {
            throw new GoldUserException(GoldTradeException.CODE_BALANCE_NOT_ENOUGH, "余额不足");
        }
        goldCornBalanceMapper.subMoney(balance.getId(), money);
    }
}