From 1fb08c2e4edfff1dfe863b24c5b1d01b1fa66cf2 Mon Sep 17 00:00:00 2001 From: xhxu Date: Tue, 15 Aug 2023 14:23:29 +0800 Subject: [PATCH] =?UTF-8?q?//=E5=88=86=E8=B4=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../schedule/ProductOrderSharingSchedule.java | 40 +++++- .../com/iformall/domain/po/ProductOrder.java | 2 +- .../domain/po/ProductOrderSharing.java | 14 ++- .../iformall/douyin/pay/DouYinPayHelper.java | 5 +- .../pay/orderQuery/QuerySettleResult.java | 3 + .../mapper/ProductOrderSharingMapper.java | 12 ++ .../iformall/service/ProductOrderService.java | 1 + .../service/ProductOrderSharingService.java | 25 ++++ .../com/iformall/service/ProductService.java | 1 + .../service/impl/ProductOrderServiceImpl.java | 41 +++++-- .../impl/ProductOrderSharingServiceImpl.java | 115 ++++++++++++++++++ .../impl/WxProfitSharingOrderServiceImpl.java | 2 +- .../service/share/PayShareAdapterService.java | 21 +++- .../share/douyin/TtPayShareService.java | 47 ++++++- .../share/entity/PayShareQueryResult.java | 17 ++- .../share/wx/sft/WxPayShareSFTService.java | 12 +- .../share/wx/v2/WxPayShareService.java | 14 ++- .../share/wx/v3/WxPayShareV3Service.java | 50 +++++++- .../wx/v3/entity/V3PayShareQueryReq.java | 2 +- .../mapper/ProductOrderSharingMapper.xml | 92 ++++++++++++++ 20 files changed, 492 insertions(+), 24 deletions(-) create mode 100644 suimangService/src/main/java/com/iformall/mapper/ProductOrderSharingMapper.java create mode 100644 suimangService/src/main/java/com/iformall/service/ProductOrderSharingService.java create mode 100644 suimangService/src/main/java/com/iformall/service/impl/ProductOrderSharingServiceImpl.java create mode 100644 suimangService/src/main/resources/mapper/ProductOrderSharingMapper.xml diff --git a/suimangSchedule/src/main/java/com/iformall/schedule/ProductOrderSharingSchedule.java b/suimangSchedule/src/main/java/com/iformall/schedule/ProductOrderSharingSchedule.java index 31c3b92..c2af785 100644 --- a/suimangSchedule/src/main/java/com/iformall/schedule/ProductOrderSharingSchedule.java +++ b/suimangSchedule/src/main/java/com/iformall/schedule/ProductOrderSharingSchedule.java @@ -1,8 +1,10 @@ package com.iformall.schedule; import com.iformall.domain.po.ProductOrder; +import com.iformall.domain.po.ProductOrderSharing; import com.iformall.enums.*; import com.iformall.service.ProductOrderService; +import com.iformall.service.ProductOrderSharingService; import com.iformall.utils.DateUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -20,7 +22,10 @@ public class ProductOrderSharingSchedule { @Autowired private ProductOrderService productOrderService; - @Scheduled(cron = "0 15 2 * * ?") // 每天凌晨02:00分账重试 + @Autowired + private ProductOrderSharingService productOrderSharingService; + + @Scheduled(cron = "0 15 1 * * ?") // 每天凌晨02:00分账重试 public void productOrderSharingSchedule() { ProductOrder productOrderQ = new ProductOrder(); productOrderQ.setOrderStatus(EnumProductOrderStatus.ORDER_STATUS_PAYMENT_SUCCESS.getCode()); @@ -30,6 +35,9 @@ public class ProductOrderSharingSchedule { for (ProductOrder order: orderList) { try{ productOrderService.handldSharing(order); + + productOrderSharingService.sharingOrder(order.getId()); + }catch(Exception e){ logger.error("分账失败:" + e.getMessage()); } @@ -37,4 +45,34 @@ public class ProductOrderSharingSchedule { } } + @Scheduled(cron = "0 15 2 * * ?") // 每天凌晨02:00分账重试 + public void productOrderSharing2Schedule() { + ProductOrderSharing productOrderSharingQ = new ProductOrderSharing(); + productOrderSharingQ.setSettleStatus(EnumProductOrderSettleStatus.unfreeze_before.getCode()); + List sharingList = productOrderSharingService.findList(productOrderSharingQ); + for (ProductOrderSharing sharing: sharingList) { + try{ + productOrderSharingService.sharingOrder(sharing.getId()); + }catch(Exception e){ + logger.error("分账失败:" + e.getMessage()); + } + + } + } + + @Scheduled(cron = "0 15 3 * * ?") // 查询分账结果 + public void productOrderSharingQuerySchedule() { + ProductOrderSharing productOrderSharingQ = new ProductOrderSharing(); + productOrderSharingQ.setSettleStatus(EnumProductOrderSettleStatus.unfreeze_ing.getCode()); + List sharingList = productOrderSharingService.findList(productOrderSharingQ); + for (ProductOrderSharing sharing: sharingList) { + try{ + productOrderSharingService.handleSharingOrder(sharing.getId()); + }catch(Exception e){ + logger.error("分账失败:" + e.getMessage()); + } + + } + } + } \ No newline at end of file diff --git a/suimangService/src/main/java/com/iformall/domain/po/ProductOrder.java b/suimangService/src/main/java/com/iformall/domain/po/ProductOrder.java index bb193c5..cc976ee 100644 --- a/suimangService/src/main/java/com/iformall/domain/po/ProductOrder.java +++ b/suimangService/src/main/java/com/iformall/domain/po/ProductOrder.java @@ -64,7 +64,7 @@ public class ProductOrder extends TenantEntity { @io.swagger.annotations.ApiModelProperty(value="支付时间",name="paymentTime") private Date paymentTime; - @io.swagger.annotations.ApiModelProperty(value="支付时间",name="paymentTime") + @io.swagger.annotations.ApiModelProperty(value="支付渠道",name="payWay") private Integer payWay; diff --git a/suimangService/src/main/java/com/iformall/domain/po/ProductOrderSharing.java b/suimangService/src/main/java/com/iformall/domain/po/ProductOrderSharing.java index 553817a..f3d88b1 100644 --- a/suimangService/src/main/java/com/iformall/domain/po/ProductOrderSharing.java +++ b/suimangService/src/main/java/com/iformall/domain/po/ProductOrderSharing.java @@ -1,5 +1,6 @@ package com.iformall.domain.po; +import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableName; import com.iformall.domain.po.base.TenantEntity; import lombok.Data; @@ -20,6 +21,9 @@ public class ProductOrderSharing extends TenantEntity { @io.swagger.annotations.ApiModelProperty(value="订单价格",name="orderPrice") private Integer orderPrice; + @io.swagger.annotations.ApiModelProperty(value="支付渠道",name="payWay") + private Integer payWay; + @io.swagger.annotations.ApiModelProperty(value="平台支付单号",name="transactionId") private String transactionId; @@ -43,10 +47,12 @@ public class ProductOrderSharing extends TenantEntity { @io.swagger.annotations.ApiModelProperty(value = "EnumProductOrderSettleStatus", name = "settleStatus") private Integer settleStatus; + @io.swagger.annotations.ApiModelProperty(value="",name="settleMsg") + private String settleMsg; + @io.swagger.annotations.ApiModelProperty(value="",name="settleDetail") private String settleDetail; - @io.swagger.annotations.ApiModelProperty(value="手续费",name="rake") private Integer rake; @io.swagger.annotations.ApiModelProperty(value="佣金",name="commission") @@ -57,4 +63,10 @@ public class ProductOrderSharing extends TenantEntity { @io.swagger.annotations.ApiModelProperty(value="创建时间",name="createDate") private Date createDate; + @TableField(exist = false) + private Date startDate; + + @TableField(exist = false) + private Date endDate; + } diff --git a/suimangService/src/main/java/com/iformall/douyin/pay/DouYinPayHelper.java b/suimangService/src/main/java/com/iformall/douyin/pay/DouYinPayHelper.java index 9829d33..9942734 100644 --- a/suimangService/src/main/java/com/iformall/douyin/pay/DouYinPayHelper.java +++ b/suimangService/src/main/java/com/iformall/douyin/pay/DouYinPayHelper.java @@ -344,8 +344,11 @@ public class DouYinPayHelper { QuerySettleResult result = new QuerySettleResult(); result.setSettleNo(info.getString("settle_no")); result.setSettleAmount(info.getInteger("settle_amount")); + result.setRake(info.getInteger("rake")); + result.setCommission(info.getInteger("commission")); result.setSettleStatus(info.getString("settle_status")); - result.setMsg(jsonObject.getString("err_tips")); + result.setMsg(jsonObject.getString("msg")); + result.setSettleDetail(jsonObject.getString("settle_detail")); return result; }else { log.error("settleQuery reponse error. request: "+JSON.toJSONString(map)+" response:"+response); diff --git a/suimangService/src/main/java/com/iformall/douyin/pay/orderQuery/QuerySettleResult.java b/suimangService/src/main/java/com/iformall/douyin/pay/orderQuery/QuerySettleResult.java index 9f979c1..d369c0b 100644 --- a/suimangService/src/main/java/com/iformall/douyin/pay/orderQuery/QuerySettleResult.java +++ b/suimangService/src/main/java/com/iformall/douyin/pay/orderQuery/QuerySettleResult.java @@ -8,5 +8,8 @@ public class QuerySettleResult { private String settleNo;//担保支付侧的分账单号 private Integer settleAmount;//分账金额,单位[分] private String settleStatus;//分账状态,成功-SUCCESS;失败-FAIL + private String settleDetail; + private Integer rake; + private Integer commission; private String msg; } diff --git a/suimangService/src/main/java/com/iformall/mapper/ProductOrderSharingMapper.java b/suimangService/src/main/java/com/iformall/mapper/ProductOrderSharingMapper.java new file mode 100644 index 0000000..37e2a40 --- /dev/null +++ b/suimangService/src/main/java/com/iformall/mapper/ProductOrderSharingMapper.java @@ -0,0 +1,12 @@ +package com.iformall.mapper; + +import com.iformall.common.CommonMapper; +import com.iformall.domain.po.ProductOrderSharing; + +import java.util.List; + +public interface ProductOrderSharingMapper extends CommonMapper{ + + List findList(ProductOrderSharing record); + +} diff --git a/suimangService/src/main/java/com/iformall/service/ProductOrderService.java b/suimangService/src/main/java/com/iformall/service/ProductOrderService.java index 1abd1b4..4e64be1 100644 --- a/suimangService/src/main/java/com/iformall/service/ProductOrderService.java +++ b/suimangService/src/main/java/com/iformall/service/ProductOrderService.java @@ -33,4 +33,5 @@ public interface ProductOrderService { List findList(ProductOrder record); void handldSharing(ProductOrder order); + } diff --git a/suimangService/src/main/java/com/iformall/service/ProductOrderSharingService.java b/suimangService/src/main/java/com/iformall/service/ProductOrderSharingService.java new file mode 100644 index 0000000..e7f9800 --- /dev/null +++ b/suimangService/src/main/java/com/iformall/service/ProductOrderSharingService.java @@ -0,0 +1,25 @@ +package com.iformall.service; + +import com.github.pagehelper.PageInfo; +import com.iformall.domain.po.ProductOrderSharing; + +import java.util.List; + +public interface ProductOrderSharingService { + + /** + * 根据实体查询分页列表 + * + * @param record + * @param pageIndex + * @param pageSize + * @return + */ + PageInfo listAsPage(ProductOrderSharing record, Integer pageIndex, Integer pageSize); + + List findList(ProductOrderSharing record); + + void sharingOrder(Long id); + + void handleSharingOrder(Long id); +} diff --git a/suimangService/src/main/java/com/iformall/service/ProductService.java b/suimangService/src/main/java/com/iformall/service/ProductService.java index f663f55..7aa7d63 100644 --- a/suimangService/src/main/java/com/iformall/service/ProductService.java +++ b/suimangService/src/main/java/com/iformall/service/ProductService.java @@ -16,4 +16,5 @@ public interface ProductService { PageInfo listAsPage(Product record, Integer pageIndex, Integer pageSize); Product getById(Long id); + } diff --git a/suimangService/src/main/java/com/iformall/service/impl/ProductOrderServiceImpl.java b/suimangService/src/main/java/com/iformall/service/impl/ProductOrderServiceImpl.java index fb4a3ac..90f7c7f 100644 --- a/suimangService/src/main/java/com/iformall/service/impl/ProductOrderServiceImpl.java +++ b/suimangService/src/main/java/com/iformall/service/impl/ProductOrderServiceImpl.java @@ -6,12 +6,11 @@ import com.iformall.common.ErrorCode; import com.iformall.common.IdWorker; import com.iformall.common.ResultData; import com.iformall.domain.po.*; -import com.iformall.enums.EnumProductOrderPayVendor; -import com.iformall.enums.EnumProductOrderStatus; -import com.iformall.enums.EnumProductType; +import com.iformall.enums.*; import com.iformall.exception.MallinkException; import com.iformall.mapper.ProductMapper; import com.iformall.mapper.ProductOrderMapper; +import com.iformall.mapper.ProductOrderSharingMapper; import com.iformall.service.ProductOrderService; import com.iformall.service.UserBasicPropertyService; import com.iformall.service.WxAppinfoService; @@ -42,6 +41,9 @@ public class ProductOrderServiceImpl implements ProductOrderService { @Autowired ProductOrderMapper productOrderMapper; + @Autowired + ProductOrderSharingMapper productOrderSharingMapper; + @Autowired ProductMapper productMapper; @@ -200,12 +202,35 @@ public class ProductOrderServiceImpl implements ProductOrderService { @Override @Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) public void handldSharing(ProductOrder order) { + if(!EnumProductOrderStatus.ORDER_STATUS_PAYMENT_SUCCESS.getCode().equals(order.getOrderStatus())){ + return; + } + if(!EnumProfitSharing.PROFIT_SHARING_MAST.getCode().equals(order.getProfitSharing())){ + return; + } - - PayShareAdapterService payShareAdapterService = payServiceFactory.getPayShareAdapterService(order.getPayVendor()); - - payShareAdapterService.noReciverShare() - + Date now = new Date(); + ProductOrderSharing productOrderSharing = new ProductOrderSharing(); + productOrderSharing.setId(order.getId()); + productOrderSharing.setOutOrderId(order.getOrderNumber()); + productOrderSharing.setOrderPrice(order.getOrderPrice()); + productOrderSharing.setPayWay(order.getPayWay()); + productOrderSharing.setTransactionId(order.getTransactionId()); + productOrderSharing.setProjectType(order.getProjectType()); + productOrderSharing.setPayVendor(order.getPayVendor()); + final IdWorker idWorker = IdWorker.get(); + productOrderSharing.setOutSettleNo(String.valueOf(idWorker.nextId())); + productOrderSharing.setSettleDesc("解冻至收款方"); + productOrderSharing.setSettleStatus(EnumProductOrderSettleStatus.unfreeze_before.getCode()); + productOrderSharing.setCreateDate(now); + productOrderSharing.setUpdateDate(now); + productOrderSharingMapper.insert(productOrderSharing); + + ProductOrder updOrder = new ProductOrder(); + updOrder.setId(order.getId()); + updOrder.setProfitSharing(EnumProfitSharing.PROFIT_SHARING_FINISH.getCode()); + updOrder.setUpdateDate(now); + productOrderMapper.updateById(updOrder); } diff --git a/suimangService/src/main/java/com/iformall/service/impl/ProductOrderSharingServiceImpl.java b/suimangService/src/main/java/com/iformall/service/impl/ProductOrderSharingServiceImpl.java new file mode 100644 index 0000000..25ec971 --- /dev/null +++ b/suimangService/src/main/java/com/iformall/service/impl/ProductOrderSharingServiceImpl.java @@ -0,0 +1,115 @@ +package com.iformall.service.impl; + +import com.github.pagehelper.PageHelper; +import com.github.pagehelper.PageInfo; +import com.iformall.common.ErrorCode; +import com.iformall.common.ResultData; +import com.iformall.domain.po.Product; +import com.iformall.domain.po.ProductOrderSharing; +import com.iformall.domain.po.WxAppinfo; +import com.iformall.domain.po.WxPayAccount; +import com.iformall.enums.EnumProductOrderPayVendor; +import com.iformall.enums.EnumProductOrderSettleStatus; +import com.iformall.exception.MallinkException; +import com.iformall.mapper.ProductMapper; +import com.iformall.mapper.ProductOrderSharingMapper; +import com.iformall.service.ProductOrderSharingService; +import com.iformall.service.ProductService; +import com.iformall.service.WxAppinfoService; +import com.iformall.service.WxPayAccountService; +import com.iformall.service.pay.PayServiceFactory; +import com.iformall.service.pay.service.share.PayShareAdapterService; +import com.iformall.service.pay.service.share.entity.PayShareQueryResult; +import com.iformall.service.pay.service.share.entity.PayShareResult; +import lombok.extern.slf4j.Slf4j; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.Date; +import java.util.List; + +@Service +@Slf4j +public class ProductOrderSharingServiceImpl implements ProductOrderSharingService { + + private final Logger logger = LoggerFactory.getLogger(this.getClass()); + + @Autowired + ProductOrderSharingMapper productOrderSharingFromMapper; + + @Autowired + WxAppinfoService wxAppinfoService; + + @Autowired + WxPayAccountService wxPayAccountService; + + @Autowired + PayServiceFactory payServiceFactory; + + @Override + public PageInfo listAsPage(ProductOrderSharing record, Integer pageIndex, Integer pageSize) { + return PageHelper.startPage(pageIndex, pageSize).doSelectPageInfo(() -> productOrderSharingFromMapper.findList(record)); + } + + @Override + public List findList(ProductOrderSharing record) { + return productOrderSharingFromMapper.findList(record); + } + + @Override + public void sharingOrder(Long id) { + ProductOrderSharing productOrderSharing = productOrderSharingFromMapper.selectById(id); + if(productOrderSharing == null){ + return; + } + if(!EnumProductOrderSettleStatus.unfreeze_before.getCode().equals(productOrderSharing.getSettleStatus())){ + return; + } + PayShareAdapterService payShareAdapterService = payServiceFactory.getPayShareAdapterService(productOrderSharing.getPayVendor()); + EnumProductOrderPayVendor payVendoEnum = EnumProductOrderPayVendor.getEnum(productOrderSharing.getPayVendor()); + WxAppinfo appinfo = wxAppinfoService.getProjectCAppInfoFromRedis(productOrderSharing.getProjectType(), payVendoEnum.getPlat()); + WxPayAccount payAccount = wxPayAccountService.getByIdFromRedis(appinfo.getPayId()); + PayShareResult payShareResult = payShareAdapterService.noReciverShare(appinfo, payAccount, productOrderSharing); + if(payShareResult.isSuccess()){ + ProductOrderSharing updSharing = new ProductOrderSharing(); + updSharing.setId(productOrderSharing.getId()); + updSharing.setSettleNo(payShareResult.getShareOrderNo()); + updSharing.setSettleStatus(EnumProductOrderSettleStatus.unfreeze_ing.getCode()); + updSharing.setUpdateDate(new Date()); + productOrderSharingFromMapper.updateById(updSharing); + }else{ + throw new MallinkException(ErrorCode.PROFIT_SHARING_REQUEST_FAILED.getCode(),payShareResult.getMsg()); + } + } + + @Override + public void handleSharingOrder(Long id) { + ProductOrderSharing productOrderSharing = productOrderSharingFromMapper.selectById(id); + if(productOrderSharing == null){ + return; + } + if(!EnumProductOrderSettleStatus.unfreeze_ing.getCode().equals(productOrderSharing.getSettleStatus())){ + return; + } + PayShareAdapterService payShareAdapterService = payServiceFactory.getPayShareAdapterService(productOrderSharing.getPayVendor()); + EnumProductOrderPayVendor payVendoEnum = EnumProductOrderPayVendor.getEnum(productOrderSharing.getPayVendor()); + WxAppinfo appinfo = wxAppinfoService.getProjectCAppInfoFromRedis(productOrderSharing.getProjectType(), payVendoEnum.getPlat()); + WxPayAccount payAccount = wxPayAccountService.getByIdFromRedis(appinfo.getPayId()); + PayShareQueryResult payShareQueryResult = payShareAdapterService.shareQuery(appinfo, payAccount, productOrderSharing); + ProductOrderSharing updSharing = new ProductOrderSharing(); + updSharing.setId(productOrderSharing.getId()); + updSharing.setSettleMsg(productOrderSharing.getSettleMsg()); + if(payShareQueryResult.isSuccess()){ + updSharing.setSettleStatus(EnumProductOrderSettleStatus.unfreeze.getCode()); + updSharing.setSettleDetail(productOrderSharing.getSettleDetail()); + updSharing.setRake(productOrderSharing.getRake()); + updSharing.setCommission(productOrderSharing.getCommission()); + }else{ + updSharing.setSettleStatus(EnumProductOrderSettleStatus.unfreeze_error.getCode()); + } + productOrderSharingFromMapper.updateById(updSharing); + } + +} diff --git a/suimangService/src/main/java/com/iformall/service/impl/WxProfitSharingOrderServiceImpl.java b/suimangService/src/main/java/com/iformall/service/impl/WxProfitSharingOrderServiceImpl.java index c39ef6c..4863d3f 100644 --- a/suimangService/src/main/java/com/iformall/service/impl/WxProfitSharingOrderServiceImpl.java +++ b/suimangService/src/main/java/com/iformall/service/impl/WxProfitSharingOrderServiceImpl.java @@ -636,7 +636,7 @@ public class WxProfitSharingOrderServiceImpl implements WxProfitSharingOrderServ // } // } // } - return new ResultData(payShareQueryResult.getData()); + return new ResultData(payShareQueryResult); } @Override diff --git a/suimangService/src/main/java/com/iformall/service/pay/service/share/PayShareAdapterService.java b/suimangService/src/main/java/com/iformall/service/pay/service/share/PayShareAdapterService.java index 86447e3..3bcfb7e 100644 --- a/suimangService/src/main/java/com/iformall/service/pay/service/share/PayShareAdapterService.java +++ b/suimangService/src/main/java/com/iformall/service/pay/service/share/PayShareAdapterService.java @@ -47,6 +47,15 @@ public interface PayShareAdapterService { * @return */ WxProfitSharingReceiver getReceiver(TenantEntity tenantEntity, Long merchantId, Integer ttPayWay,Integer mchType); + + /** + * 无分账接收方分账 ,钱直接分给小程序方 调用API分账 + * @param appInfo + * @param payAccount + * @param record + * @return + */ + public PayShareResult noReciverShare(WxAppinfo appInfo,WxPayAccount payAccount,ProductOrderSharing record); /** * 无分账接收方分账 ,钱直接分给小程序方 调用API分账 @@ -71,7 +80,17 @@ public interface PayShareAdapterService { * @throws MallinkException */ public PayShareResult haveReciversShare(WxAppinfo appInfo,WxPayAccount payAccount,WxProfitSharingOrder record,JSONArray receivers) throws MallinkException; - + + /** + * 分账结果查询 + * @param appInfo + * @param payAccount + * @param record + * @return + * @throws MallinkException + */ + public PayShareQueryResult shareQuery(WxAppinfo appInfo,WxPayAccount payAccount,ProductOrderSharing record) throws MallinkException; + /** * 分账结果查询 * @param appInfo diff --git a/suimangService/src/main/java/com/iformall/service/pay/service/share/douyin/TtPayShareService.java b/suimangService/src/main/java/com/iformall/service/pay/service/share/douyin/TtPayShareService.java index 15d0f91..2fbf342 100644 --- a/suimangService/src/main/java/com/iformall/service/pay/service/share/douyin/TtPayShareService.java +++ b/suimangService/src/main/java/com/iformall/service/pay/service/share/douyin/TtPayShareService.java @@ -34,6 +34,7 @@ import com.iformall.service.pay.service.share.entity.ShareAccountResult; import com.iformall.service.pay.service.share.entity.ShareNotifyAdapterResult; import com.iformall.utils.*; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.context.annotation.Lazy; @@ -222,7 +223,29 @@ public class TtPayShareService extends PayShareBaseAdapterService{ } - @Override + @Override + public PayShareQueryResult shareQuery(WxAppinfo appInfo, WxPayAccount payAccount, ProductOrderSharing record) throws MallinkException { + QuerySettleResult querySettleResult = DouYinPayHelper.settleQuery(appInfo.getAppId(), payAccount.getApiKey(), record.getOutSettleNo(), null); + if(querySettleResult == null){ + throw new MallinkException(ErrorCode.PROFIT_SHARING_QUERY_REQUEST_FAILED.getCode(), "分账查询异常"); + } + PayShareQueryResult payShareQueryResult = new PayShareQueryResult(); + if(querySettleResult.getSettleStatus().equals("SUCCESS")){ + payShareQueryResult.setSuccess(true); + payShareQueryResult.setMsg("success"); + payShareQueryResult.setDetail(querySettleResult.getSettleDetail()); + payShareQueryResult.setRake(querySettleResult.getRake()); + payShareQueryResult.setCommission(querySettleResult.getCommission()); + return payShareQueryResult; + }else if(querySettleResult.getSettleStatus().equals("FAIL")){ + payShareQueryResult.setSuccess(false); + payShareQueryResult.setMsg(querySettleResult.getMsg()); + return payShareQueryResult; + } + throw new MallinkException(ErrorCode.PROFIT_SHARING_QUERY_REQUEST_FAILED.getCode(), "分账状态异常"); + } + + @Override public PayShareQueryResult shareQuery(WxAppinfo appInfo, WxPayAccount payAccount, WxProfitSharingOrder record) throws MallinkException { try { TtPayService ttPayService = maUtil.getTtPayService(appInfo, payAccount); @@ -230,9 +253,9 @@ public class TtPayShareService extends PayShareBaseAdapterService{ if(profitSharingResult.isSuccess()){ ProfitSharingResult.Receiver receiver = profitSharingResult.getData().get(0); if("SUCCESS".equals(receiver.getSettleStatus())){ - return new PayShareQueryResult(true, EnumProfitSharingOrderStatus.PROFIT_SHARING_DONE.getCode(), "success",receiver, null); + return new PayShareQueryResult(true, EnumProfitSharingOrderStatus.PROFIT_SHARING_DONE.getCode(), "success", null); } else if("FAIL".equals(receiver.getSettleStatus())){ - return new PayShareQueryResult(true, EnumProfitSharingOrderStatus.PROFIT_SHARING_FAILED.getCode(), "fail",receiver, null); + return new PayShareQueryResult(true, EnumProfitSharingOrderStatus.PROFIT_SHARING_FAILED.getCode(), "fail", null); } } throw new MallinkException(ErrorCode.PROFIT_SHARING_QUERY_REQUEST_FAILED.getCode(), profitSharingResult.getErrTips()); @@ -334,4 +357,22 @@ public class TtPayShareService extends PayShareBaseAdapterService{ } + @Override + public PayShareResult noReciverShare(WxAppinfo appInfo, WxPayAccount payAccount, ProductOrderSharing record) { + + Settle settle = new Settle(); + settle.setAppId(appInfo.getAppId()); + settle.setSalt(payAccount.getApiKey()); + settle.setOutSettleNo(record.getOutSettleNo()); + settle.setOutOrderNo(record.getOutOrderId()); + settle.setSettleDesc(record.getSettleDesc()); + SettleResult settleResult = DouYinPayHelper.settle(settle); + + if (settleResult.isSuccess()) { + return new PayShareResult(true, null,"success", settleResult,settleResult.getSettleNo()); + }else{ + return new PayShareResult(false, null,settleResult.getMsg(), null,null); + } + } + } diff --git a/suimangService/src/main/java/com/iformall/service/pay/service/share/entity/PayShareQueryResult.java b/suimangService/src/main/java/com/iformall/service/pay/service/share/entity/PayShareQueryResult.java index ae72704..2a26b06 100644 --- a/suimangService/src/main/java/com/iformall/service/pay/service/share/entity/PayShareQueryResult.java +++ b/suimangService/src/main/java/com/iformall/service/pay/service/share/entity/PayShareQueryResult.java @@ -12,10 +12,25 @@ public class PayShareQueryResult implements Serializable{ private static final long serialVersionUID = -3701322871877301001L; + public PayShareQueryResult(){ + + } + + public PayShareQueryResult(boolean isSuccess,Integer code,String msg,List receivers){ + this.isSuccess = isSuccess; + this.code = code; + this.msg = msg; + this.receivers = receivers; + } + private boolean isSuccess; private Integer code; private String msg; - private Object data; + private String detail; + + private Integer rake; + private Integer commission; + private List receivers;//数组字符串,平台查询返回的分账账户列表 diff --git a/suimangService/src/main/java/com/iformall/service/pay/service/share/wx/sft/WxPayShareSFTService.java b/suimangService/src/main/java/com/iformall/service/pay/service/share/wx/sft/WxPayShareSFTService.java index 8e8d5e6..27fb196 100644 --- a/suimangService/src/main/java/com/iformall/service/pay/service/share/wx/sft/WxPayShareSFTService.java +++ b/suimangService/src/main/java/com/iformall/service/pay/service/share/wx/sft/WxPayShareSFTService.java @@ -95,6 +95,11 @@ public class WxPayShareSFTService extends PayShareBaseAdapterService{ } + @Override + public PayShareQueryResult shareQuery(WxAppinfo appInfo, WxPayAccount payAccount, ProductOrderSharing record) throws MallinkException { + return null; + } + @Override public PayShareQueryResult shareQuery(WxAppinfo appInfo, WxPayAccount payAccount, WxProfitSharingOrder record) throws MallinkException { return null; @@ -160,5 +165,10 @@ public class WxPayShareSFTService extends PayShareBaseAdapterService{ return null; } - + @Override + public PayShareResult noReciverShare(WxAppinfo appInfo, WxPayAccount payAccount, ProductOrderSharing record) { + return null; + } + + } diff --git a/suimangService/src/main/java/com/iformall/service/pay/service/share/wx/v2/WxPayShareService.java b/suimangService/src/main/java/com/iformall/service/pay/service/share/wx/v2/WxPayShareService.java index 40bc719..788d8ed 100644 --- a/suimangService/src/main/java/com/iformall/service/pay/service/share/wx/v2/WxPayShareService.java +++ b/suimangService/src/main/java/com/iformall/service/pay/service/share/wx/v2/WxPayShareService.java @@ -182,7 +182,12 @@ public class WxPayShareService extends PayShareBaseAdapterService{ return new PayShareResult(true, null, "success",returnMap, returnMap.get("order_id")); } - @Override + @Override + public PayShareQueryResult shareQuery(WxAppinfo appInfo, WxPayAccount payAccount, ProductOrderSharing record) throws MallinkException { + return null; + } + + @Override public PayShareQueryResult shareQuery(WxAppinfo appInfo, WxPayAccount payAccount, WxProfitSharingOrder record) throws MallinkException { WxProfitSharingQueryP wxProfitSharingQueryP = new WxProfitSharingQueryP();; wxProfitSharingQueryP.setMch_id(payAccount.getMchId()); @@ -219,7 +224,7 @@ public class WxPayShareService extends PayShareBaseAdapterService{ } Integer code = (Integer) statusMap.get(returnMap.get("status")); - return new PayShareQueryResult(true, code, "success",returnMap, getReceivers(returnMap.get("receivers"))); + return new PayShareQueryResult(true, code, "success",getReceivers(returnMap.get("receivers"))); } @@ -367,6 +372,11 @@ public class WxPayShareService extends PayShareBaseAdapterService{ return record; } + @Override + public PayShareResult noReciverShare(WxAppinfo appInfo, WxPayAccount payAccount, ProductOrderSharing record) { + return null; + } + private static String queryOrderShareAmount(String mchId,String transcationId,String apiKey) { WxProfitSharingP psCmd = new WxProfitSharingP(); psCmd.setMch_id(mchId);//服务商商户id diff --git a/suimangService/src/main/java/com/iformall/service/pay/service/share/wx/v3/WxPayShareV3Service.java b/suimangService/src/main/java/com/iformall/service/pay/service/share/wx/v3/WxPayShareV3Service.java index 1cc113f..7711ac7 100644 --- a/suimangService/src/main/java/com/iformall/service/pay/service/share/wx/v3/WxPayShareV3Service.java +++ b/suimangService/src/main/java/com/iformall/service/pay/service/share/wx/v3/WxPayShareV3Service.java @@ -98,7 +98,29 @@ public class WxPayShareV3Service extends PayShareBaseAdapterService{ return null; } - //无需分账,直接解冻 + @Override + public PayShareResult noReciverShare(WxAppinfo appInfo, WxPayAccount payAccount, ProductOrderSharing record) { + V3PayShareUnfreezeReq req = new V3PayShareUnfreezeReq(); + req.setTransaction_id(record.getTransactionId()); + req.setOut_order_no(record.getOutOrderId()); + req.setDescription(record.getSettleDesc()); + WxPayService payService = maUtil.getWxPayServiceBySelfModel(appInfo, payAccount); + String response = null;; + try { + response = WxPayV3.unfreezn(payService, req); + if (StringUtils.isBlank(response)) { + return new PayShareResult(false, EnumProfitSharingOrderStatus.PROFIT_SHARING_REQ_FAILED.getCode(),"分账解冻请求失败.返回值为空", null,null); + } + } catch (WxPayException e) { + log.error("wx v3 noreciver share error:",e); + return new PayShareResult(false, EnumProfitSharingOrderStatus.PROFIT_SHARING_REQ_FAILED.getCode(),ErrorCode.PROFIT_SHARING_REQUEST_FAILED.getMessage()+":"+e.getCustomErrorMsg(), null,null); + } + + JSONObject result = JSON.parseObject(response); + return new PayShareResult(true, null,"success", result,result.getString("order_id")); + } + + //无需分账,直接解冻 @Override public PayShareResult noReciverShare(WxAppinfo appInfo,WxPayAccount payAccount,WxProfitSharingOrder record) { V3PayShareUnfreezeReq req = new V3PayShareUnfreezeReq(); @@ -178,6 +200,30 @@ public class WxPayShareV3Service extends PayShareBaseAdapterService{ } + @Override + public PayShareQueryResult shareQuery(WxAppinfo appInfo, WxPayAccount payAccount, ProductOrderSharing record) throws MallinkException { + V3PayShareQueryReq req = new V3PayShareQueryReq(); + req.setTransaction_id(record.getTransactionId()); + req.setOut_order_no(record.getOutSettleNo()); + WxPayService payService = maUtil.getWxPayService(appInfo, payAccount); + String response = null; + try { + response = WxPayV3.shareQuery(payService, req); + if (StringUtils.isBlank(response)) { + throw new MallinkException(EnumProfitSharingOrderStatus.PROFIT_SHARING_REQ_FAILED.getCode(),"分账请求失败.返回值为空"); + } + } catch (WxPayException e) { + log.error("weixin pay v3 share error.",e); + throw new MallinkException(ErrorCode.PROFIT_SHARING_QUERY_REQUEST_FAILED.getCode(), ErrorCode.PROFIT_SHARING_QUERY_REQUEST_FAILED.getMessage()+e.getCustomErrorMsg()); + } + JSONObject result = JSON.parseObject(response); + String return_code = result.getString("state"); + if (!"FINISHED".equals(return_code)) { + throw new MallinkException(ErrorCode.PROFIT_SHARING_QUERY_REQUEST_FAILED.getCode(), "分账状态:"+return_code); + } + return new PayShareQueryResult(true, 200, "success",this.getReceivers(JSON.toJSONString(result.get("receivers")))); + } + @Override public PayShareQueryResult shareQuery(WxAppinfo appInfo, WxPayAccount payAccount, WxProfitSharingOrder record) throws MallinkException { V3PayShareQueryReq req = new V3PayShareQueryReq(); @@ -211,7 +257,7 @@ public class WxPayShareV3Service extends PayShareBaseAdapterService{ if (StringUtils.isBlank(out_order_no) || !out_order_no.equals(record.getId().toString())){ throw new MallinkException(ErrorCode.PROFIT_SHARING_QUERY_RETURN_INVALID.getCode(),"out_order_no:["+out_order_no+"] WxProfitSharingOrder:["+record.getId()+"]"); } - return new PayShareQueryResult(true, 200, "success",result, this.getReceivers(JSON.toJSONString(result.get("receivers")))); + return new PayShareQueryResult(true, 200, "success",this.getReceivers(JSON.toJSONString(result.get("receivers")))); } diff --git a/suimangService/src/main/java/com/iformall/service/pay/service/share/wx/v3/entity/V3PayShareQueryReq.java b/suimangService/src/main/java/com/iformall/service/pay/service/share/wx/v3/entity/V3PayShareQueryReq.java index 2ddac26..0211f54 100644 --- a/suimangService/src/main/java/com/iformall/service/pay/service/share/wx/v3/entity/V3PayShareQueryReq.java +++ b/suimangService/src/main/java/com/iformall/service/pay/service/share/wx/v3/entity/V3PayShareQueryReq.java @@ -9,6 +9,6 @@ public class V3PayShareQueryReq { private String sub_mchid;//微信支付分配的子商户号,即分账的出资商户号。 private String transaction_id;//微信支付订单号 - @JSONField(serialize = false) +// @JSONField(serialize = false) private String out_order_no;//商户订单号 } diff --git a/suimangService/src/main/resources/mapper/ProductOrderSharingMapper.xml b/suimangService/src/main/resources/mapper/ProductOrderSharingMapper.xml new file mode 100644 index 0000000..9540d5d --- /dev/null +++ b/suimangService/src/main/resources/mapper/ProductOrderSharingMapper.xml @@ -0,0 +1,92 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + `id`,`tenant_id`,`parent_tenant_id`,`out_order_no`,`order_price`,`pay_way`,`transaction_id`,`project_type`,`pay_vendor`, + `out_settle_no`,`settle_desc`,`settle_no`,`settle_amount`,`settle_status`,`settle_msg`, + `settle_detail`,`rake`,`commission`,`create_date`,`update_date` + + + + where 1=1 + + + and `id` = #{id} + + + and `out_order_no` = #{outSettleNo} + + + and `pay_way` = #{payWay} + + + and `transaction_id` = #{transactioniId} + + + + and `project_type` = #{projectType} + + + + and `pay_vendor` = #{payVendor} + + + + and `out_settle_no` = #{outSettleNo} + + + + and `settle_no` = #{settleNo} + + + + and `settle_status` = #{settleStatus} + + + + and `create_date` >= #{startDate} + + + and `create_date` <= #{endDate} + + + + and id in + + #{idItem} + + + order by ${sortColumns} + + + + +