From 54e6398cabe1b32b1dbc9857c6a99d8f15b549f7 Mon Sep 17 00:00:00 2001 From: yujian <yujian@123.com> Date: 星期三, 06 十一月 2019 15:31:44 +0800 Subject: [PATCH] 红包信息 --- fanli/src/main/java/com/yeshi/fanli/service/impl/redpack/RedPackBalanceServiceImpl.java | 26 +++++++++++++++----------- 1 files changed, 15 insertions(+), 11 deletions(-) diff --git a/fanli/src/main/java/com/yeshi/fanli/service/impl/redpack/RedPackBalanceServiceImpl.java b/fanli/src/main/java/com/yeshi/fanli/service/impl/redpack/RedPackBalanceServiceImpl.java index 227f4f7..b112cb1 100644 --- a/fanli/src/main/java/com/yeshi/fanli/service/impl/redpack/RedPackBalanceServiceImpl.java +++ b/fanli/src/main/java/com/yeshi/fanli/service/impl/redpack/RedPackBalanceServiceImpl.java @@ -20,7 +20,7 @@ @Resource private RedPackBalanceMapper redPackBalanceMapper; - + @Resource private RedPackDetailService redPackDetailService; @@ -36,12 +36,10 @@ RedPackBalance redPackBalance = redPackBalanceMapper.selectByPrimaryKey(uid); if (redPackBalance != null) - return redPackBalance.getMoney(); - + return redPackBalance.getMoney(); return new BigDecimal(0); } - - + @Override public void addRedPack(Long uid, BigDecimal money) { if (uid == null || uid == 0 || money == null) @@ -58,12 +56,11 @@ 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) + if (uid == null || uid == 0 || money == null || detail == null) throw new RedPackBalanceException(1, "鍙傛暟浼犻�掍笉瀹屾暣"); // 鍔犲叆鏄庣粏 redPackDetailService.insertSelective(detail); @@ -80,15 +77,22 @@ redPackBalanceMapper.addRedPack(uid, money); } } - - + @Override @Transactional(rollbackFor = Exception.class) public void subRedPack(Long uid, BigDecimal money, RedPackDetail detail) throws RedPackBalanceException { - if (uid == null || uid == 0 || money == null || detail == null) + if (uid == null || uid == 0 || money == null || detail == null) throw new RedPackBalanceException(1, "鍙傛暟浼犻�掍笉瀹屾暣"); // 鍔犲叆鏄庣粏 redPackDetailService.insertSelective(detail); + + RedPackBalance balance = redPackBalanceMapper.selectForUpdate(uid); + if (balance.getMoney() == null) + throw new RedPackBalanceException(2, "绾㈠寘浣欓涓嶈冻"); + + if (balance.getMoney().compareTo(money) < 0) + throw new RedPackBalanceException(2, "绾㈠寘浣欓涓嶈冻"); + // 鍑忓皯绾㈠寘 redPackBalanceMapper.subRedPack(uid, money); } -- Gitblit v1.8.0