diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxCardSpendServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxCardSpendServiceImpl.java index 582667727..7e0638615 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxCardSpendServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxCardSpendServiceImpl.java @@ -54,7 +54,10 @@ public class WxCardSpendServiceImpl implements WxCardSpendService { WxCouponMerchantMapper wxCouponMerchantMapper; @Autowired - WxPayAccountMapper payAccountMapper; + WxAppinfoService wxAppinfoService; + + @Autowired + WxPayAccountService wxPayAccountService; @Autowired WxOrderMapper wxOrderMapper; @@ -117,14 +120,13 @@ public class WxCardSpendServiceImpl implements WxCardSpendService { } // 3. get pay account - WxPayAccount payAccount = null; - WxPayAccount payAccountQ = new WxPayAccount(); - payAccountQ.updateTenantInfo(record); - try { - payAccount = payAccountMapper.selectOne(new QueryWrapper(payAccountQ)); - } catch (Exception e) { - logger.error("获取payAccount error: " + record.getTenantId()); - return new ResultData(ErrorCode.DB_FAIL.getCode(), "获取payAccount失败"); + WxAppinfo cAppInfo = wxAppinfoService.getCAppInfoFromRedis(cardInfo.getTenantId(), EnumAppPlat.WX); + if(cAppInfo == null){ + return new ResultData(ErrorCode.APP_ID_NOT_FOUND); + } + WxPayAccount payAccount = wxPayAccountService.getByIdFromRedis(cAppInfo.getPayId()); + if(payAccount == null){ + return new ResultData(ErrorCode.API_KEY_NOT_FOUND); } // 4. 扣减计算 @@ -651,14 +653,13 @@ public class WxCardSpendServiceImpl implements WxCardSpendService { } // 3. get pay account - WxPayAccount payAccount = null; - WxPayAccount payAccountQ = new WxPayAccount(); - payAccountQ.updateTenantInfo(record); - try { - payAccount = payAccountMapper.selectOne(new QueryWrapper(payAccountQ)); - } catch (Exception e) { - logger.error("获取payAccount error: " + record.getTenantId()); - throw new MallinkException(ErrorCode.SYS_MCH_NOT_FOUND); + WxAppinfo cAppInfo = wxAppinfoService.getCAppInfoFromRedis(cardInfo.getTenantId(), EnumAppPlat.WX); + if(cAppInfo == null){ + throw new MallinkException(ErrorCode.APP_ID_NOT_FOUND); + } + WxPayAccount payAccount = wxPayAccountService.getByIdFromRedis(cAppInfo.getPayId()); + if(payAccount == null){ + throw new MallinkException(ErrorCode.API_KEY_NOT_FOUND); } // 查询是否有已有的 @@ -748,14 +749,13 @@ public class WxCardSpendServiceImpl implements WxCardSpendService { } // 3. get pay account - WxPayAccount payAccount = null; - WxPayAccount payAccountQ = new WxPayAccount(); - payAccountQ.updateTenantInfo(record); - try { - payAccount = payAccountMapper.selectOne(new QueryWrapper(payAccountQ)); - } catch (Exception e) { - logger.error("获取payAccount error: " + record.getTenantId()); - throw new MallinkException(ErrorCode.SYS_MCH_NOT_FOUND); + WxAppinfo cAppInfo = wxAppinfoService.getCAppInfoFromRedis(cardInfo.getTenantId(), EnumAppPlat.WX); + if(cAppInfo == null){ + throw new MallinkException(ErrorCode.APP_ID_NOT_FOUND); + } + WxPayAccount payAccount = wxPayAccountService.getByIdFromRedis(cAppInfo.getPayId()); + if(payAccount == null){ + throw new MallinkException(ErrorCode.API_KEY_NOT_FOUND); } // 4. 增加计算 @@ -838,14 +838,13 @@ public class WxCardSpendServiceImpl implements WxCardSpendService { } // 3. get pay account - WxPayAccount payAccount = null; - WxPayAccount payAccountQ = new WxPayAccount(); - payAccountQ.updateTenantInfo(record); - try { - payAccount = payAccountMapper.selectOne(new QueryWrapper(payAccountQ)); - } catch (Exception e) { - logger.error("获取payAccount error: " + record.getTenantId()); - throw new MallinkException(ErrorCode.DB_FAIL.getCode(), "获取payAccount失败"); + WxAppinfo cAppInfo = wxAppinfoService.getCAppInfoFromRedis(cardInfo.getTenantId(), EnumAppPlat.WX); + if(cAppInfo == null){ + throw new MallinkException(ErrorCode.APP_ID_NOT_FOUND); + } + WxPayAccount payAccount = wxPayAccountService.getByIdFromRedis(cAppInfo.getPayId()); + if(payAccount == null){ + throw new MallinkException(ErrorCode.API_KEY_NOT_FOUND); } // 3. 补贴 diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxOrderServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxOrderServiceImpl.java index be7fb56bf..500b9a8c3 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxOrderServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxOrderServiceImpl.java @@ -1459,8 +1459,14 @@ public class WxOrderServiceImpl implements WxOrderService { if (null != cardInfoList && cardInfoList.size() > 0) { //do nothing }else { - WxAppinfo cAppInfo = wxAppinfoService.getCAppInfoFromRedis(order.getTenantId(), payWay.getPlat()); - WxPayAccount payAccount = wxPayAccountService.getByIdFromRedis(cAppInfo.getId()); + WxAppinfo cAppInfo = wxAppinfoService.getCAppInfoFromRedis(cardInfo.getTenantId(), EnumAppPlat.WX); + if(cAppInfo == null){ + throw new MallinkException(ErrorCode.APP_ID_NOT_FOUND); + } + WxPayAccount payAccount = wxPayAccountService.getByIdFromRedis(cAppInfo.getPayId()); + if(payAccount == null){ + throw new MallinkException(ErrorCode.API_KEY_NOT_FOUND); + } // 有价卡 cardInfo.setTransactionId(payOrder.getTransactionId()); WxComposeChildOrderShare share = payOrder.getChildOrderShare(order.getId()); diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxPayAccountServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxPayAccountServiceImpl.java index d2190622d..6a5ad03e9 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxPayAccountServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxPayAccountServiceImpl.java @@ -3,12 +3,14 @@ package com.iformall.service.impl; import com.github.binarywang.wxpay.service.WxPayService; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; +import com.iformall.common.ErrorCode; import com.iformall.domain.po.WxAppinfo; import com.iformall.domain.po.WxPayAccount; import com.iformall.domain.po.WxProjectConfig; import com.iformall.domain.po.base.TenantEntity; import com.iformall.enums.EnumAppPlat; import com.iformall.enums.EnumPayWay; +import com.iformall.exception.MallinkException; import com.iformall.mapper.WxPayAccountMapper; import com.iformall.service.WxAppinfoService; import com.iformall.service.WxPayAccountService; @@ -104,12 +106,14 @@ public class WxPayAccountServiceImpl implements WxPayAccountService { // TenantEntity tenantEntity = new TenantEntity(); // tenantEntity.setTenantId(tenantId); WxAppinfo cAppInfo = wxAppinfoService.getCAppInfoFromRedis(tenantId, EnumAppPlat.WX); + if(cAppInfo == null){ + throw new MallinkException(ErrorCode.APP_ID_NOT_FOUND); + } WxPayAccount payAccount = this.getByIdFromRedis(cAppInfo.getPayId()); - if(cAppInfo != null && payAccount != null){ - return maUtil.getWxPayService(cAppInfo,payAccount); - }else{ - return null; + if(payAccount == null){ + throw new MallinkException(ErrorCode.API_KEY_NOT_FOUND); } + return maUtil.getWxPayService(cAppInfo,payAccount); } diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxPayOrderServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxPayOrderServiceImpl.java index 5dc567d2f..535a7ad11 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxPayOrderServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxPayOrderServiceImpl.java @@ -478,7 +478,14 @@ public class WxPayOrderServiceImpl implements WxPayOrderService { public ResultData createMicroPayOrder(WxMerchantBUser user, WxPayOrder record, EnumPayWay payWay,PayExtraParam params) { final IdWorker idworker = IdWorker.get(); - WxAppinfo appInfo = wxAppinfoService.getCAppInfoFromRedis(user.getTenantId(),payWay.getPlat()); + WxAppinfo cAppInfo = wxAppinfoService.getCAppInfoFromRedis(record.getTenantId(), payWay.getPlat()); + if(cAppInfo == null){ + throw new MallinkException(ErrorCode.APP_ID_NOT_FOUND); + } + WxPayAccount payAccount = wxPayAccountService.getByIdFromRedis(cAppInfo.getPayId()); + if(payAccount == null){ + throw new MallinkException(ErrorCode.API_KEY_NOT_FOUND); + } if (null == params) { params = new PayExtraParam(); } @@ -488,7 +495,7 @@ public class WxPayOrderServiceImpl implements WxPayOrderService { try { // 1. check 订单 OrderAdapterService orderAdapterService = orderFactory.getOrderAdapterService(EnumComposeOrder.SINGLE.getCode()); - WxComposeOrder composeOrder = orderAdapterService.getComposeOrder(record.getOrderId(), appInfo.getTenantId()); + WxComposeOrder composeOrder = orderAdapterService.getComposeOrder(record.getOrderId(), cAppInfo.getTenantId()); WxOrder singleOrder = composeOrder.getSingleOrder(); if (composeOrder == null) { logger.error("pay order, order not allow, repaymentReq: " + record.toString() + ", payWay: " + payWay.toString()); @@ -506,7 +513,6 @@ public class WxPayOrderServiceImpl implements WxPayOrderService { if (order.getPaymentType() != EnumPayType.PAY_PAYMENT.getCode()) { return new ResultData(ErrorCode.PAY_ORDER_IS_NOT_PAYMENT); } - WxPayAccount payAccount = wxPayAccountService.getByIdFromRedis(appInfo.getPayId()); PayShareAdapterService payShareServie = payServiceFactory.getPayShareAdapterService(payWay.getCode(),payAccount.getPayVersion()); EnumPayShare paySHareEnum = EnumPayShare.getEnum(payAccount.getShare()); if (paySHareEnum != null) { @@ -566,9 +572,9 @@ public class WxPayOrderServiceImpl implements WxPayOrderService { logger.debug("wxPayRecord md5 before:"+record.toString()); String beforemd5 = HashUtil.md5(record.toString()); - List orderList = orderAdapterService.getChildOrders(composeOrder, appInfo.getTenantId()); + List orderList = orderAdapterService.getChildOrders(composeOrder, cAppInfo.getTenantId()); PayAdapterResult payResult = payServiceFactory.getPayAdapterService(payWay.getCode(),payAccount.getPayVersion()).pay(payAccount, record,composeOrder,orderList, - "付款码支付",isShare,appInfo, currentDate, params); + "付款码支付",isShare,cAppInfo, currentDate, params); String aftermd5 = HashUtil.md5(record.toString()); if (beforemd5.equals(aftermd5)) { logger.error("支付方式["+payWay.getCode()+"]支付接口【pay】过程中 WxPayOrder 未做更新.record:"+record.toString()); @@ -578,7 +584,7 @@ public class WxPayOrderServiceImpl implements WxPayOrderService { //支付失败,更新record,支付成功,则调用 if (payResult.isSuccess()) { try { - handleMicroOrderPaySuccess(payResult.getData(), payResult.getTransactionId(),payWay,payAccount,record,user, appInfo, params); + handleMicroOrderPaySuccess(payResult.getData(), payResult.getTransactionId(),payWay,payAccount,record,user, cAppInfo, params); }catch(Exception e) { logger.error("do handleMicroOrderPaySuccess() error.",e); try { @@ -630,10 +636,16 @@ public class WxPayOrderServiceImpl implements WxPayOrderService { return new ResultData(ErrorCode.PAY_ORDER_ERROR.getCode(), "payOrder not found"); } - WxAppinfo appInfo = wxAppinfoService.getCAppInfoFromRedis(record.getTenantId(),payWay.getPlat()); - WxPayAccount payAccount = wxPayAccountService.getByIdFromRedis(appInfo.getPayId()); + WxAppinfo cAppInfo = wxAppinfoService.getCAppInfoFromRedis(record.getTenantId(), payWay.getPlat()); + if(cAppInfo == null){ + throw new MallinkException(ErrorCode.APP_ID_NOT_FOUND); + } + WxPayAccount payAccount = wxPayAccountService.getByIdFromRedis(cAppInfo.getPayId()); + if(payAccount == null){ + throw new MallinkException(ErrorCode.API_KEY_NOT_FOUND); + } PayAdapterService payService = payServiceFactory.getPayAdapterService(payWay.getCode(),payAccount.getPayVersion()); - PayQueryAdapterResult apiResult = payService.queryPayStatus(record, appInfo, payAccount); + PayQueryAdapterResult apiResult = payService.queryPayStatus(record, cAppInfo, payAccount); int status = payServiceFactory.getPayAdapterService(payWay.getCode(),payAccount.getPayVersion()).queryPayStatus(apiResult, record.getPayOrderNo()); boolean isSuccess = true; String msg = ""; @@ -655,7 +667,7 @@ public class WxPayOrderServiceImpl implements WxPayOrderService { handleOrderPaySuccess(record, apiResult.getTransactionId()); //C端被动支付 }else if (payService instanceof CPassivePayService) { - handleMicroOrderPaySuccess(apiResult.getData(),apiResult.getTransactionId(),payWay,payAccount, record,user,appInfo,null); + handleMicroOrderPaySuccess(apiResult.getData(),apiResult.getTransactionId(),payWay,payAccount, record,user,cAppInfo,null); } return new ResultData(Result.SUCCESS, "success",apiResult.getData()); }else if (status == EnumPayStatus.PAY_STATUS_ORDER_NOT_EXISTS.getCode().intValue()) { @@ -736,11 +748,17 @@ public class WxPayOrderServiceImpl implements WxPayOrderService { */ @Override public ResultData payOrderReverse(WxPayOrder record) { - - WxAppinfo appInfo = wxAppinfoService.getCAppInfoFromRedis(record.getTenantId(),EnumPayWay.getEnum(record.getPayVendor()).getPlat()); - WxPayAccount payAccount = wxPayAccountService.getByIdFromRedis(appInfo.getPayId()); + EnumAppPlat plat = EnumPayWay.getEnum(record.getPayVendor()).getPlat(); + WxAppinfo cAppInfo = wxAppinfoService.getCAppInfoFromRedis(record.getTenantId(),plat); + if(cAppInfo == null){ + throw new MallinkException(ErrorCode.APP_ID_NOT_FOUND); + } + WxPayAccount payAccount = wxPayAccountService.getByIdFromRedis(cAppInfo.getPayId()); + if(payAccount == null){ + throw new MallinkException(ErrorCode.API_KEY_NOT_FOUND); + } try { - PayAdapterResult result = payServiceFactory.getPayAdapterService(record.getPayVendor(),record.getPayVersion()).payOrderReverse(appInfo, record, payAccount); + PayAdapterResult result = payServiceFactory.getPayAdapterService(record.getPayVendor(),record.getPayVersion()).payOrderReverse(cAppInfo, record, payAccount); if (result.isSuccess()) { record.setPayOrderStatus(EnumPayStatus.PAY_STATUS_REVERSE.getCode()); record.setUpdateTime(new Date()); @@ -1010,8 +1028,14 @@ public class WxPayOrderServiceImpl implements WxPayOrderService { @Override public PayQueryAdapterResult ttorderQuery(TenantEntity tenantInfo, Long id) { - WxAppinfo appInfo = wxAppinfoService.getCAppInfoFromRedis(tenantInfo.getTenantId(),EnumAppPlat.TOUTIAO); + WxAppinfo appInfo = wxAppinfoService.getCAppInfoFromRedis(tenantInfo.getTenantId(), EnumAppPlat.TOUTIAO); + if(appInfo == null){ + throw new MallinkException(ErrorCode.APP_ID_NOT_FOUND); + } WxPayAccount payAccount = wxPayAccountService.getByIdFromRedis(appInfo.getPayId()); + if(payAccount == null){ + throw new MallinkException(ErrorCode.API_KEY_NOT_FOUND); + } WxPayOrder payOrder = new WxPayOrder(); payOrder.setPayOrderNo(id.toString()); try { @@ -1301,12 +1325,19 @@ public class WxPayOrderServiceImpl implements WxPayOrderService { // 有价券 if (EnumPayStatus.PAY_STATUS_FAIL.getCode() == status) { // 1. get appinfo - WxAppinfo appInfo = wxAppinfoService.getCAppInfoFromRedis(record.getTenantId(),EnumPayWay.getEnum(record.getPayVendor()).getPlat()); + EnumAppPlat plat = EnumPayWay.getEnum(record.getPayVendor()).getPlat(); + WxAppinfo cAppInfo = wxAppinfoService.getCAppInfoFromRedis(record.getTenantId(),plat); + if(cAppInfo == null){ + throw new MallinkException(ErrorCode.APP_ID_NOT_FOUND); + } + WxPayAccount payAccount = wxPayAccountService.getByIdFromRedis(cAppInfo.getPayId()); + if(payAccount == null){ + throw new MallinkException(ErrorCode.API_KEY_NOT_FOUND); + } // 前端支付取消, // 回调未返回,主动检查支付订单状态 try { - WxPayAccount payAccount = wxPayAccountService.getByIdFromRedis(appInfo.getPayId()); - int payStatus = payServiceFactory.getPayAdapterService(record.getPayVendor(),payAccount.getPayVersion()).queryPayStatusCode(record, appInfo, payAccount); + int payStatus = payServiceFactory.getPayAdapterService(record.getPayVendor(),payAccount.getPayVersion()).queryPayStatusCode(record, cAppInfo, payAccount); if (payStatus!=EnumPayStatus.PAY_STATUS_SUCCESS.getCode().intValue() && payStatus!=EnumPayStatus.PAY_STATUS_WAIT.getCode().intValue()) { // 支付订单未成功,返回异常 record.setPayOrderStatus(EnumPayStatus.PAY_STATUS_FAIL.getCode());