From 77d195f023c4205bb6d2dfda4ab6ec326e8d4512 Mon Sep 17 00:00:00 2001 From: xiaohanzi Date: Thu, 15 Apr 2021 10:12:18 +0800 Subject: [PATCH] fix cash out --- .../impl/WxCouponOrderServiceImpl.java | 57 ++++++++++--------- 1 file changed, 30 insertions(+), 27 deletions(-) diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxCouponOrderServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxCouponOrderServiceImpl.java index e22062d7d..ea159b54e 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxCouponOrderServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxCouponOrderServiceImpl.java @@ -527,34 +527,9 @@ public class WxCouponOrderServiceImpl implements WxCouponOrderService { WxPayAccount wxPayAccount = wxPayAccountMapper.selectOne(new QueryWrapper<>(wxPayAccountQuery)); if (wxPayAccount != null && wxPayAccount.getShare().equals(EnumPayShare.NO.getCode())) { try { - // 核销记账 + // 核销记账,并且往账户里面记帐 if (couponOrder.getCouponPrice() > 0) { - WxMerchantSubsidy subsidy = recordAfterVerified(couponOrder, bUser.getMerchantId()); - - //是否开通了商户提现,开通了商户提现往商户账户里面加金额 - WxMall mall = wxMallMapper.getByTenantId(couponOrder.getTenantId()); - if (null != mall && mall.getCashOutSupport().intValue() == EnumCashOut.YES.getCode().intValue()) { - WxMerchant merchant = wxMerchantMapper.selectById(bUser.getMerchantId()); - if (null != merchant) { - //此处需要加锁,防止并发设置 - long time = System.currentTimeMillis() + RedisLock.TIMEOUT; - String timeStr = String.valueOf(time); - boolean cashsetlock = redisLock.lock("merchantLockCashSet_"+merchant.getId(), timeStr); - if (cashsetlock) { - try { - merchant.setCashOutNumber(couponOrder.getCouponPrice()); - wxMerchantMapper.increaseCash(merchant); - logger.info("wxcoupon update cashout success.wxCouponOrderId:["+couponOrder.getId()+"] subsidyId:["+subsidy.getId()+"]."); - redisLock.unlock("merchantLockCashSet_"+merchant.getId(), timeStr); - }catch(Exception e) { - redisLock.unlock("merchantLockCashSet_"+merchant.getId(), timeStr); - logger.error("update cashout fail.wxCouponOrderId:["+couponOrder.getId()+"] subsidyId:["+subsidy.getId()+"].",e); - }finally { - redisLock.unlock("merchantLockCashSet_"+merchant.getId(), timeStr); - } - } - } - } + recordAfterVerified(couponOrder, bUser.getMerchantId()); } } catch (Exception e) { logger.error("核销记账失败"+e.getMessage(),e); @@ -592,6 +567,7 @@ public class WxCouponOrderServiceImpl implements WxCouponOrderService { } } + @Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) public WxMerchantSubsidy recordAfterVerified(WxCouponOrder couponOrder, Long merchantId) { WxCoupon wxCoupon = wxCouponMapper.selectById(couponOrder.getCouponId(),couponOrder.getTenantId()); WxMerchantSubsidy merchantSubsidy = new WxMerchantSubsidy(); @@ -626,6 +602,33 @@ public class WxCouponOrderServiceImpl implements WxCouponOrderService { merchantSubsidy.setUpdateDate(curDate); merchantSubsidy.setStatus(EnumMerchantSubsidyStatus.NOT_SUBSIDY.getCode()); wxMerchantSubsidyMapper.insert(merchantSubsidy); + + + //是否开通了商户提现,开通了商户提现往商户账户里面加金额 + WxMall mall = wxMallMapper.getByTenantId(couponOrder.getTenantId()); + if (null != mall && mall.getCashOutSupport().intValue() == EnumCashOut.YES.getCode().intValue()) { + WxMerchant merchant = wxMerchantMapper.selectById(merchantId); + if (null != merchant) { + //此处需要加锁,防止并发设置 + long time = System.currentTimeMillis() + RedisLock.TIMEOUT; + String timeStr = String.valueOf(time); + boolean cashsetlock = redisLock.lock("merchantLockCashSet_"+merchant.getId(), timeStr); + if (cashsetlock) { + try { + merchant.setCashOutNumber(couponOrder.getCouponPrice()); + wxMerchantMapper.increaseCash(merchant); + logger.info("wxcoupon update cashout success.wxCouponOrderId:["+couponOrder.getId()+"] subsidyId:["+merchantSubsidy.getId()+"]."); + redisLock.unlock("merchantLockCashSet_"+merchant.getId(), timeStr); + }catch(Exception e) { + redisLock.unlock("merchantLockCashSet_"+merchant.getId(), timeStr); + logger.error("update cashout fail.wxCouponOrderId:["+couponOrder.getId()+"] subsidyId:["+merchantSubsidy.getId()+"].",e); + }finally { + redisLock.unlock("merchantLockCashSet_"+merchant.getId(), timeStr); + } + } + } + } + return merchantSubsidy; }