@@ -1,8 +1,10 @@ | |||||
package com.iformall.schedule; | package com.iformall.schedule; | ||||
import com.iformall.domain.po.ProductOrder; | import com.iformall.domain.po.ProductOrder; | ||||
import com.iformall.domain.po.ProductOrderSharing; | |||||
import com.iformall.enums.*; | import com.iformall.enums.*; | ||||
import com.iformall.service.ProductOrderService; | import com.iformall.service.ProductOrderService; | ||||
import com.iformall.service.ProductOrderSharingService; | |||||
import com.iformall.utils.DateUtils; | import com.iformall.utils.DateUtils; | ||||
import org.slf4j.Logger; | import org.slf4j.Logger; | ||||
import org.slf4j.LoggerFactory; | import org.slf4j.LoggerFactory; | ||||
@@ -20,7 +22,10 @@ public class ProductOrderSharingSchedule { | |||||
@Autowired | @Autowired | ||||
private ProductOrderService productOrderService; | private ProductOrderService productOrderService; | ||||
@Scheduled(cron = "0 15 2 * * ?") // 每天凌晨02:00分账重试 | |||||
@Autowired | |||||
private ProductOrderSharingService productOrderSharingService; | |||||
@Scheduled(cron = "0 15 1 * * ?") // 每天凌晨02:00分账重试 | |||||
public void productOrderSharingSchedule() { | public void productOrderSharingSchedule() { | ||||
ProductOrder productOrderQ = new ProductOrder(); | ProductOrder productOrderQ = new ProductOrder(); | ||||
productOrderQ.setOrderStatus(EnumProductOrderStatus.ORDER_STATUS_PAYMENT_SUCCESS.getCode()); | productOrderQ.setOrderStatus(EnumProductOrderStatus.ORDER_STATUS_PAYMENT_SUCCESS.getCode()); | ||||
@@ -30,6 +35,9 @@ public class ProductOrderSharingSchedule { | |||||
for (ProductOrder order: orderList) { | for (ProductOrder order: orderList) { | ||||
try{ | try{ | ||||
productOrderService.handldSharing(order); | productOrderService.handldSharing(order); | ||||
productOrderSharingService.sharingOrder(order.getId()); | |||||
}catch(Exception e){ | }catch(Exception e){ | ||||
logger.error("分账失败:" + e.getMessage()); | 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<ProductOrderSharing> 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<ProductOrderSharing> sharingList = productOrderSharingService.findList(productOrderSharingQ); | |||||
for (ProductOrderSharing sharing: sharingList) { | |||||
try{ | |||||
productOrderSharingService.handleSharingOrder(sharing.getId()); | |||||
}catch(Exception e){ | |||||
logger.error("分账失败:" + e.getMessage()); | |||||
} | |||||
} | |||||
} | |||||
} | } |
@@ -64,7 +64,7 @@ public class ProductOrder extends TenantEntity { | |||||
@io.swagger.annotations.ApiModelProperty(value="支付时间",name="paymentTime") | @io.swagger.annotations.ApiModelProperty(value="支付时间",name="paymentTime") | ||||
private Date paymentTime; | private Date paymentTime; | ||||
@io.swagger.annotations.ApiModelProperty(value="支付时间",name="paymentTime") | |||||
@io.swagger.annotations.ApiModelProperty(value="支付渠道",name="payWay") | |||||
private Integer payWay; | private Integer payWay; | ||||
@@ -1,5 +1,6 @@ | |||||
package com.iformall.domain.po; | package com.iformall.domain.po; | ||||
import com.baomidou.mybatisplus.annotation.TableField; | |||||
import com.baomidou.mybatisplus.annotation.TableName; | import com.baomidou.mybatisplus.annotation.TableName; | ||||
import com.iformall.domain.po.base.TenantEntity; | import com.iformall.domain.po.base.TenantEntity; | ||||
import lombok.Data; | import lombok.Data; | ||||
@@ -20,6 +21,9 @@ public class ProductOrderSharing extends TenantEntity { | |||||
@io.swagger.annotations.ApiModelProperty(value="订单价格",name="orderPrice") | @io.swagger.annotations.ApiModelProperty(value="订单价格",name="orderPrice") | ||||
private Integer orderPrice; | private Integer orderPrice; | ||||
@io.swagger.annotations.ApiModelProperty(value="支付渠道",name="payWay") | |||||
private Integer payWay; | |||||
@io.swagger.annotations.ApiModelProperty(value="平台支付单号",name="transactionId") | @io.swagger.annotations.ApiModelProperty(value="平台支付单号",name="transactionId") | ||||
private String transactionId; | private String transactionId; | ||||
@@ -43,10 +47,12 @@ public class ProductOrderSharing extends TenantEntity { | |||||
@io.swagger.annotations.ApiModelProperty(value = "EnumProductOrderSettleStatus", name = "settleStatus") | @io.swagger.annotations.ApiModelProperty(value = "EnumProductOrderSettleStatus", name = "settleStatus") | ||||
private Integer settleStatus; | private Integer settleStatus; | ||||
@io.swagger.annotations.ApiModelProperty(value="",name="settleMsg") | |||||
private String settleMsg; | |||||
@io.swagger.annotations.ApiModelProperty(value="",name="settleDetail") | @io.swagger.annotations.ApiModelProperty(value="",name="settleDetail") | ||||
private String settleDetail; | private String settleDetail; | ||||
@io.swagger.annotations.ApiModelProperty(value="手续费",name="rake") | @io.swagger.annotations.ApiModelProperty(value="手续费",name="rake") | ||||
private Integer rake; | private Integer rake; | ||||
@io.swagger.annotations.ApiModelProperty(value="佣金",name="commission") | @io.swagger.annotations.ApiModelProperty(value="佣金",name="commission") | ||||
@@ -57,4 +63,10 @@ public class ProductOrderSharing extends TenantEntity { | |||||
@io.swagger.annotations.ApiModelProperty(value="创建时间",name="createDate") | @io.swagger.annotations.ApiModelProperty(value="创建时间",name="createDate") | ||||
private Date createDate; | private Date createDate; | ||||
@TableField(exist = false) | |||||
private Date startDate; | |||||
@TableField(exist = false) | |||||
private Date endDate; | |||||
} | } |
@@ -344,8 +344,11 @@ public class DouYinPayHelper { | |||||
QuerySettleResult result = new QuerySettleResult(); | QuerySettleResult result = new QuerySettleResult(); | ||||
result.setSettleNo(info.getString("settle_no")); | result.setSettleNo(info.getString("settle_no")); | ||||
result.setSettleAmount(info.getInteger("settle_amount")); | result.setSettleAmount(info.getInteger("settle_amount")); | ||||
result.setRake(info.getInteger("rake")); | |||||
result.setCommission(info.getInteger("commission")); | |||||
result.setSettleStatus(info.getString("settle_status")); | 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; | return result; | ||||
}else { | }else { | ||||
log.error("settleQuery reponse error. request: "+JSON.toJSONString(map)+" response:"+response); | log.error("settleQuery reponse error. request: "+JSON.toJSONString(map)+" response:"+response); | ||||
@@ -8,5 +8,8 @@ public class QuerySettleResult { | |||||
private String settleNo;//担保支付侧的分账单号 | private String settleNo;//担保支付侧的分账单号 | ||||
private Integer settleAmount;//分账金额,单位[分] | private Integer settleAmount;//分账金额,单位[分] | ||||
private String settleStatus;//分账状态,成功-SUCCESS;失败-FAIL | private String settleStatus;//分账状态,成功-SUCCESS;失败-FAIL | ||||
private String settleDetail; | |||||
private Integer rake; | |||||
private Integer commission; | |||||
private String msg; | private String msg; | ||||
} | } |
@@ -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<ProductOrderSharing, Long>{ | |||||
List<ProductOrderSharing> findList(ProductOrderSharing record); | |||||
} |
@@ -33,4 +33,5 @@ public interface ProductOrderService { | |||||
List<ProductOrder> findList(ProductOrder record); | List<ProductOrder> findList(ProductOrder record); | ||||
void handldSharing(ProductOrder order); | void handldSharing(ProductOrder order); | ||||
} | } |
@@ -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<ProductOrderSharing> listAsPage(ProductOrderSharing record, Integer pageIndex, Integer pageSize); | |||||
List<ProductOrderSharing> findList(ProductOrderSharing record); | |||||
void sharingOrder(Long id); | |||||
void handleSharingOrder(Long id); | |||||
} |
@@ -16,4 +16,5 @@ public interface ProductService { | |||||
PageInfo<Product> listAsPage(Product record, Integer pageIndex, Integer pageSize); | PageInfo<Product> listAsPage(Product record, Integer pageIndex, Integer pageSize); | ||||
Product getById(Long id); | Product getById(Long id); | ||||
} | } |
@@ -6,12 +6,11 @@ import com.iformall.common.ErrorCode; | |||||
import com.iformall.common.IdWorker; | import com.iformall.common.IdWorker; | ||||
import com.iformall.common.ResultData; | import com.iformall.common.ResultData; | ||||
import com.iformall.domain.po.*; | 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.exception.MallinkException; | ||||
import com.iformall.mapper.ProductMapper; | import com.iformall.mapper.ProductMapper; | ||||
import com.iformall.mapper.ProductOrderMapper; | import com.iformall.mapper.ProductOrderMapper; | ||||
import com.iformall.mapper.ProductOrderSharingMapper; | |||||
import com.iformall.service.ProductOrderService; | import com.iformall.service.ProductOrderService; | ||||
import com.iformall.service.UserBasicPropertyService; | import com.iformall.service.UserBasicPropertyService; | ||||
import com.iformall.service.WxAppinfoService; | import com.iformall.service.WxAppinfoService; | ||||
@@ -42,6 +41,9 @@ public class ProductOrderServiceImpl implements ProductOrderService { | |||||
@Autowired | @Autowired | ||||
ProductOrderMapper productOrderMapper; | ProductOrderMapper productOrderMapper; | ||||
@Autowired | |||||
ProductOrderSharingMapper productOrderSharingMapper; | |||||
@Autowired | @Autowired | ||||
ProductMapper productMapper; | ProductMapper productMapper; | ||||
@@ -200,12 +202,35 @@ public class ProductOrderServiceImpl implements ProductOrderService { | |||||
@Override | @Override | ||||
@Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) | @Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) | ||||
public void handldSharing(ProductOrder order) { | 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); | |||||
} | } | ||||
@@ -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<ProductOrderSharing> listAsPage(ProductOrderSharing record, Integer pageIndex, Integer pageSize) { | |||||
return PageHelper.startPage(pageIndex, pageSize).doSelectPageInfo(() -> productOrderSharingFromMapper.findList(record)); | |||||
} | |||||
@Override | |||||
public List<ProductOrderSharing> 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); | |||||
} | |||||
} |
@@ -636,7 +636,7 @@ public class WxProfitSharingOrderServiceImpl implements WxProfitSharingOrderServ | |||||
// } | // } | ||||
// } | // } | ||||
// } | // } | ||||
return new ResultData(payShareQueryResult.getData()); | |||||
return new ResultData(payShareQueryResult); | |||||
} | } | ||||
@Override | @Override | ||||
@@ -47,6 +47,15 @@ public interface PayShareAdapterService { | |||||
* @return | * @return | ||||
*/ | */ | ||||
WxProfitSharingReceiver getReceiver(TenantEntity tenantEntity, Long merchantId, Integer ttPayWay,Integer mchType); | 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分账 | * 无分账接收方分账 ,钱直接分给小程序方 调用API分账 | ||||
@@ -71,7 +80,17 @@ public interface PayShareAdapterService { | |||||
* @throws MallinkException | * @throws MallinkException | ||||
*/ | */ | ||||
public PayShareResult haveReciversShare(WxAppinfo appInfo,WxPayAccount payAccount,WxProfitSharingOrder record,JSONArray receivers) 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 | * @param appInfo | ||||
@@ -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.service.pay.service.share.entity.ShareNotifyAdapterResult; | ||||
import com.iformall.utils.*; | import com.iformall.utils.*; | ||||
import lombok.extern.slf4j.Slf4j; | import lombok.extern.slf4j.Slf4j; | ||||
import org.apache.commons.lang3.StringUtils; | |||||
import org.springframework.beans.factory.annotation.Autowired; | import org.springframework.beans.factory.annotation.Autowired; | ||||
import org.springframework.beans.factory.annotation.Qualifier; | import org.springframework.beans.factory.annotation.Qualifier; | ||||
import org.springframework.context.annotation.Lazy; | 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 { | public PayShareQueryResult shareQuery(WxAppinfo appInfo, WxPayAccount payAccount, WxProfitSharingOrder record) throws MallinkException { | ||||
try { | try { | ||||
TtPayService ttPayService = maUtil.getTtPayService(appInfo, payAccount); | TtPayService ttPayService = maUtil.getTtPayService(appInfo, payAccount); | ||||
@@ -230,9 +253,9 @@ public class TtPayShareService extends PayShareBaseAdapterService{ | |||||
if(profitSharingResult.isSuccess()){ | if(profitSharingResult.isSuccess()){ | ||||
ProfitSharingResult.Receiver receiver = profitSharingResult.getData().get(0); | ProfitSharingResult.Receiver receiver = profitSharingResult.getData().get(0); | ||||
if("SUCCESS".equals(receiver.getSettleStatus())){ | 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())){ | } 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()); | 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); | |||||
} | |||||
} | |||||
} | } |
@@ -12,10 +12,25 @@ public class PayShareQueryResult implements Serializable{ | |||||
private static final long serialVersionUID = -3701322871877301001L; | private static final long serialVersionUID = -3701322871877301001L; | ||||
public PayShareQueryResult(){ | |||||
} | |||||
public PayShareQueryResult(boolean isSuccess,Integer code,String msg,List<PayShareQueryResultReceivers> receivers){ | |||||
this.isSuccess = isSuccess; | |||||
this.code = code; | |||||
this.msg = msg; | |||||
this.receivers = receivers; | |||||
} | |||||
private boolean isSuccess; | private boolean isSuccess; | ||||
private Integer code; | private Integer code; | ||||
private String msg; | private String msg; | ||||
private Object data; | |||||
private String detail; | |||||
private Integer rake; | |||||
private Integer commission; | |||||
private List<PayShareQueryResultReceivers> receivers;//数组字符串,平台查询返回的分账账户列表 | private List<PayShareQueryResultReceivers> receivers;//数组字符串,平台查询返回的分账账户列表 | ||||
@@ -95,6 +95,11 @@ public class WxPayShareSFTService extends PayShareBaseAdapterService{ | |||||
} | } | ||||
@Override | |||||
public PayShareQueryResult shareQuery(WxAppinfo appInfo, WxPayAccount payAccount, ProductOrderSharing record) throws MallinkException { | |||||
return null; | |||||
} | |||||
@Override | @Override | ||||
public PayShareQueryResult shareQuery(WxAppinfo appInfo, WxPayAccount payAccount, WxProfitSharingOrder record) throws MallinkException { | public PayShareQueryResult shareQuery(WxAppinfo appInfo, WxPayAccount payAccount, WxProfitSharingOrder record) throws MallinkException { | ||||
return null; | return null; | ||||
@@ -160,5 +165,10 @@ public class WxPayShareSFTService extends PayShareBaseAdapterService{ | |||||
return null; | return null; | ||||
} | } | ||||
@Override | |||||
public PayShareResult noReciverShare(WxAppinfo appInfo, WxPayAccount payAccount, ProductOrderSharing record) { | |||||
return null; | |||||
} | |||||
} | } |
@@ -182,7 +182,12 @@ public class WxPayShareService extends PayShareBaseAdapterService{ | |||||
return new PayShareResult(true, null, "success",returnMap, returnMap.get("order_id")); | 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 { | public PayShareQueryResult shareQuery(WxAppinfo appInfo, WxPayAccount payAccount, WxProfitSharingOrder record) throws MallinkException { | ||||
WxProfitSharingQueryP wxProfitSharingQueryP = new WxProfitSharingQueryP();; | WxProfitSharingQueryP wxProfitSharingQueryP = new WxProfitSharingQueryP();; | ||||
wxProfitSharingQueryP.setMch_id(payAccount.getMchId()); | wxProfitSharingQueryP.setMch_id(payAccount.getMchId()); | ||||
@@ -219,7 +224,7 @@ public class WxPayShareService extends PayShareBaseAdapterService{ | |||||
} | } | ||||
Integer code = (Integer) statusMap.get(returnMap.get("status")); | 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; | return record; | ||||
} | } | ||||
@Override | |||||
public PayShareResult noReciverShare(WxAppinfo appInfo, WxPayAccount payAccount, ProductOrderSharing record) { | |||||
return null; | |||||
} | |||||
private static String queryOrderShareAmount(String mchId,String transcationId,String apiKey) { | private static String queryOrderShareAmount(String mchId,String transcationId,String apiKey) { | ||||
WxProfitSharingP psCmd = new WxProfitSharingP(); | WxProfitSharingP psCmd = new WxProfitSharingP(); | ||||
psCmd.setMch_id(mchId);//服务商商户id | psCmd.setMch_id(mchId);//服务商商户id | ||||
@@ -98,7 +98,29 @@ public class WxPayShareV3Service extends PayShareBaseAdapterService{ | |||||
return null; | 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 | @Override | ||||
public PayShareResult noReciverShare(WxAppinfo appInfo,WxPayAccount payAccount,WxProfitSharingOrder record) { | public PayShareResult noReciverShare(WxAppinfo appInfo,WxPayAccount payAccount,WxProfitSharingOrder record) { | ||||
V3PayShareUnfreezeReq req = new V3PayShareUnfreezeReq(); | 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 | @Override | ||||
public PayShareQueryResult shareQuery(WxAppinfo appInfo, WxPayAccount payAccount, WxProfitSharingOrder record) throws MallinkException { | public PayShareQueryResult shareQuery(WxAppinfo appInfo, WxPayAccount payAccount, WxProfitSharingOrder record) throws MallinkException { | ||||
V3PayShareQueryReq req = new V3PayShareQueryReq(); | 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())){ | 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()+"]"); | 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")))); | |||||
} | } | ||||
@@ -9,6 +9,6 @@ public class V3PayShareQueryReq { | |||||
private String sub_mchid;//微信支付分配的子商户号,即分账的出资商户号。 | private String sub_mchid;//微信支付分配的子商户号,即分账的出资商户号。 | ||||
private String transaction_id;//微信支付订单号 | private String transaction_id;//微信支付订单号 | ||||
@JSONField(serialize = false) | |||||
// @JSONField(serialize = false) | |||||
private String out_order_no;//商户订单号 | private String out_order_no;//商户订单号 | ||||
} | } |
@@ -0,0 +1,92 @@ | |||||
<?xml version="1.0" encoding="UTF-8"?> | |||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | |||||
<mapper namespace="com.iformall.mapper.ProductOrderSharingMapper"> | |||||
<resultMap id="BaseResultMap" type="com.iformall.domain.po.ProductOrderSharing"> | |||||
<id column="id" jdbcType="BIGINT" property="id" /> | |||||
<result column="tenant_id" jdbcType="VARCHAR" property="tenantId" /> | |||||
<result column="parent_tenant_id" jdbcType="VARCHAR" property="parentTenantId"/> | |||||
<result column="out_order_no" jdbcType="VARCHAR" property="outOrderNo"/> | |||||
<result column="order_price" jdbcType="INTEGER" property="orderPrice"/> | |||||
<result column="pay_way" jdbcType="INTEGER" property="payWay"/> | |||||
<result column="transaction_id" jdbcType="VARCHAR" property="transactionId"/> | |||||
<result column="project_type" jdbcType="INTEGER" property="projectType"/> | |||||
<result column="pay_vendor" jdbcType="INTEGER" property="payVendor"/> | |||||
<result column="out_settle_no" jdbcType="VARCHAR" property="outSettleNo" /> | |||||
<result column="settle_desc" jdbcType="VARCHAR" property="settleDesc"/> | |||||
<result column="settle_no" jdbcType="VARCHAR" property="settleNo" /> | |||||
<result column="settle_amount" jdbcType="INTEGER" property="settleAmount"/> | |||||
<result column="settle_status" jdbcType="INTEGER" property="settleStatus"/> | |||||
<result column="settle_msg" jdbcType="VARCHAR" property="settleMsg" /> | |||||
<result column="settle_detail" jdbcType="VARCHAR" property="settleDetail" /> | |||||
<result column="rake" jdbcType="INTEGER" property="rake"/> | |||||
<result column="commission" jdbcType="INTEGER" property="commission"/> | |||||
<result column="create_date" jdbcType="TIMESTAMP" property="createDate" /> | |||||
<result column="update_date" jdbcType="TIMESTAMP" property="updateDate" /> | |||||
</resultMap> | |||||
<sql id="allColumns"> | |||||
`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` | |||||
</sql> | |||||
<sql id="dynamicWhereConditions"> | |||||
where 1=1 | |||||
<if test=" null != id "> | |||||
and `id` = #{id} | |||||
</if> | |||||
<if test=" null != outOrderNo and '' != outSettleNo"> | |||||
and `out_order_no` = #{outSettleNo} | |||||
</if> | |||||
<if test=" null != payWay"> | |||||
and `pay_way` = #{payWay} | |||||
</if> | |||||
<if test=" null != transactioniId and '' != transactioniId"> | |||||
and `transaction_id` = #{transactioniId} | |||||
</if> | |||||
<if test=" null != projectType"> | |||||
and `project_type` = #{projectType} | |||||
</if> | |||||
<if test=" null != payVendor"> | |||||
and `pay_vendor` = #{payVendor} | |||||
</if> | |||||
<if test=" null != outSettleNo and '' != outSettleNo"> | |||||
and `out_settle_no` = #{outSettleNo} | |||||
</if> | |||||
<if test=" null != settleNo and '' != settleNo"> | |||||
and `settle_no` = #{settleNo} | |||||
</if> | |||||
<if test=" null != settleStatus "> | |||||
and `settle_status` = #{settleStatus} | |||||
</if> | |||||
<if test=" null != startDate "> | |||||
and `create_date` >= #{startDate} | |||||
</if> | |||||
<if test=" null != endDate"> | |||||
and `create_date` <= #{endDate} | |||||
</if> | |||||
<if test=" null != ids "> | |||||
and id in | |||||
<foreach collection="ids" index="index" item="idItem" open="(" separator="," close=")"> | |||||
#{idItem} | |||||
</foreach> | |||||
</if> | |||||
<if test=" null != sortColumns"> order by ${sortColumns} </if> | |||||
</sql> | |||||
<select id="findList" parameterType="com.iformall.domain.po.ProductOrderSharing" resultMap="BaseResultMap"> | |||||
select | |||||
<include refid="allColumns"/> | |||||
from product_order_sharing | |||||
<include refid="dynamicWhereConditions" /> | |||||
</select> | |||||
</mapper> |