From eeaaef47e2e5a579b3b1eb5337603d71f62d83ca Mon Sep 17 00:00:00 2001 From: xiaohanzi Date: Fri, 23 Apr 2021 16:09:32 +0800 Subject: [PATCH] fix cashout --- .../iformall/schedule/CashOutSchedule.java | 52 +++++++++++++++---- .../src/main/resources/application-dev.yml | 9 ++++ .../src/main/resources/application-prod.yml | 9 ++++ .../service/impl/WxCashOutServiceImpl.java | 3 -- .../cashout/wx/WxCashOutAdapterService.java | 25 +++++---- 5 files changed, 75 insertions(+), 23 deletions(-) diff --git a/mallinkSchedule/src/main/java/com/iformall/schedule/CashOutSchedule.java b/mallinkSchedule/src/main/java/com/iformall/schedule/CashOutSchedule.java index 938a42a83..94c887606 100644 --- a/mallinkSchedule/src/main/java/com/iformall/schedule/CashOutSchedule.java +++ b/mallinkSchedule/src/main/java/com/iformall/schedule/CashOutSchedule.java @@ -1,16 +1,24 @@ package com.iformall.schedule; +import com.iformall.domain.po.WxAppinfo; import com.iformall.domain.po.WxCashOut; import com.iformall.domain.po.WxCouponChannel; import com.iformall.domain.po.WxCouponOrder; import com.iformall.domain.po.WxGame; import com.iformall.domain.po.WxMall; import com.iformall.domain.po.WxMerchant; +import com.iformall.domain.po.WxPayAccount; import com.iformall.enums.EnumCashOutStatus; import com.iformall.enums.EnumCouponChannelStatus; import com.iformall.enums.EnumCouponChannelType; import com.iformall.enums.EnumGameStatus; +import com.iformall.enums.EnumPayWay; import com.iformall.mapper.*; +import com.iformall.service.WxAppinfoService; +import com.iformall.service.WxPayAccountService; +import com.iformall.service.pay.PayServiceFactory; +import com.iformall.service.pay.service.cashout.entity.CashOutAdapterResult; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -35,6 +43,12 @@ public class CashOutSchedule { private WxMallMapper wxMallMapper; @Autowired private WxMerchantMapper wxMerchantMapper; + @Autowired + PayServiceFactory payServiceFactory; + @Autowired + WxAppinfoService wxAppinfoService; + @Autowired + WxPayAccountService wxPayAccountService; private List getMalls() { @@ -64,7 +78,7 @@ public class CashOutSchedule { List cashoutlist = wxCashOutMapper.findList(cashOut); if (null != cashoutlist && cashoutlist.size() > 0 ) { for (WxCashOut casho : cashoutlist) { - cashOutBack(casho); + cashOutBack(casho,EnumPayWay.PAY_WAY_WECHAT); } } @@ -76,16 +90,32 @@ public class CashOutSchedule { } @Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) - public void cashOutBack(WxCashOut cashout) { - //状态更新 - cashout.setStatus(EnumCashOutStatus.BACK.getCode()); - cashout.setUpdateDate(new Date()); - wxCashOutMapper.updateStatus(cashout); - - //余额回滚 - WxMerchant merchant = wxMerchantMapper.selectById(cashout.getMerchantId()); - merchant.setCashOutNumber(cashout.getTotalFee()); - wxMerchantMapper.increaseCash(merchant); + public void cashOutBack(WxCashOut cashout,EnumPayWay payWay) { + //查询零钱是否已经到账 + WxAppinfo appInfo = wxAppinfoService.getCAppInfo(cashout, payWay); + if (null == appInfo) { + return; + } + WxPayAccount payAccount = wxPayAccountService.getByTenantId(cashout.getTenantId()); + if (null == payAccount) { + return; + } + CashOutAdapterResult result = payServiceFactory.getCashOutAdapterService(payWay.getCode()).queryCashOut(appInfo, payAccount, cashout); + cashout.setUpdateDate(new Date()); + if (result.isSuccess()) { + cashout.setStatus(EnumCashOutStatus.SUCCESS.getCode()); + wxCashOutMapper.updateById(cashout); + }else { + //状态更新 + cashout.setStatus(EnumCashOutStatus.BACK.getCode()); + cashout.setUpdateDate(new Date()); + wxCashOutMapper.updateStatus(cashout); + + //余额回滚 + WxMerchant merchant = wxMerchantMapper.selectById(cashout.getMerchantId()); + merchant.setCashOutNumber(cashout.getTotalFee()); + wxMerchantMapper.increaseCash(merchant); + } } } \ No newline at end of file diff --git a/mallinkSchedule/src/main/resources/application-dev.yml b/mallinkSchedule/src/main/resources/application-dev.yml index 0e10fac9e..8b2db8bca 100644 --- a/mallinkSchedule/src/main/resources/application-dev.yml +++ b/mallinkSchedule/src/main/resources/application-dev.yml @@ -150,6 +150,15 @@ wechat: max-wait: -1 min-idle: 10 +alipay: + open: + appId:"2021002137663024" + appPrivateKey:"MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCUfymV5J73QQMG52PVIGUbowkloYCO4B7TQoKbrTZf2YeYsg/To/o4PiXPMNwEUfEUU8NYQ6WwNhCd2fa1ei8WFXJUf3bfgswtBk1aOmHLeY9yoXFxIKMTQ9RcobnmBzKQZlaAPMTSr7t1QtKZKPuc2gEHGRFYKO/ZuL8gIpnsVidVtmi52yd7hzao/pI3ThLA0lreg4L3rYP5ESQZRytxIPgUQ4KI11pZxFgbe+uy28AGDYIQscSIb+SWOHPYKLvOEqqepIZ8M18w/U0lZzpzepzi/V/llekvXJ6UEf1lzl7x/4UIA3WPN1B40+NzbD/OxEGTuM0UctOG6ZTd4Te9AgMBAAECggEAPYksnHbvARspu/SrRCh2fatkIPn6Ijrxyy3mnch7neCw9i/jqxpqmF/4nxFqO0gRlRDZBHyT7p+Y5zDpsW5+kLI2fJmNkzXKkmXoLBnBaOZo8WHBdtXFfjg/iltig9Y7t+cQtXd5QK2eCwuz5dA75FXa0ywqKdRdAGY0nYZ5LpwrHVU8RXheUDCJyhKNj2+W6lIaSKDxLZU3laO1oBrv1agcy7Crd5E2ndb8O3Enga+z7wSz2h7A1BasC/Yl/Ro0Y21wLCH3s/R6qA0Paq12+WEF+xdodM7SrP43CCTVFGbC1TfEOdanJfixop8QuYsIp7pHrL925+vP4eY9RfckgQKBgQDQqLdpDzzU7Ot/L9Vc/r8d4iwXXbX8+HwVFV4oBuausgFyv8eJJpfrI+IlEoB1ubJcPpJBFqfmeYTW6/v6ioFljJAlWfFvesUVt/HszBMIOsU0Bzt7ex6WlwKOagb0q0ZPA4T0OY0K0lg0loaaaR8ZTr4ivDymaGBtTBYhslpc7QKBgQC2MBznGEc5r2dhyENvdPOR20PnXQcevGnPdqSus8m0VmDcHE72RVcckcZtwczsb3NaLSqmjAcWTn51/VFmlvhB3F34FcFTPZGq6sj7fWK8HuFq7l7mu5OzYuVr73zy9ggsUuaw10IqvvwIVxszNAF0hiRnSGH3z27CoRmz3s+8EQKBgQCK3o7atBJ3X4rIJiypbL4DhIB1uJ+jUjk6yvLUTut+fufp1+tTw0S+cS5UIAEw2Lr1G4u5F/v8rwmTBJG6SC4gSLGyui6uVBYRA1BWmedcxchzfRDAeMt9y9kesUAZ3Fe5xIzbAeZ1ulKMBVZmM+pHrJlsgr0Wv0bV1xqvqITtbQKBgBIsIGXopQoa9dvqBtfyOW1eCprkS5aEQqWf9vM6Ga90QjsSU8n6xqKh48IE57TZtQ7UnIF6TCasc66/MsRh4KdpHLJnMR5lcMc0nhF/wz5ychehaTPol+X3wlyOyc7OPah2KG6ROhdbb3ZBggQMduyxiKYIsUTvmuOtAAxR+DSRAoGADtuDzGQDOJYWiO2uuP6FpA5IJaiwlSfu3xncJVfhO8SVr6VBJFg88igbIB3w6nk/sv7j9VTXqXre9HMvp1flxaaLsdxM4HcTSALS9q6t/ajaveqte6S5kAtWx0WW8C6PtgWXHbxcD7LXARSsKLoEl2JXXyUVS/m2l/RzHBQ8GJI=" + appPublicKeyCertPath:"/opt/iformall/service/alipay/appCertPublicKey_2021002137663024.crt" + alipayCertPath:"/opt/iformall/service/alipay/alipayCertPublicKey_RSA2.crt" + alipayRootCertPath:"/opt/iformall/service/alipay/alipayRootCert.crt" + callback:"https://callbacktest.malls.iformall.com/api/alipay/notify/callback" + jasypt: encryptor: password: oRqdnDbK5pj3eMmB diff --git a/mallinkSchedule/src/main/resources/application-prod.yml b/mallinkSchedule/src/main/resources/application-prod.yml index 86488cb6a..e14b980cf 100644 --- a/mallinkSchedule/src/main/resources/application-prod.yml +++ b/mallinkSchedule/src/main/resources/application-prod.yml @@ -109,6 +109,15 @@ wechat: max-wait: -1 min-idle: 10 +alipay: + open: + appId:"2021002137663024" + appPrivateKey:"MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQ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uJ+jUjk6yvLUTut+fufp1+tTw0S+cS5UIAEw2Lr1G4u5F/v8rwmTBJG6SC4gSLGyui6uVBYRA1BWmedcxchzfRDAeMt9y9kesUAZ3Fe5xIzbAeZ1ulKMBVZmM+pHrJlsgr0Wv0bV1xqvqITtbQKBgBIsIGXopQoa9dvqBtfyOW1eCprkS5aEQqWf9vM6Ga90QjsSU8n6xqKh48IE57TZtQ7UnIF6TCasc66/MsRh4KdpHLJnMR5lcMc0nhF/wz5ychehaTPol+X3wlyOyc7OPah2KG6ROhdbb3ZBggQMduyxiKYIsUTvmuOtAAxR+DSRAoGADtuDzGQDOJYWiO2uuP6FpA5IJaiwlSfu3xncJVfhO8SVr6VBJFg88igbIB3w6nk/sv7j9VTXqXre9HMvp1flxaaLsdxM4HcTSALS9q6t/ajaveqte6S5kAtWx0WW8C6PtgWXHbxcD7LXARSsKLoEl2JXXyUVS/m2l/RzHBQ8GJI=" + appPublicKeyCertPath:"/opt/iformall/service/alipay/appCertPublicKey_2021002137663024.crt" + alipayCertPath:"/opt/iformall/service/alipay/alipayCertPublicKey_RSA2.crt" + alipayRootCertPath:"/opt/iformall/service/alipay/alipayRootCert.crt" + callback:"https://callbacktest.malls.iformall.com/api/alipay/notify/callback" + fm: exception: true exception_emails: houtaikaifa@iformall.com diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxCashOutServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxCashOutServiceImpl.java index 8480960e6..8053ac1fb 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxCashOutServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxCashOutServiceImpl.java @@ -156,9 +156,6 @@ public class WxCashOutServiceImpl implements WxCashOutService { cashout.updateTenantInfo(buser); wxCashOutMapper.insert(cashout); - WxMerchant m = null; - System.out.println(m.getAccountId()); - //TODO有没有审批 boolean hasAudit = hasWorkFlow(buser); if (hasAudit) { diff --git a/mallinkService/src/main/java/com/iformall/service/pay/service/cashout/wx/WxCashOutAdapterService.java b/mallinkService/src/main/java/com/iformall/service/pay/service/cashout/wx/WxCashOutAdapterService.java index f07651b7b..5e97ebdaa 100644 --- a/mallinkService/src/main/java/com/iformall/service/pay/service/cashout/wx/WxCashOutAdapterService.java +++ b/mallinkService/src/main/java/com/iformall/service/pay/service/cashout/wx/WxCashOutAdapterService.java @@ -208,7 +208,7 @@ public class WxCashOutAdapterService implements CashOutAdapterService{ response = WxPay.transfers(signMap, payAccount.getCertPath(), payAccount.getMchId()); } catch (Exception e) { log.error("零钱支付异常: " + e.getMessage(),e); - return new CashOutAdapterResult(false, EnumCashOutStatus.FAIL.getCode(), "零钱支付异常", null); + return new CashOutAdapterResult(false, EnumCashOutStatus.FAIL.getCode(), "微信零钱支付接口调用异常", null); } log.info("微信零钱支付:" + wxCashOutP.toString() + ", response: " + response.toString()); return getReusltFromp(response,cashOut); @@ -272,11 +272,11 @@ public class WxCashOutAdapterService implements CashOutAdapterService{ try { response = WxPay.getTransferInfo(signMap, payAccount.getCertPath(), payAccount.getMchId()); } catch (Exception e) { - log.error("零钱支付异常: " + e.getMessage(),e); - throw new MallinkException(ErrorCode.REFUND_ORDER_ERROR.getCode(), "零钱支付异常"); + log.error("零钱支付查询异常: " + e.getMessage(),e); + throw new MallinkException(ErrorCode.REFUND_ORDER_ERROR.getCode(), "微信零钱支付查询接口异常"); } - log.info("微信零钱支付:" + wxCashOutP.toString() + ", response: " + response.toString()); - return getReusltFromQueryp(response); + log.info("微信零钱支付查询:" + wxCashOutP.toString() + ", response: " + response.toString()); + return getReusltFromQueryp(response,cashOut); } private WxCashOutQueryP generateQueryWxCashOutP(WxPayAccount payAccount,WxAppinfo appInfo,WxCashOut cashOut) { @@ -289,16 +289,23 @@ public class WxCashOutAdapterService implements CashOutAdapterService{ return wxCashOutQueryP; } - private CashOutAdapterResult getReusltFromQueryp(String response) throws MallinkException{ + private CashOutAdapterResult getReusltFromQueryp(String response,WxCashOut cashOut) throws MallinkException{ Map returnMap = WxPayment.xmlToMap(response); String result_no = returnMap.get("result_code"); if ("SUCCESS".equals(result_no)) { String realStatus = returnMap.get("status"); if ("SUCCESS".equals(realStatus) || "PROCESSING".equals(realStatus)) { + String detailId = returnMap.get("detail_id"); + cashOut.setWxPayNo(detailId); + String wxPayTime = returnMap.get("transfer_time"); + cashOut.setWxPayTime(wxPayTime); return new CashOutAdapterResult(true,EnumCashOutStatus.SUCCESS.getCode(),"微信零钱支付申请成功",returnMap); - }else { + }else if("FAILED".equals(realStatus)) { String msg = returnMap.get("reason"); - return new CashOutAdapterResult(false,EnumCashOutStatus.SUCCESS.getCode(),msg,returnMap); + return new CashOutAdapterResult(false,EnumCashOutStatus.FAIL.getCode(),msg,returnMap); + }else { + log.error("微信零钱支付查询失败,微信返回未知状态: " + response); + throw new MallinkException(ErrorCode.SYS_PARAMETER_CAST_ERROR.getCode(), "微信零钱支付查询失败, 微信返回未知状态:"+realStatus); } } else { log.error("微信零钱支付查询失败: " + response); @@ -309,7 +316,7 @@ public class WxCashOutAdapterService implements CashOutAdapterService{ } else { errMsg = returnMap.get("err_code_des"); } - return new CashOutAdapterResult(false, EnumCashOutStatus.FAIL.getCode(), errMsg, returnMap); + throw new MallinkException(ErrorCode.SYS_PARAMETER_CAST_ERROR.getCode(), "微信零钱支付查询失败:"+errMsg); } }