| | |
| | | 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; |
| | |
| | | |
| | | |
| | | @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); |
| | | } |
| | | } |