| @@ -5,6 +5,7 @@ import com.iformall.common.ResultData; | |||
| import com.iformall.domain.po.*; | |||
| import com.iformall.domain.po.base.TenantEntity; | |||
| import com.iformall.enums.EnumPayWay; | |||
| import com.iformall.exception.MallinkException; | |||
| public interface WxCashOutService { | |||
| @@ -48,4 +49,6 @@ public interface WxCashOutService { | |||
| */ | |||
| ResultData reCashout(WxMerchantBUser buser,WxCashOut record,EnumPayWay payWay); | |||
| void addCashOut(Long merchantId,Integer amount) throws MallinkException; | |||
| } | |||
| @@ -73,6 +73,9 @@ public class WxCardSpendServiceImpl implements WxCardSpendService { | |||
| @Autowired | |||
| WxScoreRulesService wxScoreRulesService; | |||
| @Autowired | |||
| WxCashOutService wxCashOutService; | |||
| @Override | |||
| public WxCouponMerchant checkMerchantInCoupon(WxCardInfo cardInfo, Long merchantId) { | |||
| @@ -277,12 +280,19 @@ public class WxCardSpendServiceImpl implements WxCardSpendService { | |||
| // } | |||
| // } else { | |||
| // 有价储值卡消费时,如果未启用分账,金额也记入补贴表,可能会导致查询错误, TODO | |||
| if (cardInfo.getSaleAmount() > 0 && payment > 0) { | |||
| try { | |||
| creteMerchantSubsidy(record, curDate, idWorker, coupon, payment); | |||
| } catch (Exception ex) { | |||
| logger.error("记录到结算表失败"); | |||
| } | |||
| if (cardInfo.getSaleAmount() > 0) { | |||
| if (payment > 0) { | |||
| try { | |||
| creteMerchantSubsidy(record, curDate, idWorker, coupon, payment); | |||
| } catch (Exception ex) { | |||
| logger.error("记录到结算表失败"); | |||
| } | |||
| } | |||
| //更新商户余额 | |||
| if (real_payment > 0) { | |||
| wxCashOutService.addCashOut(couponMerchant.getMerchantId(), real_payment); | |||
| } | |||
| } | |||
| // } | |||
| @@ -18,6 +18,7 @@ import com.iformall.enums.EnumMsgMqTag; | |||
| import com.iformall.enums.EnumMsgMqTopic; | |||
| import com.iformall.enums.EnumMsgRecordType; | |||
| import com.iformall.enums.EnumPayWay; | |||
| import com.iformall.exception.MallinkException; | |||
| import com.iformall.mapper.*; | |||
| import com.iformall.mq.MqBaseProducer; | |||
| import com.iformall.service.*; | |||
| @@ -317,4 +318,31 @@ public class WxCashOutServiceImpl implements WxCashOutService { | |||
| // } | |||
| return new ResultData(); | |||
| } | |||
| @Override | |||
| public void addCashOut(Long merchantId, Integer amount) throws MallinkException{ | |||
| WxMerchant merchant = wxMerchantMapper.selectById(merchantId); | |||
| WxMall mall = wxMallMapper.getByTenantId(merchant.getTenantId()); | |||
| if (null != mall && mall.getCashOutSupport().intValue() == EnumCashOut.YES.getCode().intValue()) { | |||
| 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(amount); | |||
| wxMerchantMapper.increaseCash(merchant); | |||
| redisLock.unlock("merchantLockCashSet_"+merchant.getId(), timeStr); | |||
| }catch(Exception e) { | |||
| redisLock.unlock("merchantLockCashSet_"+merchant.getId(), timeStr); | |||
| logger.error("addCashOut error."+merchantId,e); | |||
| throw new MallinkException(ErrorCode.SYS_SERVER_ERROR.getCode(),"addCashOut error."+e.getMessage()); | |||
| }finally { | |||
| redisLock.unlock("merchantLockCashSet_"+merchant.getId(), timeStr); | |||
| } | |||
| } | |||
| } | |||
| } | |||
| } | |||
| } | |||
| @@ -142,6 +142,9 @@ public class WxCouponOrderServiceImpl implements WxCouponOrderService { | |||
| @Autowired | |||
| PayServiceFactory payServiceFactory; | |||
| @Autowired | |||
| WxCashOutService cashOutService; | |||
| @Autowired | |||
| @Qualifier("couponDetailRedisTemplate") | |||
| @@ -605,29 +608,7 @@ public class WxCouponOrderServiceImpl implements WxCouponOrderService { | |||
| //是否开通了商户提现,开通了商户提现往商户账户里面加金额 | |||
| 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); | |||
| } | |||
| } | |||
| } | |||
| } | |||
| cashOutService.addCashOut(merchantId, couponOrder.getCouponPrice()); | |||
| return merchantSubsidy; | |||
| } | |||
| @@ -100,6 +100,9 @@ public class WxPayOrderServiceImpl implements WxPayOrderService { | |||
| @Autowired | |||
| PayServiceFactory payServiceFactory; | |||
| @Autowired | |||
| WxCashOutService cashOutService; | |||
| JSONObject errorMapQuery = JSON.parseObject("{" + | |||
| "\"ORDERNOTEXIST\":{\"detail\":\"此交易订单号不存在\",\"reason\":\"查询系统中不存在此交易订单号\",\"resolution\":\"该API只能查提交支付交易返回成功的订单,请商户检查需要查询的订单号是否正确\"},\n" + | |||
| @@ -1089,10 +1092,8 @@ public class WxPayOrderServiceImpl implements WxPayOrderService { | |||
| merchantSubsidy.setSource(EnumMerchantSubsidySource.CASHIER.getCode()); | |||
| wxMerchantSubsidyMapper.insert(merchantSubsidy); | |||
| if (freshMerchantCash) { | |||
| WxMerchant merchant = wxMerchantMapper.selectById(wxMerchantBUser.getMerchantId()); | |||
| merchant.setCashOutNumber(merchantSubsidy.getRealPayment()); | |||
| wxMerchantMapper.increaseCash(merchant); | |||
| if (freshMerchantCash && (null!=record.getShare() && EnumPayShare.NO.getCode().intValue()==record.getShare().intValue())) { | |||
| cashOutService.addCashOut(wxMerchantBUser.getMerchantId(), merchantSubsidy.getRealPayment()); | |||
| } | |||
| } | |||