From a9d086edcf1257428c3e4ea7b5e5cb5a19479310 Mon Sep 17 00:00:00 2001 From: Stormeye Wu Date: Sat, 8 Dec 2018 15:33:40 +0800 Subject: [PATCH] =?UTF-8?q?[=E5=88=86=E8=B4=A6][=E6=96=B0=E5=A2=9E]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/iformall/pay/WxProfitSharing.java | 26 ++++- .../impl/WxProfitSharingOrderServiceImpl.java | 99 ++++++++++++------- 2 files changed, 88 insertions(+), 37 deletions(-) diff --git a/mallinkService/src/main/java/com/iformall/pay/WxProfitSharing.java b/mallinkService/src/main/java/com/iformall/pay/WxProfitSharing.java index b5a5dc711..5bb82f764 100644 --- a/mallinkService/src/main/java/com/iformall/pay/WxProfitSharing.java +++ b/mallinkService/src/main/java/com/iformall/pay/WxProfitSharing.java @@ -9,8 +9,12 @@ import org.slf4j.LoggerFactory; public class WxProfitSharing { protected static Logger log = LoggerFactory.getLogger(WxProfitSharing.class); - // 分账接口 + // 单次分账接口 private static final String PROFIT_SHARING_URL = "https://api.mch.weixin.qq.com/secapi/pay/profitsharing"; + // 多次分账接口 + private static final String PROFIT_MULTI_SHARING_URL = "https://api.mch.weixin.qq.com/secapi/pay/multiprofitsharing"; + // 分账完结接口 + private static final String PROFIT_SHARING_FINISH_URL = "https://api.mch.weixin.qq.com/secapi/pay/profitsharingfinish"; // 查询接口 private static final String PROFIT_SHARING_QUERY_URL = "https://api.mch.weixin.qq.com/pay/profitsharingquery"; // 添加分账账户 @@ -23,7 +27,7 @@ public class WxProfitSharing { } /** - * 分账下单 + * 单次分账下单 * @param params * @return */ @@ -31,6 +35,24 @@ public class WxProfitSharing { return doPostSSL(PROFIT_SHARING_URL, params, certPath, certPass); } + /** + * 多次分账下单 + * @param params + * @return + */ + public static String pushMultiOrder(Map params, String certPath, String certPass) { + return doPostSSL(PROFIT_MULTI_SHARING_URL, params, certPath, certPass); + } + + /** + * 分账完结 + * @param params + * @return + */ + public static String finishOrder(Map params, String certPath, String certPass) { + return doPostSSL(PROFIT_SHARING_FINISH_URL, params, certPath, certPass); + } + /** * 分账查询 * @param params diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxProfitSharingOrderServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxProfitSharingOrderServiceImpl.java index 560d70330..3ec0d0d11 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxProfitSharingOrderServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxProfitSharingOrderServiceImpl.java @@ -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 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 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 wxProfitSharingReceiverList = wxProfitSharingReceiverMapper.findList(wxProfitSharingReceiver); - if (wxProfitSharingReceiverList.size()<=0 || wxProfitSharingReceiverList.size() > 50) { - throw new MallinkException(ErrorCode.PROFIT_SHARING_RECEIVER_INVALID); - } - + // 添加分账接收方 JSONArray receivers = new JSONArray(); List resultList = new ArrayList(); - for (int i=0;i 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