Просмотр исходного кода

[支付][修改]:修复一些分账结果的入库问题

release_toaliyun_real
hupeng 7 лет назад
Родитель
Сommit
14c14b0358
2 измененных файлов: 58 добавлений и 16 удалений
  1. +39
    -0
      mallinkService/src/main/java/com/simple/enums/EnumProfitSharingResultStatus.java
  2. +19
    -16
      mallinkService/src/main/java/com/simple/service/impl/WxProfitSharingOrderServiceImpl.java

+ 39
- 0
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;
}
}

+ 19
- 16
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<String, String> 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<String, String> 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) {


Загрузка…
Отмена
Сохранить