|
|
|
@@ -137,20 +137,54 @@ public class WxProfitSharingOrderServiceImpl implements WxProfitSharingOrderServ |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
@Transactional(isolation=Isolation.SERIALIZABLE, propagation = Propagation.REQUIRED, rollbackFor = {Exception.class}) |
|
|
|
public ResultData createSharingOrder(WxPayOrder wxPayOrder, Long merchantId) { |
|
|
|
//添加分账接受方 |
|
|
|
WxProfitSharingReceiver psReceiverQ = new WxProfitSharingReceiver(); |
|
|
|
psReceiverQ.setTenantId(wxPayOrder.getTenantId()); |
|
|
|
psReceiverQ.setMerchantId(merchantId); |
|
|
|
psReceiverQ.setSharingType(EnumProfitSharingType.PROFIT_SHARING_TYPE_WECHAT.getCode()); |
|
|
|
psReceiverQ.setStatus(EnumProfitSharingReceiverStatus.PROFIT_SHARING_RECEIVER_STATUS_VALID.getCode()); |
|
|
|
List<WxProfitSharingReceiver> psReceiverList = wxProfitSharingReceiverMapper.findList(psReceiverQ); |
|
|
|
if (psReceiverList.size()<=0 || psReceiverList.size() > 50) { |
|
|
|
throw new MallinkException(ErrorCode.PROFIT_SHARING_RECEIVER_INVALID); |
|
|
|
} |
|
|
|
|
|
|
|
return createPSOrder(wxPayOrder, merchantId, psReceiverList, false); |
|
|
|
} |
|
|
|
|
|
|
|
@Transactional(isolation=Isolation.SERIALIZABLE, propagation = Propagation.REQUIRED, rollbackFor = {Exception.class}) |
|
|
|
private ResultData createPSOrder(WxPayOrder wxPayOrder, Long merchantId, List<WxProfitSharingReceiver> psReceiverList, boolean multiCmd) { |
|
|
|
final IdWorker idworker = IdWorker.get(); |
|
|
|
|
|
|
|
WxAppinfo appInfo = getAppinfo(wxPayOrder); |
|
|
|
WxPayAccount payAccount = wxPayAccountMapper.selectByPrimaryKey(appInfo.getPayId()); |
|
|
|
|
|
|
|
// TODO |
|
|
|
WxOrder wxOrder = wxOrderMapper.selectByPrimaryKey(wxPayOrder.getOrderId()); |
|
|
|
|
|
|
|
//是否已创建分账订单 |
|
|
|
//单次分账检查是否已创建分账订单 |
|
|
|
WxProfitSharingOrder record = new WxProfitSharingOrder(); |
|
|
|
record.setOrderId(wxPayOrder.getId()); |
|
|
|
record = wxProfitSharingOrderMapper.selectOne(record); |
|
|
|
if (record == null) { |
|
|
|
if(!multiCmd) { |
|
|
|
record.setOrderId(wxPayOrder.getId()); |
|
|
|
record = wxProfitSharingOrderMapper.selectOne(record); |
|
|
|
if (record == null) { |
|
|
|
//创建分账订单 |
|
|
|
Date currentDate = new Date(); |
|
|
|
record = new WxProfitSharingOrder(); |
|
|
|
record.setId(idworker.nextId()); |
|
|
|
record.setTenantId(wxPayOrder.getTenantId()); |
|
|
|
record.setTransactionId(wxPayOrder.getTransactionId()); |
|
|
|
record.setOrderId(wxPayOrder.getId()); |
|
|
|
record.setPayAmount(wxPayOrder.getPayAmount()); |
|
|
|
record.setMerchantId(merchantId); |
|
|
|
record.setSharingStatus(EnumProfitSharingStatus.PROFIT_SHARING_UNKNOWN.getCode()); |
|
|
|
record.setCreateTime(currentDate); |
|
|
|
record.setUpdateTime(currentDate); |
|
|
|
record.setPayTimeStart(currentDate); |
|
|
|
record.setPayTimeEnd(currentDate); |
|
|
|
wxProfitSharingOrderMapper.insertSelective(record); |
|
|
|
} |
|
|
|
} else { |
|
|
|
//创建分账订单 |
|
|
|
Date currentDate = new Date(); |
|
|
|
record = new WxProfitSharingOrder(); |
|
|
|
@@ -168,31 +202,11 @@ public class WxProfitSharingOrderServiceImpl implements WxProfitSharingOrderServ |
|
|
|
wxProfitSharingOrderMapper.insertSelective(record); |
|
|
|
} |
|
|
|
|
|
|
|
//分账提交 |
|
|
|
WxProfitSharingP wxProfitSharingP = new WxProfitSharingP(); |
|
|
|
wxProfitSharingP.setAppid(appInfo.getParentAppId()); |
|
|
|
wxProfitSharingP.setMch_id(payAccount.getMchId()); |
|
|
|
wxProfitSharingP.setSub_appid(appInfo.getAppId()); |
|
|
|
wxProfitSharingP.setSub_mch_id(payAccount.getSubMchId()); |
|
|
|
wxProfitSharingP.setNonce_str(Utility.generate32UUID()); |
|
|
|
wxProfitSharingP.setTransaction_id(wxPayOrder.getTransactionId()); |
|
|
|
wxProfitSharingP.setOut_order_no(record.getId().toString()); |
|
|
|
wxProfitSharingP.setSign_type("HMAC-SHA256"); |
|
|
|
//添加分账接受方 |
|
|
|
WxProfitSharingReceiver wxProfitSharingReceiver = new WxProfitSharingReceiver(); |
|
|
|
wxProfitSharingReceiver.setTenantId(wxOrder.getTenantId()); |
|
|
|
wxProfitSharingReceiver.setMerchantId(merchantId); |
|
|
|
wxProfitSharingReceiver.setSharingType(EnumProfitSharingType.PROFIT_SHARING_TYPE_WECHAT.getCode()); |
|
|
|
wxProfitSharingReceiver.setStatus(EnumProfitSharingReceiverStatus.PROFIT_SHARING_RECEIVER_STATUS_VALID.getCode()); |
|
|
|
List<WxProfitSharingReceiver> wxProfitSharingReceiverList = wxProfitSharingReceiverMapper.findList(wxProfitSharingReceiver); |
|
|
|
if (wxProfitSharingReceiverList.size()<=0 || wxProfitSharingReceiverList.size() > 50) { |
|
|
|
throw new MallinkException(ErrorCode.PROFIT_SHARING_RECEIVER_INVALID); |
|
|
|
} |
|
|
|
|
|
|
|
// 添加分账接收方 |
|
|
|
JSONArray receivers = new JSONArray(); |
|
|
|
List <WxProfitSharingResult> resultList = new ArrayList<WxProfitSharingResult>(); |
|
|
|
for (int i=0;i<wxProfitSharingReceiverList.size();i++){ |
|
|
|
WxProfitSharingReceiver receiver = wxProfitSharingReceiverList.get(i); |
|
|
|
for (int i=0;i<psReceiverList.size();i++){ |
|
|
|
WxProfitSharingReceiver receiver = psReceiverList.get(i); |
|
|
|
Date currentDate = new Date(); |
|
|
|
JSONObject jo = new JSONObject(); |
|
|
|
jo.put("type",EnumProfitSharingReceiverType.getEnum(receiver.getReceiverType()).getMessage()); |
|
|
|
@@ -215,20 +229,34 @@ public class WxProfitSharingOrderServiceImpl implements WxProfitSharingOrderServ |
|
|
|
resultList.add(result); |
|
|
|
} |
|
|
|
|
|
|
|
wxProfitSharingP.setReceivers(receivers.toJSONString()); |
|
|
|
//分账提交 |
|
|
|
WxProfitSharingP psCmd = new WxProfitSharingP(); |
|
|
|
psCmd.setMch_id(payAccount.getMchId()); |
|
|
|
psCmd.setSub_mch_id(payAccount.getSubMchId()); |
|
|
|
psCmd.setAppid(appInfo.getParentAppId()); |
|
|
|
psCmd.setSub_appid(appInfo.getAppId()); |
|
|
|
psCmd.setNonce_str(Utility.generate32UUID()); |
|
|
|
psCmd.setTransaction_id(wxPayOrder.getTransactionId()); |
|
|
|
psCmd.setOut_order_no(record.getId().toString()); |
|
|
|
psCmd.setSign_type("HMAC-SHA256"); |
|
|
|
psCmd.setReceivers(receivers.toJSONString()); |
|
|
|
|
|
|
|
String response; |
|
|
|
try { |
|
|
|
wxProfitSharingP.setSign(WxPayment.createSignHMAC(BeanUtils.toStringMap(wxProfitSharingP), payAccount.getApiKey())); |
|
|
|
logger.info("wxProfitSharingP :" + wxProfitSharingP.toString()); |
|
|
|
response = WxProfitSharing.pushOrder(BeanUtils.toStringMap(wxProfitSharingP), payAccount.getCertPath(), payAccount.getMchId()); |
|
|
|
}catch (Exception e) { |
|
|
|
psCmd.setSign(WxPayment.createSignHMAC(BeanUtils.toStringMap(psCmd), payAccount.getApiKey())); |
|
|
|
if(!multiCmd) { |
|
|
|
response = WxProfitSharing.pushOrder(BeanUtils.toStringMap(psCmd), payAccount.getCertPath(), payAccount.getMchId()); |
|
|
|
} else { |
|
|
|
response = WxProfitSharing.pushMultiOrder(BeanUtils.toStringMap(psCmd), payAccount.getCertPath(), payAccount.getMchId()); |
|
|
|
} |
|
|
|
} catch (Exception e) { |
|
|
|
record.setSharingStatus(EnumProfitSharingStatus.PROFIT_SHARING_REQ_FAILED.getCode()); |
|
|
|
record.setErrorMsg(ErrorCode.PROFIT_SHARING_REQUEST_FAILED.getMessage()); |
|
|
|
record.setUpdateTime(new Date()); |
|
|
|
wxProfitSharingOrderMapper.updateByPrimaryKey(record); |
|
|
|
return new ResultData(ErrorCode.PROFIT_SHARING_REQUEST_FAILED); |
|
|
|
} |
|
|
|
|
|
|
|
logger.info("response: " + response); |
|
|
|
Map<String, String> returnMap = WxPayment.xmlToMap(response); |
|
|
|
String return_code = returnMap.get("return_code"); |
|
|
|
@@ -261,10 +289,11 @@ public class WxProfitSharingOrderServiceImpl implements WxProfitSharingOrderServ |
|
|
|
record.setSharingStatus(EnumProfitSharingStatus.PROFIT_SHARING_ACCEPTED.getCode()); |
|
|
|
record.setUpdateTime(new Date()); |
|
|
|
wxProfitSharingOrderMapper.updateByPrimaryKey(record); |
|
|
|
for (WxProfitSharingResult result:resultList) |
|
|
|
for (WxProfitSharingResult result:resultList) { |
|
|
|
wxProfitSharingResultMapper.insertSelective(result); |
|
|
|
return new ResultData(returnMap); |
|
|
|
} |
|
|
|
|
|
|
|
return new ResultData(returnMap); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
|