|
|
@@ -157,6 +157,29 @@ public class OrderRefundServiceImpl implements OrderRefundService {
|
|
|
return StrUtil.EMPTY;
|
|
|
}
|
|
|
|
|
|
+ private String wxRefundWholesaleOrder(GoodsWholesaleOrderDon orderDon) throws Exception {
|
|
|
+ BigDecimal money = orderDon.getRefundMoney();
|
|
|
+ if (money.compareTo(BigDecimal.ZERO) <=0){
|
|
|
+ return StrUtil.EMPTY;
|
|
|
+ }
|
|
|
+ long time = System.currentTimeMillis();
|
|
|
+ //退款订单号
|
|
|
+ String outRefundNo = Codec.DoDigest.custom()
|
|
|
+ .setAlgorithm(Codec.DoDigest.Algorithm.MD5)
|
|
|
+ .setStringData(time + String.valueOf(orderDon.getId()))
|
|
|
+ .toHexString();
|
|
|
+ log.info("退押金退款订单号:{}", outRefundNo);
|
|
|
+ weChatService.refundWxOrder(weChatConfig.getAppid(),
|
|
|
+ Optional.ofNullable(orderDon.getShopId()).orElse(ShopConfig.WX_DEFAULT_APP_ID),
|
|
|
+ orderDon.getTransactionId(),
|
|
|
+ outRefundNo,
|
|
|
+ money,
|
|
|
+ money,
|
|
|
+ weChatConfig.getDomain() + "manage/goods/whole/sale/deposit/refund/notify");
|
|
|
+ //记录退款信息
|
|
|
+ return outRefundNo;
|
|
|
+ }
|
|
|
+
|
|
|
private String zfbRefundWholesaleUserDeposit(GoodsWholesaleUserDeposit goodsWholesaleUserDeposit) throws Exception {
|
|
|
BigDecimal money = goodsWholesaleUserDeposit.getMoney();
|
|
|
if (money.compareTo(BigDecimal.ZERO) <=0){
|
|
|
@@ -355,4 +378,50 @@ public class OrderRefundServiceImpl implements OrderRefundService {
|
|
|
apiContext.setConfigurationMap(sdkConfig);
|
|
|
return apiContext;
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public String refundWholesaleOrder(GoodsWholesaleOrderDon orderDon) throws Exception {
|
|
|
+ GoodsWholesaleOrderDon.Type type = orderDon.getType();
|
|
|
+ if (type == GoodsWholesaleOrderDon.Type.WeChat) {
|
|
|
+ return wxRefundWholesaleOrder(orderDon);
|
|
|
+ }
|
|
|
+ if (type == GoodsWholesaleOrderDon.Type.ALI_PAY) {
|
|
|
+ return zfbRefundWholesaleOrder(orderDon);
|
|
|
+ }
|
|
|
+ return StrUtil.EMPTY;
|
|
|
+ }
|
|
|
+
|
|
|
+ private String zfbRefundWholesaleOrder(GoodsWholesaleOrderDon orderDon) throws Exception {
|
|
|
+ BigDecimal money = orderDon.getRefundMoney();
|
|
|
+ if (money.compareTo(BigDecimal.ZERO) <=0){
|
|
|
+ return StrUtil.EMPTY;
|
|
|
+ }
|
|
|
+ AlipayTradeRefundResponse response;
|
|
|
+ //支付宝退款
|
|
|
+ AlipayClient alipayClient = AliPayClientFactory.getAlipayClient(Optional.ofNullable(orderDon.getShopId()).orElse(ShopConfig.ZFB_DEFAULT_APP_ID));
|
|
|
+ AlipayTradeRefundRequest request = new AlipayTradeRefundRequest();
|
|
|
+ AlipayTradeRefundModel model = new AlipayTradeRefundModel();
|
|
|
+ //支付宝交易号
|
|
|
+ model.setTradeNo(orderDon.getTransactionId());
|
|
|
+ model.setRefundAmount(money.divide(BigDecimal.valueOf(100), 2, RoundingMode.HALF_EVEN).toString());
|
|
|
+ model.setQueryOptions(List.of("gmt_refund_pay"));
|
|
|
+ long time = System.currentTimeMillis();
|
|
|
+ //退款订单号
|
|
|
+ String outRefundNo = Codec.DoDigest.custom()
|
|
|
+ .setAlgorithm(Codec.DoDigest.Algorithm.MD5)
|
|
|
+ .setStringData(time + String.valueOf(orderDon.getId()))
|
|
|
+ .toHexString();
|
|
|
+ //退款请求号
|
|
|
+ model.setOutRequestNo(outRefundNo);
|
|
|
+ request.setBizModel(model);
|
|
|
+ String shopId = orderDon.getShopId();
|
|
|
+ ShopConfig shopConfig = shopConfigMapper.selectOne(Wrappers.lambdaQuery(ShopConfig.class).eq(ShopConfig::getAppId, orderDon.getShopId()));
|
|
|
+ if (shopId != null && shopConfig != null && shopConfig.getIsCert()) {
|
|
|
+ response = alipayClient.certificateExecute(request);
|
|
|
+ } else {
|
|
|
+ response = alipayClient.execute(request);
|
|
|
+ }
|
|
|
+ if (!response.isSuccess()) throw BusinessRuntimeException.getInstance("退款失败,e:{0}", response.getSubMsg());
|
|
|
+ return outRefundNo;
|
|
|
+ }
|
|
|
}
|