From c37e84a5bc4629475da4a38415a231f121d39c61 Mon Sep 17 00:00:00 2001 From: yujian <yujian@123.com> Date: 星期四, 07 十一月 2019 12:28:57 +0800 Subject: [PATCH] 品牌 --- fanli/src/main/java/com/yeshi/fanli/service/impl/redpack/RedPackBalanceServiceImpl.java | 28 +++++++++++++++++----------- 1 files changed, 17 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..7da0ce9 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) @@ -51,6 +49,7 @@ redPackBalance = new RedPackBalance(); redPackBalance.setId(uid); redPackBalance.setMoney(money); + redPackBalance.setState(RedPackBalance.STATE_INIT); redPackBalance.setCreateTime(new Date()); redPackBalance.setUpdateTime(new Date()); redPackBalanceMapper.insertSelective(redPackBalance); @@ -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); @@ -73,6 +71,7 @@ redPackBalance = new RedPackBalance(); redPackBalance.setId(uid); redPackBalance.setMoney(money); + redPackBalance.setState(RedPackBalance.STATE_INIT); redPackBalance.setCreateTime(new Date()); redPackBalance.setUpdateTime(new Date()); redPackBalanceMapper.insertSelective(redPackBalance); @@ -80,15 +79,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