diff --git a/mallinkBApi/src/main/java/com/iformall/controller/WxMicroPayController.java b/mallinkBApi/src/main/java/com/iformall/controller/WxMicroPayController.java index 9c6d8c886..8edc2fe6a 100644 --- a/mallinkBApi/src/main/java/com/iformall/controller/WxMicroPayController.java +++ b/mallinkBApi/src/main/java/com/iformall/controller/WxMicroPayController.java @@ -54,6 +54,9 @@ public class WxMicroPayController extends BaseController { @Autowired WxAppinfoService wxAppinfoService; + @Autowired + WxPayAccountService wxPayAccountService; + @Autowired WxCouponOrderService wxCouponOrderService; @@ -70,14 +73,15 @@ public class WxMicroPayController extends BaseController { @PostMapping("order_create") public ResultData saveMicopayOrder(@RequestBody Map paramMap, HttpServletRequest request) { logger.info("saveMicopayOrder: " + paramMap.toString()); + String ipStr = IPUtil.getIpAddr(request); //Assert.notNull(wxOrders.getName(), "角色名不能为空"); //Assert.isTrue(!checkUnique(sysRole.getName(), null), "重复的角色名"); String authCode = paramMap.get("authCode"); String totalFeeStr = paramMap.get("totalFee"); - return saveMicopayOrder(authCode, totalFeeStr, EnumPayWay.PAY_WAY_WECHAT_MA,EnumPayVersion.WX_PAY_V2, request); + return saveMicopayOrder(authCode, totalFeeStr, EnumPayWay.PAY_WAY_WECHAT_MA, ipStr); } - private ResultData saveMicopayOrder(String authCode,String totalFeeStr,EnumPayWay payWay,EnumPayVersion payVersion,HttpServletRequest request) { + private ResultData saveMicopayOrder(String authCode,String totalFeeStr,EnumPayWay payWay,String ipStr) { if (StringUtils.isBlank(authCode)) { logger.error("authCode不能为空"); return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "authCode不能为空"); @@ -90,11 +94,18 @@ public class WxMicroPayController extends BaseController { logger.error("totalFee不能为空"); return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "totalFee不能为空"); } - - String ipStr = IPUtil.getIpAddr(request); WxMerchantBUser user = getLoginBUser(); + WxPayAccount payAccount = wxPayAccountService.getPayAccount(user, payWay.getPlat()); + if(payAccount == null){ + return new ResultData(ErrorCode.API_KEY_NOT_FOUND.getCode(), "未找到支付配置"); + } + EnumPayVersion payVersion = EnumPayVersion.getEnum(payAccount.getPayVersion()); + if(payVersion == null){ + return new ResultData(ErrorCode.MCH_INFO_NOT_EQUAL.getCode(), "支付配置错误"); + } + WxOrder order = null; try { order = wxOrderService.saveMicroPayOrder(user, totalFeeStr,payWay,payVersion); @@ -382,16 +393,18 @@ public class WxMicroPayController extends BaseController { @PostMapping("pay_order_create_v2") public ResultData saveMicopayPayOrder(@RequestBody Map paramMap, HttpServletRequest request) { logger.info("saveMicopayPayOrder: " + paramMap.toString()); + String ipStr = IPUtil.getIpAddr(request); + String orderIdStr = paramMap.get("orderId"); String couponOrderIdStr = paramMap.get("couponOrderId"); String authCode = paramMap.get("authCode"); String payPriceStr = paramMap.get("payPrice"); - return saveMicopayPayOrder(orderIdStr, couponOrderIdStr, authCode, payPriceStr, EnumPayWay.PAY_WAY_WECHAT_MA,EnumPayVersion.WX_PAY_V2, request); + return saveMicopayPayOrder(orderIdStr, couponOrderIdStr, authCode, payPriceStr, EnumPayWay.PAY_WAY_WECHAT_MA,ipStr); } private ResultData saveMicopayPayOrder(String orderIdStr,String couponOrderIdStr,String authCode,String payPriceStr, - EnumPayWay payWay,EnumPayVersion payVersion, HttpServletRequest request) { - WxMerchantBUser user = getLoginBUser(); + EnumPayWay payWay,String ipStr) { + if (StringUtils.isBlank(orderIdStr)) { logger.error("orderId不能为空"); return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "orderId不能为空"); @@ -407,12 +420,22 @@ public class WxMicroPayController extends BaseController { return new ResultData(ErrorCode.MICRO_PAY_ERR_AUTHCODE.getCode(), "请扫描微信收款码"); } } + WxMerchantBUser user = getLoginBUser(); + + WxPayAccount payAccount = wxPayAccountService.getPayAccount(user, payWay.getPlat()); + if(payAccount == null){ + return new ResultData(ErrorCode.API_KEY_NOT_FOUND.getCode(), "未找到支付配置"); + } + EnumPayVersion payVersion = EnumPayVersion.getEnum(payAccount.getPayVersion()); + if(payVersion == null){ + return new ResultData(ErrorCode.MCH_INFO_NOT_EQUAL.getCode(), "支付配置错误"); + } BigDecimal totalFee = new BigDecimal(payPriceStr); totalFee.setScale(2, BigDecimal.ROUND_HALF_UP); // 第一个变量是小数位数,第二个变量是取舍方法(四舍五入) Integer payPrice = totalFee.multiply(new BigDecimal(100)).intValue(); - String ipStr = IPUtil.getIpAddr(request); + WxMerchantBUser wxMerchantBUser = wxMerchantBUserService.getById(user.getId()); if (wxMerchantBUser == null) { diff --git a/mallinkBApi/src/test/java/com/iformall/b/CouponsendTest.java b/mallinkBApi/src/test/java/com/iformall/b/CouponsendTest.java index 392e6cd5e..4a262d637 100644 --- a/mallinkBApi/src/test/java/com/iformall/b/CouponsendTest.java +++ b/mallinkBApi/src/test/java/com/iformall/b/CouponsendTest.java @@ -66,7 +66,7 @@ public class CouponsendTest { Long orderId = 0l;//wx_order------composeOrderId Long payOrderId = 0l;//wx_pay_order---------id - wxOrderService.shareForMicroPay(tenantEntity, orderId, payOrderId, EnumPayWay.PAY_WAY_WECHAT_MA); + wxOrderService.shareForMicroPay(tenantEntity, orderId, payOrderId); } //补贴 diff --git a/mallinkSchedule/src/main/java/com/iformall/schedule/CouponOrderExpiringSchedule.java b/mallinkSchedule/src/main/java/com/iformall/schedule/CouponOrderExpiringSchedule.java index d6d3d95e4..1f411152c 100644 --- a/mallinkSchedule/src/main/java/com/iformall/schedule/CouponOrderExpiringSchedule.java +++ b/mallinkSchedule/src/main/java/com/iformall/schedule/CouponOrderExpiringSchedule.java @@ -223,7 +223,8 @@ public class CouponOrderExpiringSchedule { wxSharingOrderDto.setShareAmount(wxPayOrder.getChildOrderShare(co.getOrderId()).getShareAmount()); } //wxSharingOrderDto.setShareAmount(wxPayOrder.getPayAmount()); - wxProfitSharingOrderService.finishSharingOrder(wxPayOrder,wxSharingOrderDto,wxPayOrder.getPayVendor(),wxPayOrder.getShare()); + wxProfitSharingOrderService.createSharingOrder(wxSharingOrderDto,wxPayOrder); +// wxProfitSharingOrderService.finishSharingOrder(wxPayOrder,wxSharingOrderDto,wxPayOrder.getPayVendor(),wxPayOrder.getShare()); } } catch (MallinkException e) { diff --git a/mallinkSchedule/src/main/java/com/iformall/schedule/SharingOrderRedoSchedule.java b/mallinkSchedule/src/main/java/com/iformall/schedule/SharingOrderRedoSchedule.java index 76b24ce37..e4a05a4b9 100644 --- a/mallinkSchedule/src/main/java/com/iformall/schedule/SharingOrderRedoSchedule.java +++ b/mallinkSchedule/src/main/java/com/iformall/schedule/SharingOrderRedoSchedule.java @@ -43,14 +43,14 @@ public class SharingOrderRedoSchedule { @Async // @Scheduled(cron = "0 0 2 * * ?") // 每天凌晨02:00分账重试 - @Scheduled(cron = "0 15 */1 * * ?")// 每2个小时的15分钟 + @Scheduled(cron = "0 15 */2 * * ?")// 每2个小时的15分钟 // @Scheduled(cron = "0 0/10 * * * ?") // 测试 public void sharingOrderRedoSchedule() { List malls = getMalls(); for (WxMall mall: malls) { WxProfitSharingOrder wxProfitSharingOrder = new WxProfitSharingOrder(); wxProfitSharingOrder.setTenantId(mall.getTenantId()); - wxProfitSharingOrder.setType(EnumProfitSharingOrderType.PROFIT_SHARING_SINGLE.getCode()); +// wxProfitSharingOrder.setType(EnumProfitSharingOrderType.PROFIT_SHARING_SINGLE.getCode()); wxProfitSharingOrder.setSharingStatus(EnumProfitSharingOrderStatus.PROFIT_SHARING_APPLY_FAILED.getCode()); List list = wxProfitSharingOrderMapper.findList(wxProfitSharingOrder); if (null != list) { @@ -72,45 +72,45 @@ public class SharingOrderRedoSchedule { } - wxProfitSharingOrder.setType(EnumProfitSharingOrderType.PROFIT_SHARING_MULTI.getCode()); - wxProfitSharingOrder.setSharingStatus(EnumProfitSharingOrderStatus.PROFIT_SHARING_APPLY_FAILED.getCode()); - list = wxProfitSharingOrderMapper.findList(wxProfitSharingOrder); - if (null != list) { - list.stream().forEach(sharingOrder->{ - try { - ResultData result = wxProfitSharingOrderService.redoSharingOrder(sharingOrder); - if (result.code != ResultData.SUCCESS) { - logger.error("分账重试失败:" + EnumProfitSharingOrderType.PROFIT_SHARING_MULTI.getMessage() - + " ID:" +sharingOrder.getId() - + " RES:" + result.message); - } - } catch (Exception e){ - logger.error("分账重试失败:" + EnumProfitSharingOrderType.PROFIT_SHARING_MULTI.getMessage() - + " ID:" +sharingOrder.getId() - + " MSG:" + e.getMessage()); - } - }); - } - - wxProfitSharingOrder.setType(EnumProfitSharingOrderType.PROFIT_SHARING_SINGLE_FINISH.getCode()); - wxProfitSharingOrder.setSharingStatus(EnumProfitSharingOrderStatus.PROFIT_SHARING_APPLY_FAILED.getCode()); - list = wxProfitSharingOrderMapper.findList(wxProfitSharingOrder); - if (null != list) { - list.stream().forEach(sharingOrder->{ - try { - ResultData result = wxProfitSharingOrderService.redoFinishSharingOrder(sharingOrder); - if (result.code != ResultData.SUCCESS) { - logger.error("分账重试失败:" + EnumProfitSharingOrderType.PROFIT_SHARING_SINGLE_FINISH.getMessage() - + " ID:" +sharingOrder.getId() - + " RES:" + result.message); - } - } catch (Exception e){ - logger.error("分账重试失败:" + EnumProfitSharingOrderType.PROFIT_SHARING_SINGLE_FINISH.getMessage() - + " ID:" +sharingOrder.getId() - + " MSG:" + e.getMessage()); - } - }); - } +// wxProfitSharingOrder.setType(EnumProfitSharingOrderType.PROFIT_SHARING_MULTI.getCode()); +// wxProfitSharingOrder.setSharingStatus(EnumProfitSharingOrderStatus.PROFIT_SHARING_APPLY_FAILED.getCode()); +// list = wxProfitSharingOrderMapper.findList(wxProfitSharingOrder); +// if (null != list) { +// list.stream().forEach(sharingOrder->{ +// try { +// ResultData result = wxProfitSharingOrderService.redoSharingOrder(sharingOrder); +// if (result.code != ResultData.SUCCESS) { +// logger.error("分账重试失败:" + EnumProfitSharingOrderType.PROFIT_SHARING_MULTI.getMessage() +// + " ID:" +sharingOrder.getId() +// + " RES:" + result.message); +// } +// } catch (Exception e){ +// logger.error("分账重试失败:" + EnumProfitSharingOrderType.PROFIT_SHARING_MULTI.getMessage() +// + " ID:" +sharingOrder.getId() +// + " MSG:" + e.getMessage()); +// } +// }); +// } +// +// wxProfitSharingOrder.setType(EnumProfitSharingOrderType.PROFIT_SHARING_SINGLE_FINISH.getCode()); +// wxProfitSharingOrder.setSharingStatus(EnumProfitSharingOrderStatus.PROFIT_SHARING_APPLY_FAILED.getCode()); +// list = wxProfitSharingOrderMapper.findList(wxProfitSharingOrder); +// if (null != list) { +// list.stream().forEach(sharingOrder->{ +// try { +// ResultData result = wxProfitSharingOrderService.redoFinishSharingOrder(sharingOrder); +// if (result.code != ResultData.SUCCESS) { +// logger.error("分账重试失败:" + EnumProfitSharingOrderType.PROFIT_SHARING_SINGLE_FINISH.getMessage() +// + " ID:" +sharingOrder.getId() +// + " RES:" + result.message); +// } +// } catch (Exception e){ +// logger.error("分账重试失败:" + EnumProfitSharingOrderType.PROFIT_SHARING_SINGLE_FINISH.getMessage() +// + " ID:" +sharingOrder.getId() +// + " MSG:" + e.getMessage()); +// } +// }); +// } } diff --git a/mallinkSchedule/src/main/java/com/iformall/schedule/SharingOrderRedoScheduletttttttttttttttttttttttttt.java b/mallinkSchedule/src/main/java/com/iformall/schedule/SharingOrderRedoScheduletttttttttttttttttttttttttt.java index 9a342fbbf..42cfc067b 100644 --- a/mallinkSchedule/src/main/java/com/iformall/schedule/SharingOrderRedoScheduletttttttttttttttttttttttttt.java +++ b/mallinkSchedule/src/main/java/com/iformall/schedule/SharingOrderRedoScheduletttttttttttttttttttttttttt.java @@ -1,57 +1,57 @@ -package com.iformall.schedule; - -import com.iformall.common.ErrorCode; -import com.iformall.common.ResultData; -import com.iformall.domain.dto.WxSharingOrderDto; -import com.iformall.domain.po.WxMall; -import com.iformall.domain.po.WxProfitSharingOrder; -import com.iformall.enums.EnumPayWay; -import com.iformall.enums.EnumProfitSharingOrderStatus; -import com.iformall.enums.EnumProfitSharingOrderType; -import com.iformall.mapper.WxMallMapper; -import com.iformall.mapper.WxPayOrderMapper; -import com.iformall.mapper.WxProfitSharingOrderMapper; -import com.iformall.service.WxProfitSharingOrderService; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.scheduling.annotation.Async; -import org.springframework.scheduling.annotation.Scheduled; -import org.springframework.stereotype.Component; - -import java.util.List; - -@Component -public class SharingOrderRedoScheduletttttttttttttttttttttttttt { - - private final Logger logger = LoggerFactory.getLogger(this.getClass()); - - @Autowired - private WxProfitSharingOrderService wxProfitSharingOrderService; - - @Autowired - private WxProfitSharingOrderMapper wxProfitSharingOrderMapper; - - @Autowired - WxMallMapper wxMallMapper; - - private List getMalls() { - WxMall wxMall =new WxMall(); - return wxMallMapper.findList(wxMall); - } - - @Async - @Scheduled(cron = "0 5 0 * * ?") // 每天凌晨02:00分账重试 - //@Scheduled(cron = "*/10 * * * * ?") // 测试10秒中一次 - public void sharingOrderResultSchedule() { - List malls = getMalls(); - for (WxMall mall: malls) { - try { - wxProfitSharingOrderService.updatetttttttttttttt(mall.getTenantId()); - }catch(Exception e) { - logger.error("sharingOrderResultScheduletttttttt error",e); - } - } - - } -} \ No newline at end of file +//package com.iformall.schedule; +// +//import com.iformall.common.ErrorCode; +//import com.iformall.common.ResultData; +//import com.iformall.domain.dto.WxSharingOrderDto; +//import com.iformall.domain.po.WxMall; +//import com.iformall.domain.po.WxProfitSharingOrder; +//import com.iformall.enums.EnumPayWay; +//import com.iformall.enums.EnumProfitSharingOrderStatus; +//import com.iformall.enums.EnumProfitSharingOrderType; +//import com.iformall.mapper.WxMallMapper; +//import com.iformall.mapper.WxPayOrderMapper; +//import com.iformall.mapper.WxProfitSharingOrderMapper; +//import com.iformall.service.WxProfitSharingOrderService; +//import org.slf4j.Logger; +//import org.slf4j.LoggerFactory; +//import org.springframework.beans.factory.annotation.Autowired; +//import org.springframework.scheduling.annotation.Async; +//import org.springframework.scheduling.annotation.Scheduled; +//import org.springframework.stereotype.Component; +// +//import java.util.List; +// +//@Component +//public class SharingOrderRedoScheduletttttttttttttttttttttttttt { +// +// private final Logger logger = LoggerFactory.getLogger(this.getClass()); +// +// @Autowired +// private WxProfitSharingOrderService wxProfitSharingOrderService; +// +// @Autowired +// private WxProfitSharingOrderMapper wxProfitSharingOrderMapper; +// +// @Autowired +// WxMallMapper wxMallMapper; +// +// private List getMalls() { +// WxMall wxMall =new WxMall(); +// return wxMallMapper.findList(wxMall); +// } +// +// @Async +// @Scheduled(cron = "0 5 0 * * ?") // 每天凌晨02:00分账重试 +// //@Scheduled(cron = "*/10 * * * * ?") // 测试10秒中一次 +// public void sharingOrderResultSchedule() { +// List malls = getMalls(); +// for (WxMall mall: malls) { +// try { +// wxProfitSharingOrderService.updatetttttttttttttt(mall.getTenantId()); +// }catch(Exception e) { +// logger.error("sharingOrderResultScheduletttttttt error",e); +// } +// } +// +// } +//} \ No newline at end of file diff --git a/mallinkService/src/main/java/com/iformall/enums/EnumProfitSharingOrderStatus.java b/mallinkService/src/main/java/com/iformall/enums/EnumProfitSharingOrderStatus.java index e7e444b2a..f887c2868 100644 --- a/mallinkService/src/main/java/com/iformall/enums/EnumProfitSharingOrderStatus.java +++ b/mallinkService/src/main/java/com/iformall/enums/EnumProfitSharingOrderStatus.java @@ -1,5 +1,8 @@ package com.iformall.enums; +import java.util.ArrayList; +import java.util.List; + /** * Created by Stormeye on 2018/08/09. */ @@ -38,4 +41,13 @@ public enum EnumProfitSharingOrderStatus { public String getMessage() { return message; } + + public static List shareStatus(){ + List list = new ArrayList<>(); + list.add(PROFIT_SHARING_READY.getCode()); + list.add(PROFIT_SHARING_REQ_FAILED.getCode()); + list.add(PROFIT_SHARING_APPLY_FAILED.getCode()); + list.add(PROFIT_SHARING_FAILED.getCode()); + return list; + } } diff --git a/mallinkService/src/main/java/com/iformall/service/WxCouponOrderService.java b/mallinkService/src/main/java/com/iformall/service/WxCouponOrderService.java index 17a1ab127..2d4c8d32c 100644 --- a/mallinkService/src/main/java/com/iformall/service/WxCouponOrderService.java +++ b/mallinkService/src/main/java/com/iformall/service/WxCouponOrderService.java @@ -95,7 +95,7 @@ public interface WxCouponOrderService { * 核销分账 * @param couponOrder */ - void shareAfterVerify(WxCouponOrder couponOrder, Long merchantId,Integer payWay,boolean mulityShare); + void shareAfterVerify(WxCouponOrder couponOrder, Long merchantId,boolean mulityShare); /** * 核销后补贴 diff --git a/mallinkService/src/main/java/com/iformall/service/WxOrderService.java b/mallinkService/src/main/java/com/iformall/service/WxOrderService.java index cc4222a6b..a6813ddb4 100644 --- a/mallinkService/src/main/java/com/iformall/service/WxOrderService.java +++ b/mallinkService/src/main/java/com/iformall/service/WxOrderService.java @@ -175,7 +175,7 @@ public interface WxOrderService { * @param orderId * @param payOrderId */ - void shareForMicroPay(TenantEntity tenantEntity, Long orderId, Long payOrderId,EnumPayWay payWay); + void shareForMicroPay(TenantEntity tenantEntity, Long orderId, Long payOrderId); PageInfo listOrderAsPage(WxOrderQueryVo wxOrder, Integer pageNum, Integer pageSize); diff --git a/mallinkService/src/main/java/com/iformall/service/WxProfitSharingOrderService.java b/mallinkService/src/main/java/com/iformall/service/WxProfitSharingOrderService.java index 388667d3a..71332f7cc 100644 --- a/mallinkService/src/main/java/com/iformall/service/WxProfitSharingOrderService.java +++ b/mallinkService/src/main/java/com/iformall/service/WxProfitSharingOrderService.java @@ -21,7 +21,7 @@ public interface WxProfitSharingOrderService { /** * 创建分账订单 */ - ResultData createSharingOrder(WxSharingOrderDto wxSharingOrderDto,WxPayOrder payOrder,Integer payway,Integer payVersion,Integer mchType,Integer share); + ResultData createSharingOrder(WxSharingOrderDto wxSharingOrderDto,WxPayOrder payOrder); /** * 分账重试 @@ -31,7 +31,7 @@ public interface WxProfitSharingOrderService { /** * 分账完结重试 */ - ResultData redoFinishSharingOrder(WxProfitSharingOrder sharingOrder); +// ResultData redoFinishSharingOrder(WxProfitSharingOrder sharingOrder); /** * 查询分账订单 @@ -41,7 +41,7 @@ public interface WxProfitSharingOrderService { /** * 结束分账订单 */ - ResultData finishSharingOrder(WxPayOrder payOrder,WxSharingOrderDto sharingOrderDto,Integer payway,Integer share); +// ResultData finishSharingOrder(WxPayOrder payOrder,WxSharingOrderDto sharingOrderDto,Integer payway,Integer share); PageInfo listAsPage(WxProfitSharingOrderQueryVo order, Integer pageNum, Integer pageSize); @@ -52,7 +52,7 @@ public interface WxProfitSharingOrderService { ResultData findOrderDetails(Long id,String tenantId); - void updatetttttttttttttt(String tenantId); +// void updatetttttttttttttt(String tenantId); ResultData handerSharingOrder(WxProfitSharingOrder sharingOrder); } diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxCouponOrderServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxCouponOrderServiceImpl.java index ff63d8894..c1f1dc94a 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxCouponOrderServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxCouponOrderServiceImpl.java @@ -1608,7 +1608,7 @@ public class WxCouponOrderServiceImpl implements WxCouponOrderService { } } // 核销分账 - shareAfterVerify(couponOrder, merchant.getId(),couponOrder.getPayVendor(),mulityShare); + shareAfterVerify(couponOrder, merchant.getId(),mulityShare); } catch (Exception e) { logger.error("核销记账失败"+e.getMessage(),e); } @@ -1693,7 +1693,7 @@ public class WxCouponOrderServiceImpl implements WxCouponOrderService { @Override @Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) - public void shareAfterVerify(WxCouponOrder couponOrder, Long merchantId,Integer payWay,boolean mulityShare) { + public void shareAfterVerify(WxCouponOrder couponOrder, Long merchantId, boolean mulityShare) { // 微信分账 try { @@ -1703,8 +1703,11 @@ public class WxCouponOrderServiceImpl implements WxCouponOrderService { wxPayOrder.setOrderId(couponOrder.getComposeOrderId()); wxPayOrder.setPayOrderStatus(EnumPayStatus.PAY_STATUS_SUCCESS.getCode()); wxPayOrder = wxPayOrderMapper.selectOne(new QueryWrapper(wxPayOrder)); - if(wxPayOrder != null && EnumPayMchType.TOTAL.getCode().equals(wxPayOrder.getMchType()) - && EnumPayShare.NO.getCode().equals(wxPayOrder.getShare())){ + if(wxPayOrder == null){ + logger.error("券订单"+couponOrder.getId()+"未查询到支付订单."); + throw new MallinkException(ErrorCode.SYS_SERVER_ERROR.getCode(),"券订单"+couponOrder.getId()+"未查询到支付订单."); + } + if(EnumPayShare.NO.getCode().equals(wxPayOrder.getShare())){ try { // 订单购买时未分账 核销记账,并且往账户里面记帐 if (couponOrder.getCouponPrice() > 0) { @@ -1713,8 +1716,8 @@ public class WxCouponOrderServiceImpl implements WxCouponOrderService { } catch (Exception e) { logger.error("核销记账失败"+e.getMessage(),e); } - }else if(wxPayOrder != null && EnumPayMchType.TOTAL.getCode().equals(wxPayOrder.getMchType())){ - WxProfitSharingReceiver psReceiver = payServiceFactory.getPayShareAdapterService(payWay,couponOrder.getPayVersion()) + }else{ + WxProfitSharingReceiver psReceiver = payServiceFactory.getPayShareAdapterService(wxPayOrder.getPayVendor(),couponOrder.getPayVersion()) .getReceiver(wxPayOrder,merchantId,wxPayOrder.getTtPayWay(),wxPayOrder.getMchType()); if (psReceiver == null) { @@ -1728,39 +1731,38 @@ public class WxCouponOrderServiceImpl implements WxCouponOrderService { } } } - if(wxPayOrder != null){ - WxOrder order = wxOrderService.getById(couponOrder.getOrderId(), wxPayOrder.getTenantId()); - if (null == order) { - logger.error("租户"+wxPayOrder.getTenantId()+"券订单"+couponOrder.getId()+"未查询到订单."); - throw new MallinkException(ErrorCode.SYS_SERVER_ERROR.getCode(),"租户"+wxPayOrder.getTenantId()+"券订单"+couponOrder.getId()+"未查询到订单."); - } - WxSharingOrderDto wxSharingOrderDto = new WxSharingOrderDto(); - wxSharingOrderDto.setCUserId(wxPayOrder.getCUserId()); - wxSharingOrderDto.setMerchantId(merchantId); - WxComposeChildOrderShare childShare = wxPayOrder.getChildOrderShare(order.getId()); - if (null == childShare) { - logger.error("租户"+wxPayOrder.getTenantId()+"订单"+order.getId()+"在支付订单"+wxPayOrder.getId()+"未查询到."); - throw new MallinkException(ErrorCode.SYS_SERVER_ERROR.getCode(),"租户"+wxPayOrder.getTenantId()+"订单"+order.getId()+"在支付订单"+wxPayOrder.getId()+"未查询到."); - } - wxSharingOrderDto.setPayMerchantId(childShare.getMerchantId()); - wxSharingOrderDto.setPayMerchantMchId(childShare.getMerchantUid()); - if (mulityShare) { - wxSharingOrderDto.setType(EnumProfitSharingOrderType.PROFIT_SHARING_MULTI.getCode()); - }else { - wxSharingOrderDto.setType(EnumProfitSharingOrderType.PROFIT_SHARING_SINGLE.getCode()); - } - wxSharingOrderDto.setPayAmount(wxPayOrder.getPayAmount()); - wxSharingOrderDto.setShareAmount(wxPayOrder.getChildOrderShare(couponOrder.getOrderId()).getShareAmount()); - wxSharingOrderDto.setRateAmount(wxPayOrder.getChildOrderShare(couponOrder.getOrderId()).getRateAmount()); - wxSharingOrderDto.setRealRateAmount(wxPayOrder.getChildOrderShare(couponOrder.getOrderId()).getRealRateAmount()); - wxSharingOrderDto.setCommissionAmount(wxPayOrder.getChildOrderShare(couponOrder.getOrderId()).getCommissionAmount()); - wxSharingOrderDto.setOrderId(wxPayOrder.getId()); - wxSharingOrderDto.setPayTimeStart(wxPayOrder.getPayTimeStart()); - wxSharingOrderDto.setPayTimeEnd(wxPayOrder.getPayTimeEnd()); - wxSharingOrderDto.updateTenantInfo(wxPayOrder); - wxSharingOrderDto.setTransactionId(wxPayOrder.getTransactionId()); - wxProfitSharingOrderService.createSharingOrder(wxSharingOrderDto,wxPayOrder,payWay,wxPayOrder.getPayVersion(),wxPayOrder.getMchType(),wxPayOrder.getShare()); + + WxOrder order = wxOrderService.getById(couponOrder.getOrderId(), wxPayOrder.getTenantId()); + if (null == order) { + logger.error("租户"+wxPayOrder.getTenantId()+"券订单"+couponOrder.getId()+"未查询到订单."); + throw new MallinkException(ErrorCode.SYS_SERVER_ERROR.getCode(),"租户"+wxPayOrder.getTenantId()+"券订单"+couponOrder.getId()+"未查询到订单."); + } + WxSharingOrderDto wxSharingOrderDto = new WxSharingOrderDto(); + wxSharingOrderDto.setCUserId(wxPayOrder.getCUserId()); + wxSharingOrderDto.setMerchantId(merchantId); + WxComposeChildOrderShare childShare = wxPayOrder.getChildOrderShare(order.getId()); + if (null == childShare) { + logger.error("租户"+wxPayOrder.getTenantId()+"订单"+order.getId()+"在支付订单"+wxPayOrder.getId()+"未查询到."); + throw new MallinkException(ErrorCode.SYS_SERVER_ERROR.getCode(),"租户"+wxPayOrder.getTenantId()+"订单"+order.getId()+"在支付订单"+wxPayOrder.getId()+"未查询到."); + } + wxSharingOrderDto.setPayMerchantId(childShare.getMerchantId()); + wxSharingOrderDto.setPayMerchantMchId(childShare.getMerchantUid()); + if (mulityShare) { + wxSharingOrderDto.setType(EnumProfitSharingOrderType.PROFIT_SHARING_MULTI.getCode()); + }else { + wxSharingOrderDto.setType(EnumProfitSharingOrderType.PROFIT_SHARING_SINGLE.getCode()); } + wxSharingOrderDto.setPayAmount(wxPayOrder.getPayAmount()); + wxSharingOrderDto.setShareAmount(wxPayOrder.getChildOrderShare(couponOrder.getOrderId()).getShareAmount()); + wxSharingOrderDto.setRateAmount(wxPayOrder.getChildOrderShare(couponOrder.getOrderId()).getRateAmount()); + wxSharingOrderDto.setRealRateAmount(wxPayOrder.getChildOrderShare(couponOrder.getOrderId()).getRealRateAmount()); + wxSharingOrderDto.setCommissionAmount(wxPayOrder.getChildOrderShare(couponOrder.getOrderId()).getCommissionAmount()); + wxSharingOrderDto.setOrderId(wxPayOrder.getId()); + wxSharingOrderDto.setPayTimeStart(wxPayOrder.getPayTimeStart()); + wxSharingOrderDto.setPayTimeEnd(wxPayOrder.getPayTimeEnd()); + wxSharingOrderDto.updateTenantInfo(wxPayOrder); + wxSharingOrderDto.setTransactionId(wxPayOrder.getTransactionId()); + wxProfitSharingOrderService.createSharingOrder(wxSharingOrderDto,wxPayOrder); } catch (Exception e) { logger.error("微信分账: " + e.getMessage()); } diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxOrderServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxOrderServiceImpl.java index b4e00be83..d3ae5d75f 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxOrderServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxOrderServiceImpl.java @@ -1121,8 +1121,7 @@ public class WxOrderServiceImpl implements WxOrderService { order.setOrderType(EnumComposeOrder.SINGLE.getCode()); order.setCreateDate(new Date()); wxBatchOrderMapper.insert(order); - - + Long orderNumber = idWorker.nextId(); @@ -1148,7 +1147,6 @@ public class WxOrderServiceImpl implements WxOrderService { record.setComposeOrderType(EnumComposeOrder.SINGLE.getCode()); record.setCouponNumber(1); - try { // 保存订单 wxOrderMapper.insert(record); @@ -2539,7 +2537,7 @@ public class WxOrderServiceImpl implements WxOrderService { @Override @Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) - public void shareForMicroPay(TenantEntity tenantEntity, Long orderId, Long payOrderId,EnumPayWay payWay) { + public void shareForMicroPay(TenantEntity tenantEntity, Long orderId, Long payOrderId) { // 微信分账 try { WxPayOrder wxPayOrder = new WxPayOrder(); @@ -2569,7 +2567,7 @@ public class WxOrderServiceImpl implements WxOrderService { sharingOrder.setPayTimeEnd(wxPayOrder.getPayTimeEnd()); sharingOrder.updateTenantInfo(wxPayOrder); sharingOrder.setTransactionId(wxPayOrder.getTransactionId()); - wxProfitSharingOrderService.createSharingOrder(sharingOrder,wxPayOrder,payWay.getCode(),wxPayOrder.getPayVersion(),wxPayOrder.getMchType(),wxPayOrder.getShare()); + wxProfitSharingOrderService.createSharingOrder(sharingOrder,wxPayOrder); } else { diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxPayOrderServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxPayOrderServiceImpl.java index 306876d3d..1cb5df240 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxPayOrderServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxPayOrderServiceImpl.java @@ -1194,7 +1194,7 @@ public class WxPayOrderServiceImpl implements WxPayOrderService { // 支付分账 logger.info("收银台订单分账开始: composeOrderId: {}, payOrderId: {}", orderId, payOrderId); try { - wxOrderService.shareForMicroPay(tenantEntity, orderId, payOrderId,payWay); + wxOrderService.shareForMicroPay(tenantEntity, orderId, payOrderId); } catch (MallinkException e) { logger.error("收银台订单分账失败: orderId: {}, payOrderId: {}", orderId, payOrderId); logger.error("收银台订单分账失败: " + e.getMessage()); 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 c015ffdbe..346b05a86 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxProfitSharingOrderServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxProfitSharingOrderServiceImpl.java @@ -22,6 +22,7 @@ import com.iformall.exception.MallinkException; import com.iformall.mapper.*; import com.iformall.pay.*; import com.iformall.service.ExcelService; +import com.iformall.service.WxAppinfoService; import com.iformall.service.WxProfitSharingOrderService; import com.iformall.service.pay.PayServiceFactory; import com.iformall.service.pay.service.share.PayShareAdapterService; @@ -61,6 +62,9 @@ public class WxProfitSharingOrderServiceImpl implements WxProfitSharingOrderServ @Autowired WxAppinfoMapper wxAppinfoMapper; + @Autowired + WxAppinfoService wxAppinfoService; + @Autowired WxPayAccountMapper wxPayAccountMapper; @@ -132,262 +136,359 @@ public class WxProfitSharingOrderServiceImpl implements WxProfitSharingOrderServ return wxAppinfo; } - private WxProfitShareAppInoDto getAppinfo(WxProfitSharingOrder wxProfitSharingOrder) { - WxAppinfo appinfo; - Integer payWay; - if (wxProfitSharingOrder.getType().equals(EnumProfitSharingOrderType.PROFIT_SHARING_SINGLE.getCode()) - || wxProfitSharingOrder.getType().equals(EnumProfitSharingOrderType.PROFIT_SHARING_SINGLE_FINISH.getCode())){ - WxPayOrder wxPayOrder = wxPayOrderMapper.selectById(wxProfitSharingOrder.getOrderId(),wxProfitSharingOrder.getTenantId()); - if (wxPayOrder == null) { - throw new MallinkException(ErrorCode.ORDER_IS_NOT_FIND.getCode(),"wxProfitSharingOrder["+wxProfitSharingOrder.getId()+"] 没有payOrder信息."); - } - appinfo = getAppinfo(wxPayOrder.getTenantId(),wxPayOrder.getPayVendor()); - payWay = wxPayOrder.getPayVendor(); - } else if(wxProfitSharingOrder.getType().equals(EnumProfitSharingOrderType.PROFIT_SHARING_MULTI.getCode()) - ||wxProfitSharingOrder.getType().equals(EnumProfitSharingOrderType.PROFIT_SHARING_MULTI_FINISH.getCode())){ - WxCardSpend wxCardSpend = wxCardSpendMapper.selectById(wxProfitSharingOrder.getOrderId()); - if (wxCardSpend == null) - throw new MallinkException(ErrorCode.ORDER_IS_NOT_FIND.getCode(),"wxProfitSharingOrder["+wxProfitSharingOrder.getId()+"] 没有WxCardSpend信息."); - appinfo = getAppinfo(wxCardSpend.getTenantId(),EnumCardSpendFrom.getPayWay(wxCardSpend.getPayFrom()).getCode()); - payWay = EnumCardSpendFrom.getPayWay(wxCardSpend.getPayFrom()).getCode(); - } else { - throw new MallinkException(ErrorCode.PROFIT_SHARING_QUERY_UNKNOWN_TYPE); - } - WxProfitShareAppInoDto rt = new WxProfitShareAppInoDto(); - rt.setAppinfo(appinfo); - rt.setPayWay(payWay); - return rt; - } +// private WxProfitShareAppInoDto getAppinfo(WxProfitSharingOrder wxProfitSharingOrder) { +// WxAppinfo appinfo; +// Integer payWay; +// if (wxProfitSharingOrder.getType().equals(EnumProfitSharingOrderType.PROFIT_SHARING_SINGLE.getCode()) +// || wxProfitSharingOrder.getType().equals(EnumProfitSharingOrderType.PROFIT_SHARING_SINGLE_FINISH.getCode())){ +// WxPayOrder wxPayOrder = wxPayOrderMapper.selectById(wxProfitSharingOrder.getOrderId(),wxProfitSharingOrder.getTenantId()); +// if (wxPayOrder == null) { +// throw new MallinkException(ErrorCode.ORDER_IS_NOT_FIND.getCode(),"wxProfitSharingOrder["+wxProfitSharingOrder.getId()+"] 没有payOrder信息."); +// } +// appinfo = getAppinfo(wxPayOrder.getTenantId(),wxPayOrder.getPayVendor()); +// payWay = wxPayOrder.getPayVendor(); +// } else if(wxProfitSharingOrder.getType().equals(EnumProfitSharingOrderType.PROFIT_SHARING_MULTI.getCode()) +// || wxProfitSharingOrder.getType().equals(EnumProfitSharingOrderType.PROFIT_SHARING_MULTI_FINISH.getCode())){ +// WxCardSpend wxCardSpend = wxCardSpendMapper.selectById(wxProfitSharingOrder.getOrderId()); +// if (wxCardSpend == null) +// throw new MallinkException(ErrorCode.ORDER_IS_NOT_FIND.getCode(),"wxProfitSharingOrder["+wxProfitSharingOrder.getId()+"] 没有WxCardSpend信息."); +// appinfo = getAppinfo(wxCardSpend.getTenantId(),EnumCardSpendFrom.getPayWay(wxCardSpend.getPayFrom()).getCode()); +// payWay = EnumCardSpendFrom.getPayWay(wxCardSpend.getPayFrom()).getCode(); +// } else { +// throw new MallinkException(ErrorCode.PROFIT_SHARING_QUERY_UNKNOWN_TYPE); +// } +// WxProfitShareAppInoDto rt = new WxProfitShareAppInoDto(); +// rt.setAppinfo(appinfo); +// rt.setPayWay(payWay); +// return rt; +// } @Override @Transactional(isolation=Isolation.SERIALIZABLE, propagation = Propagation.REQUIRED, rollbackFor = {Exception.class}) public ResultData redoSharingOrder(WxProfitSharingOrder sharingOrder) { - final IdWorker idworker = IdWorker.get(); - if (!sharingOrder.getType().equals(EnumProfitSharingOrderType.PROFIT_SHARING_SINGLE.getCode()) && - !sharingOrder.getType().equals(EnumProfitSharingOrderType.PROFIT_SHARING_MULTI.getCode())) { - return new ResultData(ErrorCode.SYS_PARAMETER_ERROR); + if(!EnumProfitSharingOrderStatus.shareStatus().contains(sharingOrder.getSharingStatus())){ + return new ResultData(ErrorCode.PROFIT_SHARING_REQUEST_FAILED.getCode(),"分账状态不允许"); } - WxProfitShareAppInoDto dto = getAppinfo(sharingOrder); - WxAppinfo appInfo = dto.getAppinfo(); - WxPayAccount payAccount = wxPayAccountMapper.selectById(appInfo.getPayId()); + WxPayOrder wxPayOrder = wxPayOrderMapper.selectById(sharingOrder.getOrderId(),sharingOrder.getTenantId()); - List receivers; + if (wxPayOrder == null) { + throw new MallinkException(ErrorCode.ORDER_IS_NOT_FIND.getCode(),"wxProfitSharingOrder["+sharingOrder.getId()+"] 没有payOrder信息."); + } - try { - receivers = JSONArray.parseArray(sharingOrder.getReceivers(), JSONObject.class); - if (receivers.size() <= 0) + EnumPayWay enumPayWay = EnumPayWay.getEnum(wxPayOrder.getPayVendor()); + EnumAppPlat enumPlat = enumPayWay.getPlat(); + + WxAppinfo cAppInfo = wxAppinfoService.getCAppInfo(sharingOrder, enumPlat); + WxPayAccount payAccount = wxPayAccountMapper.selectById(cAppInfo.getPayId()); + + PayShareAdapterService payShareAdapterService = payServiceFactory.getPayShareAdapterService(wxPayOrder.getPayVendor(),wxPayOrder.getPayVersion()); + PayShareResult shareResult = null; + JSONArray jsonArray = null; + + if(StringUtils.isNotBlank(sharingOrder.getReceivers())){ + jsonArray = JSONArray.parseArray(sharingOrder.getReceivers()); + } + List resultList = new ArrayList(); + if(jsonArray == null || jsonArray.isEmpty()){ + shareResult = payShareAdapterService.noReciverShare(cAppInfo, payAccount, sharingOrder); + }else{ + final IdWorker idworker = IdWorker.get(); + Date currentDate = new Date(); + try { + jsonArray.stream().forEach(obj -> { + JSONObject receiver =(JSONObject) obj; + WxProfitSharingResult result = new WxProfitSharingResult(); + result.setId(idworker.nextId()); + result.updateTenantInfo(sharingOrder); + result.setMerchantId(sharingOrder.getMerchantId()); + result.setSharingOrderId(sharingOrder.getId()); + result.setSharingReceiverId(Long.valueOf(receiver.getString("description"))); + result.setPayAmount(receiver.getInteger("amount")); + result.setCreateTime(currentDate); + result.setUpdateTime(currentDate); + result.setSharingStatus(EnumProfitSharingResultStatus.PROFIT_SHARING_RESULT_PENDING.getCode()); + resultList.add(result); + }); + }catch (Exception e) { + logger.error("分账详细信息为null",e); return new ResultData(ErrorCode.PROFIT_SHARING_RECEIVER_INVALID); - } catch (Exception e) { - return new ResultData(ErrorCode.PROFIT_SHARING_RECEIVER_INVALID); + } + shareResult = payShareAdapterService.haveReciversShare(cAppInfo, payAccount, sharingOrder, jsonArray, wxPayOrder.getMchType()); } - final WxProfitSharingOrder frecord = sharingOrder; - List resultList = new ArrayList(); - try { - receivers.stream().forEach(receiver -> { - Date currentDate = new Date(); - WxProfitSharingResult result = new WxProfitSharingResult(); - result.setId(idworker.nextId()); - result.updateTenantInfo(frecord); - result.setMerchantId(frecord.getMerchantId()); - result.setSharingOrderId(frecord.getId()); - result.setSharingReceiverId(Long.valueOf(receiver.getString("description"))); - result.setPayAmount(receiver.getInteger("amount")); - result.setCreateTime(currentDate); - result.setUpdateTime(currentDate); - result.setSharingStatus(EnumProfitSharingResultStatus.PROFIT_SHARING_RESULT_PENDING.getCode()); - resultList.add(result); - }); - }catch (Exception e) { - return new ResultData(ErrorCode.PROFIT_SHARING_RECEIVER_INVALID); + if (null == shareResult) { + return new ResultData(ErrorCode.PROFIT_SHARING_REQUEST_FAILED.getCode(),"当前支付模式调用分账未返回结果"); } - - PayShareResult shareResult = payServiceFactory.getPayShareAdapterService(dto.getPayWay(),payAccount.getPayVersion()).haveReciversShare(appInfo, payAccount,frecord, - sharingOrder.getTransactionId(), JSONArray.parseArray(JSON.toJSONString(receivers)), EnumProfitSharingOrderType.getEnum(sharingOrder.getType())); WxProfitSharingOrder updSharingOrder = new WxProfitSharingOrder(); updSharingOrder.updateTenantInfo(sharingOrder); updSharingOrder.setId(sharingOrder.getId()); - updSharingOrder.setOutSettleNo(frecord.getOutSettleNo()); + updSharingOrder.setOutSettleNo(sharingOrder.getOutSettleNo()); if (!shareResult.isSuccess()) { updSharingOrder.setSharingStatus(shareResult.getCode()); - updSharingOrder.setErrorMsg("REDO:"+shareResult.getMsg()); + updSharingOrder.setErrorMsg(shareResult.getMsg()); updSharingOrder.setUpdateTime(new Date()); wxProfitSharingOrderMapper.updateById(updSharingOrder); return new ResultData(ErrorCode.PROFIT_SHARING_REQUEST_FAILED.getCode(),updSharingOrder.getErrorMsg()); } updSharingOrder.setSharingOrderNo(shareResult.getShareOrderNo()); updSharingOrder.setSharingStatus(EnumProfitSharingOrderStatus.PROFIT_SHARING_ACCEPTED.getCode()); - updSharingOrder.setErrorMsg("REDO:重试分账成功"); updSharingOrder.setUpdateTime(new Date()); wxProfitSharingOrderMapper.updateById(updSharingOrder); + for (WxProfitSharingResult result:resultList) { wxProfitSharingResultMapper.insert(result); } return new ResultData(shareResult.getData()); - } - @Override - public ResultData redoFinishSharingOrder(WxProfitSharingOrder sharingOrder) { - if (!sharingOrder.getType().equals(EnumProfitSharingOrderType.PROFIT_SHARING_SINGLE_FINISH.getCode())) { - return new ResultData(ErrorCode.SYS_PARAMETER_ERROR); - } - WxProfitShareAppInoDto dto = getAppinfo(sharingOrder); - WxAppinfo appInfo = dto.getAppinfo(); - WxPayAccount payAccount = wxPayAccountMapper.selectById(appInfo.getPayId()); - PayShareResult shareResult = payServiceFactory.getPayShareAdapterService(dto.getPayWay(),payAccount.getPayVersion()).noReciverShare(appInfo,payAccount,sharingOrder,sharingOrder.getTransactionId(),sharingOrder.getPayAmount()); - WxProfitSharingOrder updSharingOrder = new WxProfitSharingOrder(); - updSharingOrder.updateTenantInfo(sharingOrder); - updSharingOrder.setId(sharingOrder.getId()); - updSharingOrder.setOutSettleNo(sharingOrder.getOutSettleNo()); - if (!shareResult.isSuccess()) { - updSharingOrder.setSharingStatus(shareResult.getCode()); - updSharingOrder.setErrorMsg("REDO:"+shareResult.getMsg()); - updSharingOrder.setUpdateTime(new Date()); - wxProfitSharingOrderMapper.updateById(updSharingOrder); - return new ResultData(ErrorCode.PROFIT_SHARING_REQUEST_FAILED.getCode(),updSharingOrder.getErrorMsg()); - } - updSharingOrder.setSharingOrderNo(shareResult.getShareOrderNo()); - updSharingOrder.setSharingStatus(EnumProfitSharingOrderStatus.PROFIT_SHARING_ACCEPTED.getCode()); - updSharingOrder.setErrorMsg("REDO:重试分账成功"); - updSharingOrder.setUpdateTime(new Date()); - wxProfitSharingOrderMapper.updateById(updSharingOrder); - return new ResultData(shareResult.getData()); +// final IdWorker idworker = IdWorker.get(); +// +// if (!sharingOrder.getType().equals(EnumProfitSharingOrderType.PROFIT_SHARING_SINGLE.getCode()) && +// !sharingOrder.getType().equals(EnumProfitSharingOrderType.PROFIT_SHARING_MULTI.getCode())) { +// return new ResultData(ErrorCode.SYS_PARAMETER_ERROR); +// } +// +// WxProfitShareAppInoDto dto = getAppinfo(sharingOrder); +// WxAppinfo appInfo = dto.getAppinfo(); +// WxPayAccount payAccount = wxPayAccountMapper.selectById(appInfo.getPayId()); +// +// List receivers; +// +// try { +// receivers = JSONArray.parseArray(sharingOrder.getReceivers(), JSONObject.class); +// if (receivers.size() <= 0) +// return new ResultData(ErrorCode.PROFIT_SHARING_RECEIVER_INVALID); +// } catch (Exception e) { +// return new ResultData(ErrorCode.PROFIT_SHARING_RECEIVER_INVALID); +// } +// +// final WxProfitSharingOrder frecord = sharingOrder; +// List resultList = new ArrayList(); +// try { +// receivers.stream().forEach(receiver -> { +// Date currentDate = new Date(); +// WxProfitSharingResult result = new WxProfitSharingResult(); +// result.setId(idworker.nextId()); +// result.updateTenantInfo(frecord); +// result.setMerchantId(frecord.getMerchantId()); +// result.setSharingOrderId(frecord.getId()); +// result.setSharingReceiverId(Long.valueOf(receiver.getString("description"))); +// result.setPayAmount(receiver.getInteger("amount")); +// result.setCreateTime(currentDate); +// result.setUpdateTime(currentDate); +// result.setSharingStatus(EnumProfitSharingResultStatus.PROFIT_SHARING_RESULT_PENDING.getCode()); +// resultList.add(result); +// }); +// }catch (Exception e) { +// return new ResultData(ErrorCode.PROFIT_SHARING_RECEIVER_INVALID); +// } +// +// +// PayShareResult shareResult = payServiceFactory.getPayShareAdapterService(dto.getPayWay(),payAccount.getPayVersion()).haveReciversShare(appInfo, payAccount,frecord, +// sharingOrder.getTransactionId(), JSONArray.parseArray(JSON.toJSONString(receivers)), EnumProfitSharingOrderType.getEnum(sharingOrder.getType())); +// WxProfitSharingOrder updSharingOrder = new WxProfitSharingOrder(); +// updSharingOrder.updateTenantInfo(sharingOrder); +// updSharingOrder.setId(sharingOrder.getId()); +// updSharingOrder.setOutSettleNo(frecord.getOutSettleNo()); +// if (!shareResult.isSuccess()) { +// updSharingOrder.setSharingStatus(shareResult.getCode()); +// updSharingOrder.setErrorMsg("REDO:"+shareResult.getMsg()); +// updSharingOrder.setUpdateTime(new Date()); +// wxProfitSharingOrderMapper.updateById(updSharingOrder); +// return new ResultData(ErrorCode.PROFIT_SHARING_REQUEST_FAILED.getCode(),updSharingOrder.getErrorMsg()); +// } +// updSharingOrder.setSharingOrderNo(shareResult.getShareOrderNo()); +// updSharingOrder.setSharingStatus(EnumProfitSharingOrderStatus.PROFIT_SHARING_ACCEPTED.getCode()); +// updSharingOrder.setErrorMsg("REDO:重试分账成功"); +// updSharingOrder.setUpdateTime(new Date()); +// wxProfitSharingOrderMapper.updateById(updSharingOrder); +// for (WxProfitSharingResult result:resultList) { +// wxProfitSharingResultMapper.insert(result); +// } +// return new ResultData(shareResult.getData()); } +// @Override +// public ResultData redoFinishSharingOrder(WxProfitSharingOrder sharingOrder) { +// if (!sharingOrder.getType().equals(EnumProfitSharingOrderType.PROFIT_SHARING_SINGLE_FINISH.getCode())) { +// return new ResultData(ErrorCode.SYS_PARAMETER_ERROR); +// } +// WxProfitShareAppInoDto dto = getAppinfo(sharingOrder); +// WxAppinfo appInfo = dto.getAppinfo(); +// WxPayAccount payAccount = wxPayAccountMapper.selectById(appInfo.getPayId()); +// +// PayShareResult shareResult = payServiceFactory.getPayShareAdapterService(dto.getPayWay(),payAccount.getPayVersion()).noReciverShare(appInfo,payAccount,sharingOrder,sharingOrder.getTransactionId(),sharingOrder.getPayAmount()); +// +// WxProfitSharingOrder updSharingOrder = new WxProfitSharingOrder(); +// updSharingOrder.updateTenantInfo(sharingOrder); +// updSharingOrder.setId(sharingOrder.getId()); +// updSharingOrder.setOutSettleNo(sharingOrder.getOutSettleNo()); +// if (!shareResult.isSuccess()) { +// updSharingOrder.setSharingStatus(shareResult.getCode()); +// updSharingOrder.setErrorMsg("REDO:"+shareResult.getMsg()); +// updSharingOrder.setUpdateTime(new Date()); +// wxProfitSharingOrderMapper.updateById(updSharingOrder); +// return new ResultData(ErrorCode.PROFIT_SHARING_REQUEST_FAILED.getCode(),updSharingOrder.getErrorMsg()); +// } +// updSharingOrder.setSharingOrderNo(shareResult.getShareOrderNo()); +// updSharingOrder.setSharingStatus(EnumProfitSharingOrderStatus.PROFIT_SHARING_ACCEPTED.getCode()); +// updSharingOrder.setErrorMsg("REDO:重试分账成功"); +// updSharingOrder.setUpdateTime(new Date()); +// wxProfitSharingOrderMapper.updateById(updSharingOrder); +// return new ResultData(shareResult.getData()); +// } + @Override // @Transactional(isolation=Isolation.SERIALIZABLE, propagation = Propagation.REQUIRED, rollbackFor = {Exception.class}) - public ResultData createSharingOrder(WxSharingOrderDto sharingOrderDto,WxPayOrder payOrder,Integer payWay,Integer payVersion,Integer mchType,Integer share) { + public ResultData createSharingOrder(WxSharingOrderDto sharingOrderDto,WxPayOrder payOrder) { - PayShareAdapterService payShareAdapterService = payServiceFactory.getPayShareAdapterService(payWay,payVersion); + PayShareAdapterService payShareAdapterService = payServiceFactory.getPayShareAdapterService(payOrder.getPayVendor(),payOrder.getPayVersion()); - WxProfitSharingOrder record = payShareAdapterService.createSharingOrder(sharingOrderDto,mchType,share); + WxProfitSharingOrder record = payShareAdapterService.createSharingOrder(sharingOrderDto,payOrder.getMchType(),payOrder.getShare()); //抖音模式涉及到佣金,无法实时分账 - if(EnumPayWay.PAY_WAY_TT.getCode().equals(payWay)){ + if(EnumPayWay.PAY_WAY_TT.getCode().equals(payOrder.getPayVendor())){ return new ResultData(); } - if (!sharingOrderDto.getType().equals(EnumProfitSharingOrderType.PROFIT_SHARING_SINGLE.getCode()) && - !sharingOrderDto.getType().equals(EnumProfitSharingOrderType.PROFIT_SHARING_MULTI.getCode())){ - return new ResultData(ErrorCode.SYS_PARAMETER_ERROR); - } - EnumProfitSharingOrderType shareType = EnumProfitSharingOrderType.getEnum(sharingOrderDto.getType()); - if (null == shareType) { - throw new MallinkException(ErrorCode.SYS_PARAMETER_ERROR.getCode(),sharingOrderDto.getType()+"在分账方式中不存在。EnumProfitSharingOrderType"); - } - WxAppinfo appInfo = getAppinfo(sharingOrderDto.getTenantId(),payWay); - WxPayAccount payAccount = wxPayAccountMapper.selectById(appInfo.getPayId()); - PayShareResult shareResult = null; - JSONArray jsonArray = null; - - //总分模式,收款账户分账 - if (EnumPayMchType.TOTAL.getCode() == mchType) { - if(StringUtils.isNotBlank(record.getReceivers())){ - jsonArray = JSONArray.parseArray(record.getReceivers()); - shareResult = payShareAdapterService.haveReciversShare(appInfo, payAccount, record, - sharingOrderDto.getTransactionId(), jsonArray, shareType); - }else { - return new ResultData(); - } - //直连模式,不用分账,直接完结分账 - }else if (EnumPayMchType.DIRECT.getCode() == mchType) { - shareResult = payShareAdapterService.noReciverShare(appInfo, payAccount, record, sharingOrderDto.getTransactionId(), sharingOrderDto.getShareAmount()); - //当前商户的收款账号 - WxProfitSharingReceiver receiver = payShareAdapterService.getReceiver(sharingOrderDto, sharingOrderDto.getMerchantId(), payOrder.getTtPayWay(), mchType); - if (null == receiver) { - return new ResultData(ErrorCode.PROFIT_SHARING_REQUEST_FAILED.getCode(),"当前商户未配置收款账号"); - } - StringBuffer sb = new StringBuffer("[{").append("\"description\":").append(receiver.getId()).append(",\"amount\":").append(sharingOrderDto.getShareAmount()); - jsonArray = JSONArray.parseArray(sb.toString()); - } - if (null == shareResult) { - return new ResultData(ErrorCode.PROFIT_SHARING_REQUEST_FAILED.getCode(),"当前支付模式调用分账未返回结果"); - } - - WxProfitSharingOrder updSharingOrder = new WxProfitSharingOrder(); - updSharingOrder.updateTenantInfo(record); - updSharingOrder.setId(record.getId()); - updSharingOrder.setOutSettleNo(record.getOutSettleNo()); - if (!shareResult.isSuccess()) { - updSharingOrder.setSharingStatus(shareResult.getCode()); - updSharingOrder.setErrorMsg(shareResult.getMsg()); - updSharingOrder.setUpdateTime(new Date()); - wxProfitSharingOrderMapper.updateById(updSharingOrder); - return new ResultData(ErrorCode.PROFIT_SHARING_REQUEST_FAILED.getCode(),updSharingOrder.getErrorMsg()); - } - updSharingOrder.setSharingOrderNo(shareResult.getShareOrderNo()); - updSharingOrder.setSharingStatus(EnumProfitSharingOrderStatus.PROFIT_SHARING_ACCEPTED.getCode()); - updSharingOrder.setUpdateTime(new Date()); - wxProfitSharingOrderMapper.updateById(updSharingOrder); - - final IdWorker idworker = IdWorker.get(); - try { - jsonArray.stream().forEach(obj -> { - JSONObject receiver =(JSONObject) obj; - Date currentDate = new Date(); - WxProfitSharingResult result = new WxProfitSharingResult(); - result.setId(idworker.nextId()); - result.updateTenantInfo(sharingOrderDto); - result.setMerchantId(record.getMerchantId()); - result.setSharingOrderId(record.getId()); - result.setSharingReceiverId(Long.valueOf(receiver.getString("description"))); - result.setPayAmount(receiver.getInteger("amount")); - result.setCreateTime(currentDate); - result.setUpdateTime(currentDate); - result.setSharingStatus(EnumProfitSharingResultStatus.PROFIT_SHARING_RESULT_PENDING.getCode()); - wxProfitSharingResultMapper.insert(result); - }); - }catch (Exception e) { - logger.error("分账详细信息为null",e); -// return new ResultData(ErrorCode.PROFIT_SHARING_RECEIVER_INVALID); - } - - return new ResultData(shareResult.getData()); - + ResultData resultData = redoSharingOrder(record); + return resultData; + +// if (!sharingOrderDto.getType().equals(EnumProfitSharingOrderType.PROFIT_SHARING_SINGLE.getCode()) && +// !sharingOrderDto.getType().equals(EnumProfitSharingOrderType.PROFIT_SHARING_MULTI.getCode())){ +// return new ResultData(ErrorCode.SYS_PARAMETER_ERROR); +// } +// EnumProfitSharingOrderType shareType = EnumProfitSharingOrderType.getEnum(sharingOrderDto.getType()); +// if (null == shareType) { +// throw new MallinkException(ErrorCode.SYS_PARAMETER_ERROR.getCode(),sharingOrderDto.getType()+"在分账方式中不存在。EnumProfitSharingOrderType"); +// } +// WxAppinfo appInfo = getAppinfo(sharingOrderDto.getTenantId(),payWay); +// WxPayAccount payAccount = wxPayAccountMapper.selectById(appInfo.getPayId()); +// PayShareResult shareResult = null; +// JSONArray jsonArray = null; +// +// if(StringUtils.isNotBlank(record.getReceivers())){ +// jsonArray = JSONArray.parseArray(record.getReceivers()); +// } +// +// if(jsonArray == null || jsonArray.isEmpty()){ +// shareResult = payShareAdapterService.noReciverShare(appInfo, payAccount, record, sharingOrderDto.getTransactionId(), sharingOrderDto.getShareAmount()); +// }else{ +// shareResult = payShareAdapterService.haveReciversShare(appInfo, payAccount, record, sharingOrderDto.getTransactionId(), jsonArray, shareType); +// } +// +// //总分模式,收款账户分账 +//// if (EnumPayMchType.TOTAL.getCode() == mchType) { +//// if(StringUtils.isNotBlank(record.getReceivers())){ +//// jsonArray = JSONArray.parseArray(record.getReceivers()); +//// shareResult = payShareAdapterService.haveReciversShare(appInfo, payAccount, record, +//// sharingOrderDto.getTransactionId(), jsonArray, shareType); +//// }else { +//// return new ResultData(); +//// } +//// //直连模式,不用分账,直接完结分账 +//// }else if (EnumPayMchType.DIRECT.getCode() == mchType) { +//// shareResult = payShareAdapterService.noReciverShare(appInfo, payAccount, record, sharingOrderDto.getTransactionId(), sharingOrderDto.getShareAmount()); +//// //当前商户的收款账号 +//// WxProfitSharingReceiver receiver = payShareAdapterService.getReceiver(sharingOrderDto, sharingOrderDto.getMerchantId(), payOrder.getTtPayWay(), mchType); +//// if (null == receiver) { +//// return new ResultData(ErrorCode.PROFIT_SHARING_REQUEST_FAILED.getCode(),"当前商户未配置收款账号"); +//// } +//// StringBuffer sb = new StringBuffer("[{").append("\"description\":").append(receiver.getId()).append(",\"amount\":").append(sharingOrderDto.getShareAmount()); +//// jsonArray = JSONArray.parseArray(sb.toString()); +//// } +// if (null == shareResult) { +// return new ResultData(ErrorCode.PROFIT_SHARING_REQUEST_FAILED.getCode(),"当前支付模式调用分账未返回结果"); +// } +// +// WxProfitSharingOrder updSharingOrder = new WxProfitSharingOrder(); +// updSharingOrder.updateTenantInfo(record); +// updSharingOrder.setId(record.getId()); +// updSharingOrder.setOutSettleNo(record.getOutSettleNo()); +// if (!shareResult.isSuccess()) { +// updSharingOrder.setSharingStatus(shareResult.getCode()); +// updSharingOrder.setErrorMsg(shareResult.getMsg()); +// updSharingOrder.setUpdateTime(new Date()); +// wxProfitSharingOrderMapper.updateById(updSharingOrder); +// return new ResultData(ErrorCode.PROFIT_SHARING_REQUEST_FAILED.getCode(),updSharingOrder.getErrorMsg()); +// } +// updSharingOrder.setSharingOrderNo(shareResult.getShareOrderNo()); +// updSharingOrder.setSharingStatus(EnumProfitSharingOrderStatus.PROFIT_SHARING_ACCEPTED.getCode()); +// updSharingOrder.setUpdateTime(new Date()); +// wxProfitSharingOrderMapper.updateById(updSharingOrder); +// +// if(jsonArray == null || jsonArray.isEmpty()){ +// final IdWorker idworker = IdWorker.get(); +// try { +// jsonArray.stream().forEach(obj -> { +// JSONObject receiver =(JSONObject) obj; +// Date currentDate = new Date(); +// WxProfitSharingResult result = new WxProfitSharingResult(); +// result.setId(idworker.nextId()); +// result.updateTenantInfo(sharingOrderDto); +// result.setMerchantId(record.getMerchantId()); +// result.setSharingOrderId(record.getId()); +// result.setSharingReceiverId(Long.valueOf(receiver.getString("description"))); +// result.setPayAmount(receiver.getInteger("amount")); +// result.setCreateTime(currentDate); +// result.setUpdateTime(currentDate); +// result.setSharingStatus(EnumProfitSharingResultStatus.PROFIT_SHARING_RESULT_PENDING.getCode()); +// wxProfitSharingResultMapper.insert(result); +// }); +// }catch (Exception e) { +// logger.error("分账详细信息为null",e); +//// return new ResultData(ErrorCode.PROFIT_SHARING_RECEIVER_INVALID); +// } +// } +// +// return new ResultData(shareResult.getData()); } @Override @Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) - public ResultData querySharingOrder(WxProfitSharingOrder wxProfitSharingOrder) { + public ResultData querySharingOrder(WxProfitSharingOrder sharingOrder) { + + WxPayOrder wxPayOrder = wxPayOrderMapper.selectById(sharingOrder.getOrderId(),sharingOrder.getTenantId()); - WxProfitSharingOrder record = new WxProfitSharingOrder(); + if (wxPayOrder == null) { + throw new MallinkException(ErrorCode.ORDER_IS_NOT_FIND.getCode(),"wxProfitSharingOrder["+sharingOrder.getId()+"] 没有payOrder信息."); + } - WxProfitShareAppInoDto dto = getAppinfo(wxProfitSharingOrder); - WxAppinfo appInfo = dto.getAppinfo(); - WxPayAccount payAccount = wxPayAccountMapper.selectById(appInfo.getPayId()); + EnumPayWay enumPayWay = EnumPayWay.getEnum(wxPayOrder.getPayVendor()); + EnumAppPlat enumPlat = enumPayWay.getPlat(); - //是否已创建分账订单 - record.setOrderId(wxProfitSharingOrder.getOrderId()); - record.updateTenantInfo(wxProfitSharingOrder); - record = wxProfitSharingOrderMapper.selectOne(new QueryWrapper(record)); - if (record == null) - return new ResultData(ErrorCode.ORDER_IS_NOT_FIND); + WxAppinfo cAppInfo = wxAppinfoService.getCAppInfo(sharingOrder, enumPlat); + WxPayAccount payAccount = wxPayAccountMapper.selectById(cAppInfo.getPayId()); - PayShareQueryResult shareResult = payServiceFactory.getPayShareAdapterService(dto.getPayWay(),payAccount.getPayVersion()).shareQuery(appInfo, payAccount, record); - if (!shareResult.isSuccess()) { - throw new MallinkException(shareResult.getCode(),shareResult.getMsg()); + PayShareAdapterService payShareAdapterService = payServiceFactory.getPayShareAdapterService(wxPayOrder.getPayVendor(),wxPayOrder.getPayVersion()); + + PayShareQueryResult payShareQueryResult = payShareAdapterService.shareQuery(cAppInfo, payAccount, sharingOrder); + if (!payShareQueryResult.isSuccess()) { + throw new MallinkException(payShareQueryResult.getCode(),payShareQueryResult.getMsg()); } - - record.setSharingStatus(shareResult.getCode()); - record.setUpdateTime(new Date()); - wxProfitSharingOrderMapper.updateById(record); - if(EnumPayWay.PAY_WAY_TT.getCode().equals(dto.getPayWay())){ - return new ResultData(shareResult.getData()); + WxProfitSharingOrder sharingOrderUpd = new WxProfitSharingOrder(); + sharingOrderUpd.setId(sharingOrder.getId()); + sharingOrderUpd.updateTenantInfo(sharingOrder); + sharingOrderUpd.setSharingStatus(payShareQueryResult.getCode()); + sharingOrderUpd.setUpdateTime(new Date()); + wxProfitSharingOrderMapper.updateById(sharingOrderUpd); + + if(EnumPayWay.PAY_WAY_TT.equals(enumPayWay)){ + return new ResultData(payShareQueryResult.getData()); } - List receivers = shareResult.getReceivers(); + List receivers = payShareQueryResult.getReceivers(); if (receivers != null) { WxProfitSharingResult result = new WxProfitSharingResult(); - result.setSharingOrderId(record.getId()); - result.updateTenantInfo(wxProfitSharingOrder); + result.setSharingOrderId(sharingOrder.getId()); + result.updateTenantInfo(sharingOrder); List wxProfitSharingResultList = wxProfitSharingResultMapper.findList(result); for(int j = 0; j < receivers.size() ; j++) { PayShareQueryResultReceivers res = receivers.get(j); @@ -418,9 +519,9 @@ public class WxProfitSharingOrderServiceImpl implements WxProfitSharingOrderServ WxProfitSharingResult wxProfitSharingResult = new WxProfitSharingResult(); - wxProfitSharingResult.updateTenantInfo(record); - wxProfitSharingResult.setMerchantId(record.getMerchantId()); - wxProfitSharingResult.setSharingOrderId(record.getId()); + wxProfitSharingResult.updateTenantInfo(sharingOrder); + wxProfitSharingResult.setMerchantId(sharingOrder.getMerchantId()); + wxProfitSharingResult.setSharingOrderId(sharingOrder.getId()); wxProfitSharingResult.setSharingReceiverId(0L); //剩余钱分给特约商户,没有相应的接受者 List list = wxProfitSharingResultMapper.findList(wxProfitSharingResult); @@ -445,70 +546,70 @@ public class WxProfitSharingOrderServiceImpl implements WxProfitSharingOrderServ } } } - return new ResultData(shareResult.getData()); + return new ResultData(payShareQueryResult.getData()); } // 分账完结 - @Override - @Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) - public ResultData finishSharingOrder(WxPayOrder payOrder,WxSharingOrderDto sharingOrderDto,Integer payWay,Integer share) { - final IdWorker idworker = IdWorker.get(); - - if ((EnumPayWay.PAY_WAY_WECHAT.getCode().equals(payWay) - || EnumPayWay.PAY_WAY_WECHAT_MA.getCode().equals(payWay) - || EnumPayWay.PAY_WAY_WECHAT_WAP.getCode().equals(payWay)) - && EnumPayShare.NO.getCode().equals(share)){ - logger.info("微信支付不分账模式下无需分账"); - return new ResultData(); - } - - if (!sharingOrderDto.getType().equals(EnumProfitSharingOrderType.PROFIT_SHARING_SINGLE_FINISH.getCode()) - && !sharingOrderDto.getType().equals(EnumProfitSharingOrderType.PROFIT_SHARING_MULTI_FINISH.getCode())){ - return new ResultData(ErrorCode.SYS_PARAMETER_ERROR); - } - - WxAppinfo appInfo = getAppinfo(sharingOrderDto.getTenantId(),payWay); - WxPayAccount payAccount = wxPayAccountMapper.selectById(appInfo.getPayId()); - PayShareAdapterService payShareAdapterService = payServiceFactory.getPayShareAdapterService(payWay,payAccount.getPayVersion()); - - //分账检查是否已创建分账订单 - WxProfitSharingOrder record = new WxProfitSharingOrder(); - //创建分账订单 - Date currentDate = new Date(); - record.setId(idworker.nextId()); - record.updateTenantInfo(payAccount); - record.setTransactionId(sharingOrderDto.getTransactionId()); - record.setPayAmount(sharingOrderDto.getPayAmount()); - record.setMerchantId(sharingOrderDto.getMerchantId()); - record.setOrderId(sharingOrderDto.getOrderId()); - record.setSharingStatus(payShareAdapterService.getSharingOrderInitialStatus()); - record.setCreateTime(currentDate); - record.setUpdateTime(currentDate); - record.setPayTimeStart(sharingOrderDto.getPayTimeStart()); - record.setPayTimeEnd(sharingOrderDto.getPayTimeEnd()); - record.setType(sharingOrderDto.getType()); - wxProfitSharingOrderMapper.insert(record); - - //分账提交 - PayShareResult shareResult = payShareAdapterService.noReciverShare(appInfo,payAccount,record,sharingOrderDto.getTransactionId(),sharingOrderDto.getShareAmount()); - WxProfitSharingOrder updSharingOrder = new WxProfitSharingOrder(); - updSharingOrder.updateTenantInfo(record); - updSharingOrder.setId(record.getId()); - updSharingOrder.setOutSettleNo(record.getOutSettleNo()); - if (!shareResult.isSuccess()) { - updSharingOrder.setSharingStatus(shareResult.getCode()); - updSharingOrder.setErrorMsg(shareResult.getMsg()); - updSharingOrder.setUpdateTime(new Date()); - wxProfitSharingOrderMapper.updateById(updSharingOrder); - return new ResultData(ErrorCode.PROFIT_SHARING_REQUEST_FAILED.getCode(),updSharingOrder.getErrorMsg()); - } - - updSharingOrder.setSharingOrderNo(shareResult.getShareOrderNo()); - updSharingOrder.setSharingStatus(EnumProfitSharingOrderStatus.PROFIT_SHARING_ACCEPTED.getCode()); - updSharingOrder.setUpdateTime(new Date()); - wxProfitSharingOrderMapper.updateById(updSharingOrder); - return new ResultData(shareResult.getData()); - } +// @Override +// @Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) +// public ResultData finishSharingOrder(WxPayOrder payOrder,WxSharingOrderDto sharingOrderDto,Integer payWay,Integer share) { +// final IdWorker idworker = IdWorker.get(); +// +// if ((EnumPayWay.PAY_WAY_WECHAT.getCode().equals(payWay) +// || EnumPayWay.PAY_WAY_WECHAT_MA.getCode().equals(payWay) +// || EnumPayWay.PAY_WAY_WECHAT_WAP.getCode().equals(payWay)) +// && EnumPayShare.NO.getCode().equals(share)){ +// logger.info("微信支付不分账模式下无需分账"); +// return new ResultData(); +// } +// +// if (!sharingOrderDto.getType().equals(EnumProfitSharingOrderType.PROFIT_SHARING_SINGLE_FINISH.getCode()) +// && !sharingOrderDto.getType().equals(EnumProfitSharingOrderType.PROFIT_SHARING_MULTI_FINISH.getCode())){ +// return new ResultData(ErrorCode.SYS_PARAMETER_ERROR); +// } +// +// WxAppinfo appInfo = getAppinfo(sharingOrderDto.getTenantId(),payWay); +// WxPayAccount payAccount = wxPayAccountMapper.selectById(appInfo.getPayId()); +// PayShareAdapterService payShareAdapterService = payServiceFactory.getPayShareAdapterService(payWay,payAccount.getPayVersion()); +// +// //分账检查是否已创建分账订单 +// WxProfitSharingOrder record = new WxProfitSharingOrder(); +// //创建分账订单 +// Date currentDate = new Date(); +// record.setId(idworker.nextId()); +// record.updateTenantInfo(payAccount); +// record.setTransactionId(sharingOrderDto.getTransactionId()); +// record.setPayAmount(sharingOrderDto.getPayAmount()); +// record.setMerchantId(sharingOrderDto.getMerchantId()); +// record.setOrderId(sharingOrderDto.getOrderId()); +// record.setSharingStatus(payShareAdapterService.getSharingOrderInitialStatus()); +// record.setCreateTime(currentDate); +// record.setUpdateTime(currentDate); +// record.setPayTimeStart(sharingOrderDto.getPayTimeStart()); +// record.setPayTimeEnd(sharingOrderDto.getPayTimeEnd()); +// record.setType(sharingOrderDto.getType()); +// wxProfitSharingOrderMapper.insert(record); +// +// //分账提交 +// PayShareResult shareResult = payShareAdapterService.noReciverShare(appInfo,payAccount,record,sharingOrderDto.getTransactionId(),sharingOrderDto.getShareAmount()); +// WxProfitSharingOrder updSharingOrder = new WxProfitSharingOrder(); +// updSharingOrder.updateTenantInfo(record); +// updSharingOrder.setId(record.getId()); +// updSharingOrder.setOutSettleNo(record.getOutSettleNo()); +// if (!shareResult.isSuccess()) { +// updSharingOrder.setSharingStatus(shareResult.getCode()); +// updSharingOrder.setErrorMsg(shareResult.getMsg()); +// updSharingOrder.setUpdateTime(new Date()); +// wxProfitSharingOrderMapper.updateById(updSharingOrder); +// return new ResultData(ErrorCode.PROFIT_SHARING_REQUEST_FAILED.getCode(),updSharingOrder.getErrorMsg()); +// } +// +// updSharingOrder.setSharingOrderNo(shareResult.getShareOrderNo()); +// updSharingOrder.setSharingStatus(EnumProfitSharingOrderStatus.PROFIT_SHARING_ACCEPTED.getCode()); +// updSharingOrder.setUpdateTime(new Date()); +// wxProfitSharingOrderMapper.updateById(updSharingOrder); +// return new ResultData(shareResult.getData()); +// } @Override public PageInfo listAsPage(WxProfitSharingOrderQueryVo order, Integer pageIndex, Integer pageSize) { @@ -653,61 +754,61 @@ public class WxProfitSharingOrderServiceImpl implements WxProfitSharingOrderServ } //更新以前分账用户绑定微信号的分账数据,微信已经停止了微信号分账 - @Override - @Deprecated - public void updatetttttttttttttt(String tenantId) { - WxProfitSharingOrder wxProfitSharingOrder = new WxProfitSharingOrder(); - wxProfitSharingOrder.setTenantId(tenantId); - wxProfitSharingOrder.setType(EnumProfitSharingOrderType.PROFIT_SHARING_SINGLE.getCode()); - wxProfitSharingOrder.setSharingStatus(EnumProfitSharingOrderStatus.PROFIT_SHARING_APPLY_FAILED.getCode()); - List list = wxProfitSharingOrderMapper.findList(wxProfitSharingOrder); - list.stream().forEach(sharingOrder->{ - if (!sharingOrder.getType().equals(EnumProfitSharingOrderType.PROFIT_SHARING_SINGLE.getCode())) { - return; - } - - WxProfitShareAppInoDto dto = getAppinfo(sharingOrder); - WxAppinfo appInfo = dto.getAppinfo(); - WxPayAccount payAccount = wxPayAccountMapper.selectById(appInfo.getPayId()); - - List receivers; - - receivers = JSONArray.parseArray(sharingOrder.getReceivers(), JSONObject.class); - if (receivers.size() != 1 ) - return; - - Integer amount = receivers.get(0).getInteger("amount"); - if (!EnumProfitSharingReceiverType.PROFIT_SHARING_RECEIVER_PERSONAL_WECHATID.getMessage().equals(receivers.get(0).getString("type"))) { - return; - } - - //准备分账列表 - WxProfitSharingReceiver psReceiverQ = new WxProfitSharingReceiver(); - psReceiverQ.updateTenantInfo(payAccount); - psReceiverQ.setMerchantId(sharingOrder.getMerchantId()); - psReceiverQ.setSharingType(EnumProfitSharingType.PROFIT_SHARING_TYPE_WECHAT.getCode()); - psReceiverQ.setStatus(EnumProfitSharingReceiverStatus.PROFIT_SHARING_RECEIVER_STATUS_VALID.getCode()); - List psReceiverList = wxProfitSharingReceiverMapper.findList(psReceiverQ); - if (null == psReceiverList || psReceiverList.size() !=1 ) { - return ; - } - - JSONArray realReceivers = new JSONArray(); - psReceiverList.stream().forEach(receiver->{ - JSONObject jo = new JSONObject(); - jo.put("type",payServiceFactory.getPayShareAdapterService(dto.getPayWay(),payAccount.getPayVersion()).getShareAccount(receiver.getReceiverType()).getMessage()); - jo.put("account",receiver.getReceiverAccount()); - jo.put("amount", amount); - //jo.put("description",receiver.getReceiverComments()); //改为存ID, - jo.put("description",receiver.getId().toString()); //为重试做准备 - realReceivers.add(jo); - }); - - - sharingOrder.setReceivers(JSON.toJSONString(realReceivers)); - wxProfitSharingOrderMapper.updateById(sharingOrder); - }); - } +// @Override +// @Deprecated +// public void updatetttttttttttttt(String tenantId) { +// WxProfitSharingOrder wxProfitSharingOrder = new WxProfitSharingOrder(); +// wxProfitSharingOrder.setTenantId(tenantId); +// wxProfitSharingOrder.setType(EnumProfitSharingOrderType.PROFIT_SHARING_SINGLE.getCode()); +// wxProfitSharingOrder.setSharingStatus(EnumProfitSharingOrderStatus.PROFIT_SHARING_APPLY_FAILED.getCode()); +// List list = wxProfitSharingOrderMapper.findList(wxProfitSharingOrder); +// list.stream().forEach(sharingOrder->{ +// if (!sharingOrder.getType().equals(EnumProfitSharingOrderType.PROFIT_SHARING_SINGLE.getCode())) { +// return; +// } +// +// WxProfitShareAppInoDto dto = getAppinfo(sharingOrder); +// WxAppinfo appInfo = dto.getAppinfo(); +// WxPayAccount payAccount = wxPayAccountMapper.selectById(appInfo.getPayId()); +// +// List receivers; +// +// receivers = JSONArray.parseArray(sharingOrder.getReceivers(), JSONObject.class); +// if (receivers.size() != 1 ) +// return; +// +// Integer amount = receivers.get(0).getInteger("amount"); +// if (!EnumProfitSharingReceiverType.PROFIT_SHARING_RECEIVER_PERSONAL_WECHATID.getMessage().equals(receivers.get(0).getString("type"))) { +// return; +// } +// +// //准备分账列表 +// WxProfitSharingReceiver psReceiverQ = new WxProfitSharingReceiver(); +// psReceiverQ.updateTenantInfo(payAccount); +// psReceiverQ.setMerchantId(sharingOrder.getMerchantId()); +// psReceiverQ.setSharingType(EnumProfitSharingType.PROFIT_SHARING_TYPE_WECHAT.getCode()); +// psReceiverQ.setStatus(EnumProfitSharingReceiverStatus.PROFIT_SHARING_RECEIVER_STATUS_VALID.getCode()); +// List psReceiverList = wxProfitSharingReceiverMapper.findList(psReceiverQ); +// if (null == psReceiverList || psReceiverList.size() !=1 ) { +// return ; +// } +// +// JSONArray realReceivers = new JSONArray(); +// psReceiverList.stream().forEach(receiver->{ +// JSONObject jo = new JSONObject(); +// jo.put("type",payServiceFactory.getPayShareAdapterService(dto.getPayWay(),payAccount.getPayVersion()).getShareAccount(receiver.getReceiverType()).getMessage()); +// jo.put("account",receiver.getReceiverAccount()); +// jo.put("amount", amount); +// //jo.put("description",receiver.getReceiverComments()); //改为存ID, +// jo.put("description",receiver.getId().toString()); //为重试做准备 +// realReceivers.add(jo); +// }); +// +// +// sharingOrder.setReceivers(JSON.toJSONString(realReceivers)); +// wxProfitSharingOrderMapper.updateById(sharingOrder); +// }); +// } @Override public ResultData handerSharingOrder(WxProfitSharingOrder sharingOrder) { diff --git a/mallinkService/src/main/java/com/iformall/service/pay/service/share/PayShareAdapterService.java b/mallinkService/src/main/java/com/iformall/service/pay/service/share/PayShareAdapterService.java index 196cd4bf8..4ad2f7e13 100644 --- a/mallinkService/src/main/java/com/iformall/service/pay/service/share/PayShareAdapterService.java +++ b/mallinkService/src/main/java/com/iformall/service/pay/service/share/PayShareAdapterService.java @@ -70,20 +70,20 @@ public interface PayShareAdapterService { * @param amount 分账金额 * @return */ - public PayShareResult noReciverShare(WxAppinfo appInfo,WxPayAccount payAccount,WxProfitSharingOrder record,String transcationId,Integer amount); + public PayShareResult noReciverShare(WxAppinfo appInfo,WxPayAccount payAccount,WxProfitSharingOrder record); /** * 有分账接收账号分账 ,钱分给小程序方,还要分给分账账号 调用API分账 * @param appInfo * @param payAccount * @param record - * @param transcationId + * @param * @param receivers 接收方账号 {"type":${EnumProfitSharingReceiverType.message},"account":${String},"amount":${Integer},"description":${id}} - * @param shareType + * @param Integer mchType * @return * @throws MallinkException */ - public PayShareResult haveReciversShare(WxAppinfo appInfo,WxPayAccount payAccount,WxProfitSharingOrder record,String transcationId,JSONArray receivers,EnumProfitSharingOrderType shareType ) throws MallinkException; + public PayShareResult haveReciversShare(WxAppinfo appInfo,WxPayAccount payAccount,WxProfitSharingOrder record,JSONArray receivers,Integer mchType ) throws MallinkException; /** * 分账结果查询 diff --git a/mallinkService/src/main/java/com/iformall/service/pay/service/share/douyin/TtPayShareService.java b/mallinkService/src/main/java/com/iformall/service/pay/service/share/douyin/TtPayShareService.java index c2d683d8d..f95ea42b6 100644 --- a/mallinkService/src/main/java/com/iformall/service/pay/service/share/douyin/TtPayShareService.java +++ b/mallinkService/src/main/java/com/iformall/service/pay/service/share/douyin/TtPayShareService.java @@ -42,6 +42,7 @@ import org.springframework.stereotype.Service; import java.util.*; import java.util.stream.Collectors; +import java.util.stream.Stream; import static java.util.stream.Collectors.groupingBy; @@ -100,7 +101,7 @@ public class TtPayShareService extends PayShareBaseAdapterService{ } @Override - public PayShareResult noReciverShare(WxAppinfo appInfo,WxPayAccount payAccount,WxProfitSharingOrder record,String transcationId,Integer amount) { + public PayShareResult noReciverShare(WxAppinfo appInfo,WxPayAccount payAccount,WxProfitSharingOrder record) { if(EnumProfitSharingOrderStatus.PROFIT_SHARING_UNKNOWN.getCode().equals(record.getSharingStatus())){ return new PayShareResult(false, EnumProfitSharingOrderStatus.PROFIT_SHARING_UNKNOWN.getCode(),"分账准备中", null,null); } @@ -152,7 +153,7 @@ public class TtPayShareService extends PayShareBaseAdapterService{ } @Override - public PayShareResult haveReciversShare(WxAppinfo appInfo,WxPayAccount payAccount,WxProfitSharingOrder record,String transcationId,JSONArray receivers,EnumProfitSharingOrderType shareType ) throws MallinkException { + public PayShareResult haveReciversShare(WxAppinfo appInfo,WxPayAccount payAccount,WxProfitSharingOrder record,JSONArray receivers,Integer mchType) throws MallinkException { if(EnumProfitSharingOrderStatus.PROFIT_SHARING_UNKNOWN.getCode().equals(record.getSharingStatus())){ return new PayShareResult(false, EnumProfitSharingOrderStatus.PROFIT_SHARING_UNKNOWN.getCode(),"分账准备中", null,null); } @@ -283,18 +284,18 @@ public class TtPayShareService extends PayShareBaseAdapterService{ @Override public ResultData handerSharingOrder(WxPayOrder payOrder, WxProfitSharingOrder sharingOrder) { - if(!EnumProfitSharingOrderType.PROFIT_SHARING_SINGLE.getCode().equals(sharingOrder.getType()) - && !EnumProfitSharingOrderType.PROFIT_SHARING_SINGLE_FINISH.getCode().equals(sharingOrder.getType())){ - return new ResultData(ErrorCode.SYS_PARAMETER_TYPE_ERROR.getCode(),"抖音暂不支持多次分账"); - } +// if(!EnumProfitSharingOrderType.PROFIT_SHARING_SINGLE.getCode().equals(sharingOrder.getType()) +// && !EnumProfitSharingOrderType.PROFIT_SHARING_SINGLE_FINISH.getCode().equals(sharingOrder.getType())){ +// return new ResultData(ErrorCode.SYS_PARAMETER_TYPE_ERROR.getCode(),"抖音暂不支持多次分账"); +// } WxCouponOrder couponOrder = new WxCouponOrder(); couponOrder.updateTenantInfo(payOrder); couponOrder.setComposeOrderId(payOrder.getId()); List list = wxCouponOrderMapper.findList(couponOrder); - if(list.stream().filter(co->(!EnumCouponOrderStatus.COUPON_ORDER_USED.getCode().equals(co.getCouponOrderStatus()))).count() > 0){ + if(list.stream().filter(co->(EnumCouponOrderStatus.COUPON_ORDER_USE_WAIT.getCode().equals(co.getCouponOrderStatus()))).count() > 0){ return new ResultData(ErrorCode.SYS_SERVER_ERROR.getCode(),"存在未核销的券"); } - if(EnumProfitSharingOrderType.PROFIT_SHARING_SINGLE_FINISH.getCode().equals(sharingOrder.getType())){ + if(EnumPayMchType.DIRECT.getCode().equals(payOrder.getMchType())){ WxProfitSharingOrder updSharingOrder = new WxProfitSharingOrder(); updSharingOrder.setId(sharingOrder.getId()); updSharingOrder.updateTenantInfo(payOrder); @@ -320,24 +321,26 @@ public class TtPayShareService extends PayShareBaseAdapterService{ for (WxOrder o:list1) { WxCouponOrder co = map.get(o.getId()); WxProfitSharingReceiver receiver = getReceiver(payOrder, co.getBMerchantId(), payOrder.getTtPayWay(),payOrder.getMchType()); - WxComposeChildOrderShare childOrderShare = payOrder.getChildOrderShare(o.getId()); - int darenTakeAmount = 0; - if(EnumOrderCpsStatus.ORDER_IS_CPS.getCode().equals(o.getCpsStatus())){ - OrderCps orderCps = orderCpsMapper.selectById(o.getId(), payOrder.getTenantId()); - darenTakeAmount = orderCps.getCommissionAmount(); + if(receiver != null){ + WxComposeChildOrderShare childOrderShare = payOrder.getChildOrderShare(o.getId()); + int darenTakeAmount = 0; + if(EnumOrderCpsStatus.ORDER_IS_CPS.getCode().equals(o.getCpsStatus())){ + OrderCps orderCps = orderCpsMapper.selectById(o.getId(), payOrder.getTenantId()); + darenTakeAmount = orderCps.getCommissionAmount(); + } + JSONObject jo = new JSONObject(); + jo.put("type",this.getShareAccount(receiver.getReceiverType()).getMessage()); + jo.put("account",receiver.getReceiverAccount()); + + jo.put("amount", childOrderShare.getShareAmount() - darenTakeAmount); + jo.put("rateAmount", childOrderShare.getRateAmount()); + jo.put("realRateAmount", childOrderShare.getRealRateAmount()); + jo.put("commissionAmount", childOrderShare.getCommissionAmount()); + jo.put("darenTakeAmount", darenTakeAmount); + //jo.put("description",receiver.getReceiverComments()); //改为存ID, + jo.put("description",receiver.getId().toString()); //为重试做准备 + receivers.add(jo); } - JSONObject jo = new JSONObject(); - jo.put("type",this.getShareAccount(receiver.getReceiverType()).getMessage()); - jo.put("account",receiver.getReceiverAccount()); - - jo.put("amount", childOrderShare.getShareAmount() - darenTakeAmount); - jo.put("rateAmount", childOrderShare.getRateAmount()); - jo.put("realRateAmount", childOrderShare.getRealRateAmount()); - jo.put("commissionAmount", childOrderShare.getCommissionAmount()); - jo.put("darenTakeAmount", darenTakeAmount); - //jo.put("description",receiver.getReceiverComments()); //改为存ID, - jo.put("description",receiver.getId().toString()); //为重试做准备 - receivers.add(jo); } WxProfitSharingOrder updSharingOrder = new WxProfitSharingOrder(); @@ -345,7 +348,9 @@ public class TtPayShareService extends PayShareBaseAdapterService{ updSharingOrder.updateTenantInfo(payOrder); updSharingOrder.setSharingStatus(EnumProfitSharingOrderStatus.PROFIT_SHARING_APPLY_FAILED.getCode()); updSharingOrder.setErrorMsg("待分账重试"); - updSharingOrder.setReceivers(receivers.toJSONString()); + if(!receivers.isEmpty()){ + updSharingOrder.setReceivers(receivers.toJSONString()); + } updSharingOrder.setUpdateTime(new Date()); wxProfitSharingOrderMapper.updateById(updSharingOrder); return new ResultData(); @@ -356,10 +361,10 @@ public class TtPayShareService extends PayShareBaseAdapterService{ @Override public WxProfitSharingOrder createSharingOrder(WxSharingOrderDto sharingOrderDto, Integer mchType,Integer share) { - if(!EnumProfitSharingOrderType.PROFIT_SHARING_SINGLE.getCode().equals(sharingOrderDto.getType()) - && !EnumProfitSharingOrderType.PROFIT_SHARING_SINGLE_FINISH.getCode().equals(sharingOrderDto.getType())){ - throw new MallinkException(ErrorCode.SYS_PARAMETER_TYPE_ERROR.getCode(),"抖音暂不支持多次分账"); - } +// if(!EnumProfitSharingOrderType.PROFIT_SHARING_SINGLE.getCode().equals(sharingOrderDto.getType()) +// && !EnumProfitSharingOrderType.PROFIT_SHARING_SINGLE_FINISH.getCode().equals(sharingOrderDto.getType())){ +// throw new MallinkException(ErrorCode.SYS_PARAMETER_TYPE_ERROR.getCode(),"抖音暂不支持多次分账"); +// } WxProfitSharingOrder record = new WxProfitSharingOrder(); record.updateTenantInfo(sharingOrderDto); @@ -383,16 +388,7 @@ public class TtPayShareService extends PayShareBaseAdapterService{ record.setUpdateTime(currentDate); record.setPayTimeStart(sharingOrderDto.getPayTimeStart()); record.setPayTimeEnd(sharingOrderDto.getPayTimeEnd()); - if(EnumPayMchType.DIRECT.getCode().equals(mchType)){ - record.setType(EnumProfitSharingOrderType.PROFIT_SHARING_SINGLE_FINISH.getCode()); - }else{ - if(EnumPayShare.YES.getCode().equals(share)){ - record.setType(EnumProfitSharingOrderType.PROFIT_SHARING_SINGLE.getCode()); - }else{ - record.setType(EnumProfitSharingOrderType.PROFIT_SHARING_SINGLE_FINISH.getCode()); - } - } - + record.setType(sharingOrderDto.getType()); wxProfitSharingOrderMapper.insert(record); } @@ -401,6 +397,10 @@ public class TtPayShareService extends PayShareBaseAdapterService{ @Override public WxProfitSharingReceiver getReceiver(TenantEntity tenantEntity, Long merchantId, Integer ttPayWay,Integer mchType) { + if(merchantId == null || merchantId.equals(0L)){ + return null; + } + WxProfitSharingReceiver psReceiverQ = new WxProfitSharingReceiver(); psReceiverQ.updateTenantInfo(tenantEntity); psReceiverQ.setMerchantId(merchantId); diff --git a/mallinkService/src/main/java/com/iformall/service/pay/service/share/wx/sft/WxPayShareSFTService.java b/mallinkService/src/main/java/com/iformall/service/pay/service/share/wx/sft/WxPayShareSFTService.java index 925b9a63e..da6f781f1 100644 --- a/mallinkService/src/main/java/com/iformall/service/pay/service/share/wx/sft/WxPayShareSFTService.java +++ b/mallinkService/src/main/java/com/iformall/service/pay/service/share/wx/sft/WxPayShareSFTService.java @@ -84,13 +84,13 @@ public class WxPayShareSFTService extends PayShareBaseAdapterService{ } @Override - public PayShareResult noReciverShare(WxAppinfo appInfo,WxPayAccount payAccount,WxProfitSharingOrder record,String transcationId,Integer amount) { + public PayShareResult noReciverShare(WxAppinfo appInfo,WxPayAccount payAccount,WxProfitSharingOrder record) { return null; } @Override - public PayShareResult haveReciversShare(WxAppinfo appInfo,WxPayAccount payAccount,WxProfitSharingOrder record,String transcationId,JSONArray receivers,EnumProfitSharingOrderType shareType ) throws MallinkException { + public PayShareResult haveReciversShare(WxAppinfo appInfo,WxPayAccount payAccount,WxProfitSharingOrder record,JSONArray receivers,Integer mchType) throws MallinkException { return null; } diff --git a/mallinkService/src/main/java/com/iformall/service/pay/service/share/wx/v2/WxPayShareService.java b/mallinkService/src/main/java/com/iformall/service/pay/service/share/wx/v2/WxPayShareService.java index 9fb142956..2b58deef0 100644 --- a/mallinkService/src/main/java/com/iformall/service/pay/service/share/wx/v2/WxPayShareService.java +++ b/mallinkService/src/main/java/com/iformall/service/pay/service/share/wx/v2/WxPayShareService.java @@ -77,14 +77,14 @@ public class WxPayShareService extends PayShareBaseAdapterService{ } @Override - public PayShareResult noReciverShare(WxAppinfo appInfo,WxPayAccount payAccount,WxProfitSharingOrder record,String transcationId,Integer amount) { + public PayShareResult noReciverShare(WxAppinfo appInfo,WxPayAccount payAccount,WxProfitSharingOrder record) { WxProfitSharingFinishP psFCmd = new WxProfitSharingFinishP(); psFCmd.setMch_id(payAccount.getMchId()); psFCmd.setSub_mch_id(payAccount.getSubMchId()); psFCmd.setAppid(appInfo.getParentAppId()); psFCmd.setNonce_str(Utility.generate32UUID()); - psFCmd.setTransaction_id(transcationId); + psFCmd.setTransaction_id(record.getTransactionId()); psFCmd.setOut_order_no(record.getId().toString()); //psFCmd.setAmount(amount); psFCmd.setDescription("分账已完结"); @@ -119,7 +119,7 @@ public class WxPayShareService extends PayShareBaseAdapterService{ } @Override - public PayShareResult haveReciversShare(WxAppinfo appInfo,WxPayAccount payAccount,WxProfitSharingOrder record,String transcationId,JSONArray receivers,EnumProfitSharingOrderType shareType ) throws MallinkException { + public PayShareResult haveReciversShare(WxAppinfo appInfo,WxPayAccount payAccount,WxProfitSharingOrder record,JSONArray receivers,Integer mchType) throws MallinkException { //分账提交 WxProfitSharingP psCmd = new WxProfitSharingP(); psCmd.setMch_id(payAccount.getMchId()); @@ -127,7 +127,7 @@ public class WxPayShareService extends PayShareBaseAdapterService{ psCmd.setAppid(appInfo.getParentAppId()); psCmd.setSub_appid(appInfo.getAppId()); psCmd.setNonce_str(Utility.generate32UUID()); - psCmd.setTransaction_id(transcationId); + psCmd.setTransaction_id(record.getTransactionId()); psCmd.setOut_order_no(record.getId().toString()); psCmd.setSign_type("HMAC-SHA256"); psCmd.setReceivers(receivers.toJSONString()); @@ -136,9 +136,9 @@ public class WxPayShareService extends PayShareBaseAdapterService{ try { psCmd.setSign(WxPayment.createSignHMAC(BeanUtils.toStringMap(psCmd), payAccount.getApiKey())); log.info("request:" + psCmd.toString()); - if(shareType.getCode().intValue()==EnumProfitSharingOrderType.PROFIT_SHARING_SINGLE.getCode().intValue()) { + if(EnumProfitSharingOrderType.PROFIT_SHARING_SINGLE.getCode().equals(record.getType())) { response = WxProfitSharing.pushOrder(BeanUtils.toStringMap(psCmd), payAccount.getCertPath(), payAccount.getMchId()); - } else if(shareType.getCode().intValue()==EnumProfitSharingOrderType.PROFIT_SHARING_MULTI.getCode().intValue()) { + } else if(EnumProfitSharingOrderType.PROFIT_SHARING_MULTI.getCode().equals(record.getType())) { response = WxProfitSharing.pushMultiOrder(BeanUtils.toStringMap(psCmd), payAccount.getCertPath(), payAccount.getMchId()); } else { throw new MallinkException(ErrorCode.SYS_PARAMETER_ERROR); @@ -391,6 +391,9 @@ public class WxPayShareService extends PayShareBaseAdapterService{ @Override public WxProfitSharingReceiver getReceiver(TenantEntity tenantEntity, Long merchantId, Integer ttPayWay,Integer mchType) { + if(merchantId == null || merchantId.equals(0L)){ + return null; + } WxProfitSharingReceiver psReceiverQ = new WxProfitSharingReceiver(); psReceiverQ.updateTenantInfo(tenantEntity); psReceiverQ.setMerchantId(merchantId); diff --git a/mallinkService/src/main/java/com/iformall/service/pay/service/share/wx/v3/WxPayShareV3Service.java b/mallinkService/src/main/java/com/iformall/service/pay/service/share/wx/v3/WxPayShareV3Service.java index 01a47a8d2..3ef8a55d6 100644 --- a/mallinkService/src/main/java/com/iformall/service/pay/service/share/wx/v3/WxPayShareV3Service.java +++ b/mallinkService/src/main/java/com/iformall/service/pay/service/share/wx/v3/WxPayShareV3Service.java @@ -134,6 +134,9 @@ public class WxPayShareV3Service extends PayShareBaseAdapterService{ @Override public WxProfitSharingReceiver getReceiver(TenantEntity tenantEntity, Long merchantId, Integer ttPayWay,Integer mchType) { + if(merchantId == null || merchantId.equals(0L)){ + return null; + } WxProfitSharingReceiver receiver = null; //直连,必须是特约商户号 if (EnumPayMchType.DIRECT.getCode() == mchType) { @@ -150,7 +153,7 @@ public class WxPayShareV3Service extends PayShareBaseAdapterService{ //无需分账,直接解冻 @Override - public PayShareResult noReciverShare(WxAppinfo appInfo,WxPayAccount payAccount,WxProfitSharingOrder record,String transcationId,Integer amount) { + public PayShareResult noReciverShare(WxAppinfo appInfo,WxPayAccount payAccount,WxProfitSharingOrder record) { V3PayShareUnfreezeReq req = new V3PayShareUnfreezeReq(); //直连模式 if (payAccount.getMchType() == EnumPayMchType.DIRECT.getCode()) { @@ -159,7 +162,7 @@ public class WxPayShareV3Service extends PayShareBaseAdapterService{ }else { req.setSub_mchid(payAccount.getSubMchId()); } - req.setTransaction_id(transcationId); + req.setTransaction_id(record.getTransactionId()); req.setOut_order_no(String.valueOf(record.getOrderId())); try { req.setDescription(WxPayV3.handleChinese(appInfo.getName()+"支付订单:"+record.getOrderId())); @@ -184,10 +187,10 @@ public class WxPayShareV3Service extends PayShareBaseAdapterService{ } @Override - public PayShareResult haveReciversShare(WxAppinfo appInfo,WxPayAccount payAccount,WxProfitSharingOrder record,String transcationId,JSONArray receivers,EnumProfitSharingOrderType shareType ) throws MallinkException { + public PayShareResult haveReciversShare(WxAppinfo appInfo,WxPayAccount payAccount,WxProfitSharingOrder record,JSONArray receivers,Integer mchType ) throws MallinkException { V3PayShareReq req = new V3PayShareReq(); //直连模式 - if (payAccount.getMchType() == EnumPayMchType.DIRECT.getCode()) { + if (EnumPayMchType.DIRECT.getCode().equals(mchType)) { req.setSub_mchid(record.getPayMerchantMchId()); //总分 }else { @@ -195,7 +198,7 @@ public class WxPayShareV3Service extends PayShareBaseAdapterService{ } req.setAppid(appInfo.getParentAppId()); req.setSub_appid(appInfo.getAppId()); - req.setTransaction_id(transcationId); + req.setTransaction_id(record.getTransactionId()); req.setOut_order_no(String.valueOf(record.getOrderId())); req.setReceivers(receivers); WxPayService payService = maUtil.getWxPayService(appInfo, payAccount);