|
|
@@ -63,6 +63,8 @@ public class OrderRefundServiceImpl implements OrderRefundService {
|
|
|
|
|
|
private final RefundUpgradeOrderDonMapper refundUpgradeOrderDonMapper;
|
|
|
|
|
|
+ private final SpotifyUserUpgradeOrderMapper spotifyUserUpgradeOrderMapper;
|
|
|
+
|
|
|
@Override
|
|
|
public String centerRefund(OrderRefundReq refundReq, OrderDon orderDon) throws Exception {
|
|
|
OrderDon.Type type = orderDon.getType();
|
|
|
@@ -432,6 +434,50 @@ public class OrderRefundServiceImpl implements OrderRefundService {
|
|
|
return outRefundNo;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public void refundSpotifyUpgrade(Long orderId) throws Exception {
|
|
|
+ SpotifyUserUpgradeOrder order = spotifyUserUpgradeOrderMapper.selectById(orderId);
|
|
|
+ if (order == null) {
|
|
|
+ throw BusinessRuntimeException.getInstance("订单不存在");
|
|
|
+ }
|
|
|
+ if (order.getStatus() != SpotifyUserUpgradeOrder.Status.hasPayment) {
|
|
|
+ throw BusinessRuntimeException.getInstance("订单状态异常");
|
|
|
+ }
|
|
|
+ BigDecimal money = order.getMoney();
|
|
|
+ if (money.compareTo(BigDecimal.ZERO) <=0){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ AlipayTradeRefundResponse response;
|
|
|
+ //支付宝退款
|
|
|
+ AlipayClient alipayClient = AliPayClientFactory.getAlipayClient(Optional.ofNullable(order.getShopId()).orElse(ShopConfig.ZFB_DEFAULT_APP_ID));
|
|
|
+ AlipayTradeRefundRequest request = new AlipayTradeRefundRequest();
|
|
|
+ AlipayTradeRefundModel model = new AlipayTradeRefundModel();
|
|
|
+ //支付宝交易号
|
|
|
+ model.setTradeNo(order.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(order.getId()))
|
|
|
+ .toHexString();
|
|
|
+ log.info("spotify升级订单oid:{}退款订单号:{}", orderId, outRefundNo);
|
|
|
+ //退款请求号
|
|
|
+ model.setOutRequestNo(outRefundNo);
|
|
|
+ request.setBizModel(model);
|
|
|
+ String shopId = order.getShopId();
|
|
|
+ ShopConfig shopConfig = shopConfigMapper.selectOne(Wrappers.lambdaQuery(ShopConfig.class).eq(ShopConfig::getAppId, order.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());
|
|
|
+ order.setStatus(SpotifyUserUpgradeOrder.Status.refund);
|
|
|
+ spotifyUserUpgradeOrderMapper.updateById(order);
|
|
|
+ }
|
|
|
+
|
|
|
private String zfbRefundWholesaleOrder(GoodsWholesaleOrderDon orderDon) throws Exception {
|
|
|
BigDecimal money = orderDon.getRefundMoney();
|
|
|
if (money.compareTo(BigDecimal.ZERO) <=0){
|