| @@ -527,34 +527,9 @@ public class WxCouponOrderServiceImpl implements WxCouponOrderService { | |||||
| WxPayAccount wxPayAccount = wxPayAccountMapper.selectOne(new QueryWrapper<>(wxPayAccountQuery)); | WxPayAccount wxPayAccount = wxPayAccountMapper.selectOne(new QueryWrapper<>(wxPayAccountQuery)); | ||||
| if (wxPayAccount != null && wxPayAccount.getShare().equals(EnumPayShare.NO.getCode())) { | if (wxPayAccount != null && wxPayAccount.getShare().equals(EnumPayShare.NO.getCode())) { | ||||
| try { | try { | ||||
| // 核销记账 | |||||
| // 核销记账,并且往账户里面记帐 | |||||
| if (couponOrder.getCouponPrice() > 0) { | 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) { | } catch (Exception e) { | ||||
| logger.error("核销记账失败"+e.getMessage(),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) { | public WxMerchantSubsidy recordAfterVerified(WxCouponOrder couponOrder, Long merchantId) { | ||||
| WxCoupon wxCoupon = wxCouponMapper.selectById(couponOrder.getCouponId(),couponOrder.getTenantId()); | WxCoupon wxCoupon = wxCouponMapper.selectById(couponOrder.getCouponId(),couponOrder.getTenantId()); | ||||
| WxMerchantSubsidy merchantSubsidy = new WxMerchantSubsidy(); | WxMerchantSubsidy merchantSubsidy = new WxMerchantSubsidy(); | ||||
| @@ -626,6 +602,33 @@ public class WxCouponOrderServiceImpl implements WxCouponOrderService { | |||||
| merchantSubsidy.setUpdateDate(curDate); | merchantSubsidy.setUpdateDate(curDate); | ||||
| merchantSubsidy.setStatus(EnumMerchantSubsidyStatus.NOT_SUBSIDY.getCode()); | merchantSubsidy.setStatus(EnumMerchantSubsidyStatus.NOT_SUBSIDY.getCode()); | ||||
| wxMerchantSubsidyMapper.insert(merchantSubsidy); | 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; | return merchantSubsidy; | ||||
| } | } | ||||