From 788deca1b4a24f8a24e49c24f7d89975a1d74bbe Mon Sep 17 00:00:00 2001 From: admin <2780501319@qq.com> Date: 星期日, 03 十一月 2019 23:31:25 +0800 Subject: [PATCH] 商城订单退款处理 --- fanli/src/main/java/com/yeshi/fanli/service/impl/redpack/RedPackBalanceServiceImpl.java | 27 ++++++++++++++++----------- 1 files changed, 16 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 b975434..2cf5583 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; @@ -33,15 +33,14 @@ public BigDecimal getBalance(Long uid) { if (uid == null || uid == 0) return null; - + RedPackBalance redPackBalance = redPackBalanceMapper.selectByPrimaryKey(uid); if (redPackBalance != null) return redPackBalance.getMoney(); - + return null; } - - + @Override public void addRedPack(Long uid, BigDecimal money) { if (uid == null || uid == 0 || money == null) @@ -58,27 +57,33 @@ 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); // 鍑忓皯绾㈠寘 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