From 148af6b2f57be264c84d0991237fbd7ddea491a4 Mon Sep 17 00:00:00 2001 From: yujian <yujian@123.com> Date: 星期一, 04 十一月 2019 09:55:55 +0800 Subject: [PATCH] Merge branch 'div' of ssh://193.112.35.168:29418/fanli-server into div --- fanli/src/main/java/com/yeshi/fanli/service/impl/redpack/RedPackBalanceServiceImpl.java | 23 ++++++++++++++--------- 1 files changed, 14 insertions(+), 9 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..e6ef61b 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; @@ -40,8 +40,7 @@ return new BigDecimal(0); } - - + @Override public void addRedPack(Long uid, BigDecimal money) { if (uid == null || uid == 0 || money == null) @@ -58,12 +57,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 +78,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