| | |
| | |
|
| | | import java.math.BigDecimal;
|
| | | import java.util.Date;
|
| | | import java.util.List;
|
| | |
|
| | | import javax.annotation.Resource;
|
| | |
|
| | |
| | | import com.yeshi.fanli.exception.redpack.RedPackBalanceException;
|
| | | import com.yeshi.fanli.service.inter.redpack.RedPackBalanceService;
|
| | | import com.yeshi.fanli.service.inter.redpack.RedPackDetailService;
|
| | | import com.yeshi.fanli.vo.redpack.RedPackBalanceVO;
|
| | |
|
| | | @Service
|
| | | public class RedPackBalanceServiceImpl implements RedPackBalanceService {
|
| | |
| | | }
|
| | |
|
| | | @Override
|
| | | public BigDecimal getBalance(Long uid) {
|
| | | public BigDecimal getBalance(Long uid){
|
| | | if (uid == null || uid == 0)
|
| | | return null;
|
| | |
|
| | | return new BigDecimal(0);
|
| | | |
| | | RedPackBalance redPackBalance = redPackBalanceMapper.selectByPrimaryKey(uid);
|
| | | if (redPackBalance != null)
|
| | | return redPackBalance.getMoney();
|
| | |
|
| | | if (redPackBalance != null && redPackBalance.getMoney() != null)
|
| | | return redPackBalance.getMoney(); |
| | | return new BigDecimal(0);
|
| | | }
|
| | |
|
| | |
|
| | | @Override
|
| | | public void addRedPack(Long uid, BigDecimal money) {
|
| | | if (uid == null || uid == 0 || money == null)
|
| | | return;
|
| | | @Transactional(rollbackFor = Exception.class)
|
| | | public void addRedPack(Long uid, BigDecimal money, RedPackDetail detail) throws RedPackBalanceException {
|
| | | if (uid == null || uid == 0 || money == null || detail == null)
|
| | | throw new RedPackBalanceException(1, "参数传递不完整");
|
| | | // 加入明细
|
| | | redPackDetailService.insertSelective(detail);
|
| | | // 添加红包
|
| | | RedPackBalance redPackBalance = redPackBalanceMapper.selectForUpdate(uid);
|
| | | if (redPackBalance == null) {
|
| | | redPackBalance = new RedPackBalance();
|
| | |
| | | } else {
|
| | | redPackBalanceMapper.addRedPack(uid, money);
|
| | | }
|
| | | }
|
| | |
|
| | | @Override
|
| | | @Transactional(rollbackFor = Exception.class)
|
| | | public void addRedPack(Long uid, BigDecimal money, RedPackDetail detail) throws RedPackBalanceException {
|
| | | if (uid == null || uid == 0 || money == null || detail == null)
|
| | | throw new RedPackBalanceException(1, "参数传递不完整");
|
| | | // 加入明细
|
| | | redPackDetailService.insertSelective(detail);
|
| | | // 减少红包
|
| | | redPackBalanceMapper.addRedPack(uid, money);
|
| | | }
|
| | |
|
| | | @Override
|
| | |
| | |
|
| | | if (balance.getMoney().compareTo(money) < 0)
|
| | | throw new RedPackBalanceException(2, "红包余额不足");
|
| | |
|
| | | |
| | | // 减少红包
|
| | | redPackBalanceMapper.subRedPack(uid, money);
|
| | | }
|
| | | |
| | | |
| | | @Override
|
| | | public RedPackBalance selectForUpdate(Long uid) {
|
| | | return redPackBalanceMapper.selectForUpdate(uid);
|
| | | }
|
| | | |
| | | @Override
|
| | | @Transactional(rollbackFor = Exception.class)
|
| | | public void resetRedPack(Long uid, RedPackDetail detail) throws RedPackBalanceException {
|
| | | if (uid == null || uid == 0 || detail == null)
|
| | | throw new RedPackBalanceException(1, "参数传递不完整");
|
| | | // 加入明细
|
| | | redPackDetailService.insertSelective(detail);
|
| | | // 重置
|
| | | redPackBalanceMapper.resetRedPack(uid);
|
| | | }
|
| | | |
| | | |
| | | @Override
|
| | | public List<RedPackBalanceVO> query(Integer start, Integer count, String key, Integer state,Integer order){
|
| | | return redPackBalanceMapper.query(start, count, key, state,order);
|
| | | }
|
| | | |
| | | @Override
|
| | | public long count(String key, Integer state){
|
| | | return redPackBalanceMapper.count(key, state);
|
| | | }
|
| | | |
| | | }
|