From 14c14b03585e6f59f7ee5e9bcdf1c764745e2d70 Mon Sep 17 00:00:00 2001 From: hupeng Date: Fri, 7 Sep 2018 11:28:43 +0800 Subject: [PATCH] =?UTF-8?q?[=E6=94=AF=E4=BB=98][=E4=BF=AE=E6=94=B9]:?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=B8=80=E4=BA=9B=E5=88=86=E8=B4=A6=E7=BB=93?= =?UTF-8?q?=E6=9E=9C=E7=9A=84=E5=85=A5=E5=BA=93=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../enums/EnumProfitSharingResultStatus.java | 39 +++++++++++++++++++ .../impl/WxProfitSharingOrderServiceImpl.java | 35 +++++++++-------- 2 files changed, 58 insertions(+), 16 deletions(-) create mode 100644 mallinkService/src/main/java/com/simple/enums/EnumProfitSharingResultStatus.java diff --git a/mallinkService/src/main/java/com/simple/enums/EnumProfitSharingResultStatus.java b/mallinkService/src/main/java/com/simple/enums/EnumProfitSharingResultStatus.java new file mode 100644 index 000000000..73c1059fc --- /dev/null +++ b/mallinkService/src/main/java/com/simple/enums/EnumProfitSharingResultStatus.java @@ -0,0 +1,39 @@ +package com.simple.enums; + +/** + * Created by Stormeye on 2018/08/09. + */ +public enum EnumProfitSharingResultStatus { + PROFIT_SHARING_UNKNOWN(-1, "未知"), + PROFIT_SHARING_RESULT_PENDING(1, "待分账"), + PROFIT_SHARING_RESULT_SUCCESS(2, "分账成功"), + PROFIT_SHARING_RESULT_ADJUST(3, "分账失败待调账"), + PROFIT_SHARING_RESULT_RETURNED(4, "已转回分账方"), + PROFIT_SHARING_RESULT_CLOSED(5, "已关闭"), + ; + + public static EnumProfitSharingResultStatus getEnum(Integer code) { + for (EnumProfitSharingResultStatus value : values()) { + if (value.getCode().equals(code)) { + return value; + } + } + return null; + } + + private Integer code; + private String message; + + EnumProfitSharingResultStatus(Integer code, String message) { + this.code = code; + this.message = message; + } + + public Integer getCode() { + return code; + } + + public String getMessage() { + return message; + } +} diff --git a/mallinkService/src/main/java/com/simple/service/impl/WxProfitSharingOrderServiceImpl.java b/mallinkService/src/main/java/com/simple/service/impl/WxProfitSharingOrderServiceImpl.java index 23d5411d8..18bb72a41 100644 --- a/mallinkService/src/main/java/com/simple/service/impl/WxProfitSharingOrderServiceImpl.java +++ b/mallinkService/src/main/java/com/simple/service/impl/WxProfitSharingOrderServiceImpl.java @@ -10,10 +10,7 @@ import com.github.pagehelper.PageInfo; import com.simple.common.ErrorCode; import com.simple.common.ResultData; import com.simple.domain.po.*; -import com.simple.enums.EnumPayDomain; -import com.simple.enums.EnumProfitSharingReceiverType; -import com.simple.enums.EnumProfitSharingStatus; -import com.simple.enums.EnumProfitSharingType; +import com.simple.enums.*; import com.simple.exception.MallinkException; import com.simple.mapper.*; import com.simple.pay.WxPayment; @@ -165,11 +162,11 @@ public class WxProfitSharingOrderServiceImpl implements WxProfitSharingOrderServ record.setOrderId(wxPayOrder.getId()); record.setPayAmount(wxPayOrder.getPayAmount()); record.setMerchantId(wxOrder.getMerchantId()); + record.setSharingStatus(EnumProfitSharingStatus.PROFIT_SHARING_UNKNOWN.getCode()); record.setCreateTime(currentDate); record.setUpdateTime(currentDate); record.setPayTimeStart(currentDate); record.setPayTimeEnd(currentDate); - wxProfitSharingOrderMapper.insertSelective(record); } @@ -214,34 +211,41 @@ public class WxProfitSharingOrderServiceImpl implements WxProfitSharingOrderServ result.setPayAmount(total_amount); result.setCreateTime(currentDate); result.setUpdateTime(currentDate); + result.setSharingStatus(EnumProfitSharingResultStatus.PROFIT_SHARING_RESULT_PENDING.getCode()); resultList.add(result); } wxProfitSharingP.setReceivers(receivers.toJSONString()); wxProfitSharingP.setSign(WxPayment.createSignHMAC(BeanUtils.toStringMap(wxProfitSharingP), payAccount.getApiKey())); + logger.info("wxProfitSharingP :" + wxProfitSharingP.toString()); String response = WxProfitSharing.pushOrder(BeanUtils.toStringMap(wxProfitSharingP), payAccount.getCertPath(), payAccount.getMchId()); + logger.info("response: " + response); Map returnMap = WxPayment.xmlToMap(response); String return_code = returnMap.get("return_code"); + if (!"SUCCESS".equals(return_code)) { record.setSharingStatus(EnumProfitSharingStatus.PROFIT_SHARING_REQ_FAILED.getCode()); + record.setErrorMsg(returnMap.get("return_msg")); record.setUpdateTime(new Date()); wxProfitSharingOrderMapper.updateByPrimaryKey(record); - throw new MallinkException(ErrorCode.PROFIT_SHARING_REQUEST_FAILED.getCode(), returnMap.get("return_msg")); + return new ResultData(ErrorCode.PROFIT_SHARING_REQUEST_FAILED.getCode(), returnMap.get("return_msg")); } - //if (!WxPayment.verifyNotifyHMAC(returnMap,payAccount.getApiKey())){ - // throw new MallinkException(ErrorCode.PROFIT_SHARING_RETURN_INVALID.getCode(), ErrorCode.PROFIT_SHARING_RETURN_INVALID.getMessage()); - //} + if (!WxPayment.verifyNotifyHMAC(returnMap,payAccount.getApiKey())){ + record.setErrorMsg("返回值校验失败"); + return new ResultData(ErrorCode.PROFIT_SHARING_RETURN_INVALID.getCode(), ErrorCode.PROFIT_SHARING_RETURN_INVALID.getMessage()); + } String result_code = returnMap.get("result_code"); if (!"SUCCESS".equals(result_code)) { record.setSharingStatus(EnumProfitSharingStatus.PROFIT_SHARING_APPLY_FAILED.getCode()); record.setUpdateTime(new Date()); + record.setErrorMsg(returnMap.get("result_msg")); wxProfitSharingOrderMapper.updateByPrimaryKey(record); - throw new MallinkException(ErrorCode.PROFIT_SHARING_APPLY_FAILED.getCode(), returnMap.get("result_msg")); + return new ResultData(ErrorCode.PROFIT_SHARING_APPLY_FAILED.getCode(), returnMap.get("result_msg")); } record.setSharingOrderNo(returnMap.get("order_id")); @@ -268,7 +272,7 @@ public class WxProfitSharingOrderServiceImpl implements WxProfitSharingOrderServ record.setOrderId(wxPayOrder.getId()); record = wxProfitSharingOrderMapper.selectOne(record); if (record == null) - throw new MallinkException(ErrorCode.ORDER_IS_NOT_FIND.getCode(), ErrorCode.ORDER_IS_NOT_FIND.getMessage()); + return new ResultData(ErrorCode.ORDER_IS_NOT_FIND.getCode(), ErrorCode.ORDER_IS_NOT_FIND.getMessage()); //分账查询提交 WxProfitSharingQueryP wxProfitSharingQueryP = new WxProfitSharingQueryP();; @@ -285,21 +289,21 @@ public class WxProfitSharingOrderServiceImpl implements WxProfitSharingOrderServ Map returnMap = WxPayment.xmlToMap(response); String return_code = returnMap.get("return_code"); if (!"SUCCESS".equals(return_code)) { - throw new MallinkException(ErrorCode.PROFIT_SHARING_QUERY_REQUEST_FAILED.getCode(), returnMap.get("return_msg")); + return new ResultData(ErrorCode.PROFIT_SHARING_QUERY_REQUEST_FAILED.getCode(), returnMap.get("return_msg")); } if (!WxPayment.verifyNotify(returnMap,payAccount.getApiKey())){ - throw new MallinkException(ErrorCode.PROFIT_SHARING_QUERY_RETURN_INVALID.getCode(), ErrorCode.PROFIT_SHARING_RETURN_INVALID.getMessage()); + return new ResultData(ErrorCode.PROFIT_SHARING_QUERY_RETURN_INVALID.getCode(), ErrorCode.PROFIT_SHARING_RETURN_INVALID.getMessage()); } String out_order_no = returnMap.get("out_order_no"); if (!out_order_no.equals(record.getId().toString())){ - throw new MallinkException(ErrorCode.PROFIT_SHARING_QUERY_RETURN_INVALID.getCode(), ErrorCode.PROFIT_SHARING_RETURN_INVALID.getMessage()); + return new ResultData(ErrorCode.PROFIT_SHARING_QUERY_RETURN_INVALID.getCode(), ErrorCode.PROFIT_SHARING_RETURN_INVALID.getMessage()); } String result_code = returnMap.get("result_code"); if (!"SUCCESS".equals(result_code)) { - throw new MallinkException(ErrorCode.PROFIT_SHARING_QUERY_APPLY_FAILED.getCode(), returnMap.get("result_msg")); + return new ResultData(ErrorCode.PROFIT_SHARING_QUERY_APPLY_FAILED.getCode(), returnMap.get("result_msg")); } record.setSharingStatus((Integer) statusMap.get(returnMap.get("status"))); @@ -337,7 +341,6 @@ public class WxProfitSharingOrderServiceImpl implements WxProfitSharingOrderServ } } - return new ResultData(returnMap); }catch (Exception e) {