Bläddra i källkod

[支付][修改]:分账账户设置修改

release_toaliyun_real
hupeng 7 år sedan
förälder
incheckning
3db086607b
4 ändrade filer med 61 tillägg och 31 borttagningar
  1. +2
    -1
      mallinkService/src/main/java/com/simple/common/ErrorCode.java
  2. +2
    -2
      mallinkService/src/main/java/com/simple/pay/WxProfitSharingP.java
  3. +2
    -2
      mallinkService/src/main/java/com/simple/service/WxProfitSharingOrderService.java
  4. +55
    -26
      mallinkService/src/main/java/com/simple/service/impl/WxProfitSharingOrderServiceImpl.java

+ 2
- 1
mallinkService/src/main/java/com/simple/common/ErrorCode.java Visa fil

@@ -116,7 +116,8 @@ public enum ErrorCode{


PROFIT_SHARING_REQUEST_FAILED(12030, "分账请求失败"), PROFIT_SHARING_REQUEST_FAILED(12030, "分账请求失败"),
PROFIT_SHARING_APPLY_FAILED(12031, "分账请求业务失败"), PROFIT_SHARING_APPLY_FAILED(12031, "分账请求业务失败"),
PROFIT_SHARING_RETURN_INVALID(12022, "分账请求返回校验失败"),
PROFIT_SHARING_RETURN_INVALID(12032, "分账请求返回校验失败"),
PROFIT_SHARING_RECEIVER_INVALID(12033, "分账接受方查寻无效"),


/** /**
* 核销 * 核销


+ 2
- 2
mallinkService/src/main/java/com/simple/pay/WxProfitSharingP.java Visa fil

@@ -78,11 +78,11 @@ public class WxProfitSharingP implements Serializable {
this.out_trade_no = out_trade_no; this.out_trade_no = out_trade_no;
} }


public String setReceivers() {
public String getReceivers() {
return receivers; return receivers;
} }


public void getReceivers(String receivers) {
public void setReceivers(String receivers) {
this.receivers = receivers; this.receivers = receivers;
} }




+ 2
- 2
mallinkService/src/main/java/com/simple/service/WxProfitSharingOrderService.java Visa fil

@@ -4,7 +4,7 @@ import java.util.*;
import com.github.pagehelper.PageInfo; import com.github.pagehelper.PageInfo;
import com.simple.common.ResultData; import com.simple.common.ResultData;
import com.simple.domain.po.WxAppinfo; import com.simple.domain.po.WxAppinfo;
import com.simple.domain.po.WxOrder;
import com.simple.domain.po.WxPayOrder;
import com.simple.domain.po.WxProfitSharingOrder; import com.simple.domain.po.WxProfitSharingOrder;


public interface WxProfitSharingOrderService { public interface WxProfitSharingOrderService {
@@ -45,7 +45,7 @@ public interface WxProfitSharingOrderService {
/** /**
* 创建分账订单 * 创建分账订单
*/ */
public ResultData createSharingOrder(WxAppinfo appInfo, WxOrder wxOrder);
public ResultData createSharingOrder(WxAppinfo appInfo, WxPayOrder wxPayOrder);


+ 55
- 26
mallinkService/src/main/java/com/simple/service/impl/WxProfitSharingOrderServiceImpl.java Visa fil

@@ -8,16 +8,11 @@ import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo; import com.github.pagehelper.PageInfo;
import com.simple.common.ErrorCode; import com.simple.common.ErrorCode;
import com.simple.common.ResultData; import com.simple.common.ResultData;
import com.simple.domain.po.WxAppinfo;
import com.simple.domain.po.WxOrder;
import com.simple.domain.po.WxPayAccount;
import com.simple.domain.po.WxProfitSharingOrder;
import com.simple.domain.po.*;
import com.simple.enums.EnumPayDomain; import com.simple.enums.EnumPayDomain;
import com.simple.enums.EnumProfitSharingStatus; import com.simple.enums.EnumProfitSharingStatus;
import com.simple.exception.MallinkException; import com.simple.exception.MallinkException;
import com.simple.mapper.WxAppinfoMapper;
import com.simple.mapper.WxPayAccountMapper;
import com.simple.mapper.WxProfitSharingOrderMapper;
import com.simple.mapper.*;
import com.simple.pay.WxPayment; import com.simple.pay.WxPayment;
import com.simple.pay.WxProfitSharing; import com.simple.pay.WxProfitSharing;
import com.simple.pay.WxProfitSharingP; import com.simple.pay.WxProfitSharingP;
@@ -43,7 +38,14 @@ public class WxProfitSharingOrderServiceImpl implements WxProfitSharingOrderServ
WxPayAccountMapper wxPayAccountMapper; WxPayAccountMapper wxPayAccountMapper;


@Autowired @Autowired
WxProfitSharingOrderMapper wxOrderMapper;
WxOrderMapper wxOrderMapper;

@Autowired
WxProfitSharingReceiverMapper wxProfitSharingReceiverMapper;

@Autowired
WxProfitSharingResultMapper wxProfitSharingResultMapper;





JSONObject errorMap = JSON.parseObject( JSONObject errorMap = JSON.parseObject(
@@ -87,29 +89,29 @@ public class WxProfitSharingOrderServiceImpl implements WxProfitSharingOrderServ
} }


@Override @Override
public ResultData createSharingOrder(WxAppinfo subAppInfo, WxOrder wxOrder) {
public ResultData createSharingOrder(WxAppinfo subAppInfo, WxPayOrder wxPayOrder) {
final IdWorker idworker = IdWorker.get(); final IdWorker idworker = IdWorker.get();

WxProfitSharingOrder record = new WxProfitSharingOrder(); WxProfitSharingOrder record = new WxProfitSharingOrder();
try { try {
WxOrder wxOrder = wxOrderMapper.selectByPrimaryKey(wxPayOrder.getOrderId());
//是否已创建分账订单 //是否已创建分账订单
Date currentDate = new Date();
record.setOrderId(wxOrder.getId().toString());
record.setOrderId(wxPayOrder.getId().toString());
record = wxProfitSharingOrderMapper.selectOne(record); record = wxProfitSharingOrderMapper.selectOne(record);
if (record == null) { if (record == null) {
//创建分账订单 //创建分账订单
Date currentDate = new Date();
record.setId(idworker.nextId()); record.setId(idworker.nextId());
record.setTenantId(wxOrder.getTenantId());
record.setOrderId(wxOrder.getId().toString());
record.setPayAmount(wxOrder.getPayment());
//record.setMerchantId();
record.setTenantId(wxPayOrder.getTenantId());
record.setOrderId(wxPayOrder.getId().toString());
record.setPayAmount(wxPayOrder.getPayAmount());
record.setMerchantId(wxOrder.getMerchantId().toString());
record.setCreateTime(currentDate); record.setCreateTime(currentDate);
record.setUpdateTime(currentDate); record.setUpdateTime(currentDate);
record.setPayTimeStart(currentDate); record.setPayTimeStart(currentDate);
record.setPayTimeEnd(currentDate); record.setPayTimeEnd(currentDate);


if (wxProfitSharingOrderMapper.insertSelective(record) != 1) {
throw new MallinkException(ErrorCode.DB_FAIL);
}
wxProfitSharingOrderMapper.insertSelective(record);
} }


WxPayAccount payAccount = wxPayAccountMapper.selectByPrimaryKey(subAppInfo.getPayId()); WxPayAccount payAccount = wxPayAccountMapper.selectByPrimaryKey(subAppInfo.getPayId());
@@ -121,15 +123,39 @@ public class WxProfitSharingOrderServiceImpl implements WxProfitSharingOrderServ
wxProfitSharingP.setAppid(mainAppInfo.getAppId()); wxProfitSharingP.setAppid(mainAppInfo.getAppId());
wxProfitSharingP.setMch_id(mainPayAccount.getMchId()); wxProfitSharingP.setMch_id(mainPayAccount.getMchId());
wxProfitSharingP.setSub_appid(subAppInfo.getAppId()); wxProfitSharingP.setSub_appid(subAppInfo.getAppId());
wxProfitSharingP.setMch_id(payAccount.getMchId());
wxProfitSharingP.setSub_mch_id(payAccount.getMchId()); wxProfitSharingP.setSub_mch_id(payAccount.getMchId());
wxProfitSharingP.setNonce_str(Utility.generate32UUID()); wxProfitSharingP.setNonce_str(Utility.generate32UUID());
wxProfitSharingP.setTransaction_id(wxOrder.getTenantId());
wxProfitSharingP.setTransaction_id(wxPayOrder.getTransactionId());
wxProfitSharingP.setOut_trade_no(record.getId().toString()); wxProfitSharingP.setOut_trade_no(record.getId().toString());


//添加分账接受方 //添加分账接受方
WxProfitSharingReceiver wxProfitSharingReceiver = new WxProfitSharingReceiver();
wxProfitSharingReceiver.setMerchantId(wxOrder.getMerchantId().toString());
wxProfitSharingReceiver.setSharingType(1);
List<WxProfitSharingReceiver> wxProfitSharingReceiverList = wxProfitSharingReceiverMapper.findList(wxProfitSharingReceiver);
if (wxProfitSharingReceiverList.size()<=0 || wxProfitSharingReceiverList.size() > 50) {
throw new MallinkException(ErrorCode.PROFIT_SHARING_RECEIVER_INVALID.getCode(), ErrorCode.PROFIT_SHARING_RECEIVER_INVALID.getMessage());
}
JSONObject receivers = new JSONObject();
List <WxProfitSharingResult> resultList = new ArrayList<WxProfitSharingResult>();
for (int i=0;i<=wxProfitSharingReceiverList.size();i++){
WxProfitSharingReceiver receiver = wxProfitSharingReceiverList.get(i);
Date currentDate = new Date();
receivers.put("type",receiver.getReceiverType());
receivers.put("acount",receiver.getReceiverAccount());
receivers.put("amount",record.getPayAmount()); //temp: sharing all money with only owner
receivers.put("description",receiver.getReceiverComments());
WxProfitSharingResult result = new WxProfitSharingResult();

result.setId(idworker.nextId());
result.setSharingOrderId(record.getSharingOrderId());
result.setSharingReceiverId(receiver.getId().toString());
result.setCreateTime(currentDate);
result.setUpdateTime(currentDate);
resultList.add(result);
}



wxProfitSharingP.setReceivers(receivers.toJSONString());


wxProfitSharingP.setSign(WxPayment.createSign(BeanUtils.toStringMap(wxProfitSharingP), payAccount.getApiKey())); wxProfitSharingP.setSign(WxPayment.createSign(BeanUtils.toStringMap(wxProfitSharingP), payAccount.getApiKey()));
String response = WxProfitSharing.pushOrder(BeanUtils.toStringMap(wxProfitSharingP)); String response = WxProfitSharing.pushOrder(BeanUtils.toStringMap(wxProfitSharingP));
@@ -138,26 +164,29 @@ public class WxProfitSharingOrderServiceImpl implements WxProfitSharingOrderServ
String return_code = returnMap.get("return_code"); String return_code = returnMap.get("return_code");
if (!"SUCCESS".equals(return_code)) { if (!"SUCCESS".equals(return_code)) {
record.setSharingStatus(EnumProfitSharingStatus.PROFIT_SHARING_REQ_FAILED.getCode()); record.setSharingStatus(EnumProfitSharingStatus.PROFIT_SHARING_REQ_FAILED.getCode());
record.setUpdateTime(new Date());
wxProfitSharingOrderMapper.updateByPrimaryKey(record); 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.verifyNotify(returnMap,payAccount.getApiKey())){ if (!WxPayment.verifyNotify(returnMap,payAccount.getApiKey())){
throw new MallinkException(ErrorCode.PROFIT_SHARING_RETURN_INVALID.getCode(), ErrorCode.PROFIT_SHARING_RETURN_INVALID.getMessage());
return new ResultData(ErrorCode.PROFIT_SHARING_RETURN_INVALID.getCode(), ErrorCode.PROFIT_SHARING_RETURN_INVALID.getMessage());
} }


String result_code = returnMap.get("result_code"); String result_code = returnMap.get("result_code");
if (!"SUCCESS".equals(result_code)) { if (!"SUCCESS".equals(result_code)) {
record.setSharingStatus(EnumProfitSharingStatus.PROFIT_SHARING_APPLY_FAILED.getCode()); record.setSharingStatus(EnumProfitSharingStatus.PROFIT_SHARING_APPLY_FAILED.getCode());
record.setUpdateTime(new Date());
wxProfitSharingOrderMapper.updateByPrimaryKey(record); 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.setSharingOrderId(returnMap.get("order_id")); record.setSharingOrderId(returnMap.get("order_id"));
record.setSharingStatus(EnumProfitSharingStatus.PROFIT_SHARING_ACCEPTED.getCode()); record.setSharingStatus(EnumProfitSharingStatus.PROFIT_SHARING_ACCEPTED.getCode());
record.setUpdateTime(new Date());
wxProfitSharingOrderMapper.updateByPrimaryKey(record); wxProfitSharingOrderMapper.updateByPrimaryKey(record);
return new ResultData(200, "分账申请成功", returnMap);
wxProfitSharingResultMapper.insertList(resultList);
return new ResultData(returnMap);


} catch (RuntimeException e) { } catch (RuntimeException e) {
throw new MallinkException(ErrorCode.PAY_ORDER_ERROR.getCode(), e.getMessage()); throw new MallinkException(ErrorCode.PAY_ORDER_ERROR.getCode(), e.getMessage());


Laddar…
Avbryt
Spara