瀏覽代碼

修改退款

Yangzw 3 周之前
父節點
當前提交
dfc744bfbd

+ 60 - 61
feifan-module-mall/feifan-module-trade-biz/src/main/java/cn/newfeifan/mall/module/trade/service/aftersale/AfterSaleServiceImpl.java

@@ -54,8 +54,6 @@ import com.google.common.collect.Maps;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
-import org.springframework.transaction.support.TransactionSynchronization;
-import org.springframework.transaction.support.TransactionSynchronizationManager;
 import org.springframework.validation.annotation.Validated;
 
 import javax.annotation.Resource;
@@ -244,8 +242,8 @@ public class AfterSaleServiceImpl implements AfterSaleService {
         AfterSaleLogUtils.setAfterSaleInfo(afterSale.getId(), afterSale.getStatus(), newStatus);
 
         // TODO 发送售后消息
-        if(afterSale.getWay().equals(AfterSaleWayEnum.RETURN_AND_REFUND.getWay())){
-            sentWcChatMessage(afterSale,AfterSaleStatusEnum.SELLER_AGREE.getContent());
+        if (afterSale.getWay().equals(AfterSaleWayEnum.RETURN_AND_REFUND.getWay())) {
+            sentWcChatMessage(afterSale, AfterSaleStatusEnum.SELLER_AGREE.getContent());
         }
     }
 
@@ -266,7 +264,7 @@ public class AfterSaleServiceImpl implements AfterSaleService {
         AfterSaleLogUtils.setAfterSaleInfo(afterSale.getId(), afterSale.getStatus(), newStatus);
 
         // 发送给微信用户售后消息
-        sentWcChatMessage(afterSale,AfterSaleStatusEnum.SELLER_DISAGREE.getContent());
+        sentWcChatMessage(afterSale, AfterSaleStatusEnum.SELLER_DISAGREE.getContent());
 
         // 更新交易订单项的售后状态为【未申请】
         tradeOrderUpdateService.updateOrderItemWhenAfterSaleCancel(afterSale.getOrderItemId());
@@ -367,7 +365,7 @@ public class AfterSaleServiceImpl implements AfterSaleService {
                 MapUtil.of("reason", refuseReqVO.getRefuseMemo()));
 
         // TODO 发送售后消息
-        sentWcChatMessage(afterSale,AfterSaleStatusEnum.SELLER_REFUSE.getContent());
+        sentWcChatMessage(afterSale, AfterSaleStatusEnum.SELLER_REFUSE.getContent());
 
         // 更新交易订单项的售后状态为【未申请】
         tradeOrderUpdateService.updateOrderItemWhenAfterSaleCancel(afterSale.getOrderItemId());
@@ -421,67 +419,67 @@ public class AfterSaleServiceImpl implements AfterSaleService {
         PtDailyBillDO ptDailyBill = ptDailyBillService.getPtDailyBill(tradeOrderDO.getCreateTime().toLocalDate());
 
         //记录退还积分
-        if(payIntegral>0) {
+        if (payIntegral > 0) {
             TradeOrderItemDO toid = new TradeOrderItemDO();
             toid.setId(tradeOrderItemDO.getId());
             toid.setRefundIntegral(payIntegral);
             tradeOrderItemMapper.updateById(toid);
 
-            if(tradeOrderDO.getRefundIntegral() != null){
-                tradeOrderDO.setRefundIntegral(tradeOrderDO.getRefundIntegral()+payIntegral);
-            }else{
+            if (tradeOrderDO.getRefundIntegral() != null) {
+                tradeOrderDO.setRefundIntegral(tradeOrderDO.getRefundIntegral() + payIntegral);
+            } else {
                 tradeOrderDO.setRefundIntegral(payIntegral);
             }
             tradeOrderMapper.updateById(tradeOrderDO);
 
             //退回退款订单项,购物者支付的积分
-            integralService.updateUserIntegral(orderUserId,orderUserId, CaclEnum.ORDER_REFUND_INTEGRAL, payIntegral, 0L, tradeOrderId, tradeOrderNum);
+            integralService.updateUserIntegral(orderUserId, orderUserId, CaclEnum.ORDER_REFUND_INTEGRAL, payIntegral, 0L, tradeOrderId, tradeOrderNum);
 
-            if(dailyBill != null){
+            if (dailyBill != null) {
                 //有就追加退回积分
-                dailyBill.setRefundIntegral(dailyBill.getRefundIntegral()+payIntegral);
-                dailyBill.setReceivedIntegral(dailyBill.getReceivedIntegral()-payIntegral);
+                dailyBill.setRefundIntegral(dailyBill.getRefundIntegral() + payIntegral);
+                dailyBill.setReceivedIntegral(dailyBill.getReceivedIntegral() - payIntegral);
 
-                ptDailyBill.setRefundIntegral(ptDailyBill.getRefundIntegral()+payIntegral);
-                ptDailyBill.setReceivedIntegral(ptDailyBill.getReceivedIntegral()-payIntegral);
+                ptDailyBill.setRefundIntegral(ptDailyBill.getRefundIntegral() + payIntegral);
+                ptDailyBill.setReceivedIntegral(ptDailyBill.getReceivedIntegral() - payIntegral);
             }
         }
 
         //记录退还消费分
-        if(payConsumptionPoints>0) {
+        if (payConsumptionPoints > 0) {
             TradeOrderItemDO toid = new TradeOrderItemDO();
             toid.setId(tradeOrderItemDO.getId());
             toid.setRefundConsumption(payConsumptionPoints);
             tradeOrderItemMapper.updateById(toid);
 
-            if(tradeOrderDO.getRefundConsumption() != null){
-                tradeOrderDO.setRefundConsumption(tradeOrderDO.getRefundConsumption()+payConsumptionPoints);
-            }else{
+            if (tradeOrderDO.getRefundConsumption() != null) {
+                tradeOrderDO.setRefundConsumption(tradeOrderDO.getRefundConsumption() + payConsumptionPoints);
+            } else {
                 tradeOrderDO.setRefundConsumption(payConsumptionPoints);
             }
             tradeOrderMapper.updateById(tradeOrderDO);
 
             //退回退款订单项,购物者支付的消费分
-            integralService.updateUserConsumptionPoints(orderUserId,orderUserId, payConsumptionPoints, tradeOrderId, tradeOrderNum);
+            integralService.updateUserConsumptionPoints(orderUserId, orderUserId, payConsumptionPoints, tradeOrderId, tradeOrderNum);
 
-            if(dailyBill != null){
+            if (dailyBill != null) {
                 //有就追加退回消费分
-                dailyBill.setRefundConsumptionPoints(dailyBill.getRefundConsumptionPoints()+payConsumptionPoints);
-                dailyBill.setReceivedConsumptionPoints(dailyBill.getReceivedConsumptionPoints()-payConsumptionPoints);
+                dailyBill.setRefundConsumptionPoints(dailyBill.getRefundConsumptionPoints() + payConsumptionPoints);
+                dailyBill.setReceivedConsumptionPoints(dailyBill.getReceivedConsumptionPoints() - payConsumptionPoints);
 
-                ptDailyBill.setRefundConsumptionPoints(ptDailyBill.getRefundConsumptionPoints()+payConsumptionPoints);
-                ptDailyBill.setReceivedConsumptionPoints(ptDailyBill.getReceivedConsumptionPoints()-payConsumptionPoints);
+                ptDailyBill.setRefundConsumptionPoints(ptDailyBill.getRefundConsumptionPoints() + payConsumptionPoints);
+                ptDailyBill.setReceivedConsumptionPoints(ptDailyBill.getReceivedConsumptionPoints() - payConsumptionPoints);
             }
         }
 
-        if(dailyBill != null){
+        if (dailyBill != null) {
             //有就追加退款金额
-            dailyBill.setRefundPrice(dailyBill.getRefundPrice()+afterSale.getRefundPrice());
-            dailyBill.setReceivedPrice(dailyBill.getReceivedPrice()-afterSale.getRefundPrice());
-            dailyBillService.updateDailyBill(BeanUtils.toBean(dailyBill,DailyBillSaveReqVO.class));
+            dailyBill.setRefundPrice(dailyBill.getRefundPrice() + afterSale.getRefundPrice());
+            dailyBill.setReceivedPrice(dailyBill.getReceivedPrice() - afterSale.getRefundPrice());
+            dailyBillService.updateDailyBill(BeanUtils.toBean(dailyBill, DailyBillSaveReqVO.class));
 
-            ptDailyBill.setRefundPrice(ptDailyBill.getRefundPrice()+afterSale.getRefundPrice());
-            ptDailyBill.setReceivedPrice(ptDailyBill.getReceivedPrice()-afterSale.getRefundPrice());
+            ptDailyBill.setRefundPrice(ptDailyBill.getRefundPrice() + afterSale.getRefundPrice());
+            ptDailyBill.setReceivedPrice(ptDailyBill.getReceivedPrice() - afterSale.getRefundPrice());
             ptDailyBillService.updatePtDailyBill(BeanUtils.toBean(ptDailyBill, PtDailyBillSaveReqVO.class));
         }
 
@@ -492,15 +490,15 @@ public class AfterSaleServiceImpl implements AfterSaleService {
 
 
         //订单退款,收回消费者获得的冻结积分
-        integralService.updateUserIntegral(orderUserId,orderUserId, CaclEnum.ORDER_REFUND_INTEGRAL_CONSUMER, increaseIntegral*(-1),0L,tradeOrderId,tradeOrderNum);
+        integralService.updateUserIntegral(orderUserId, orderUserId, CaclEnum.ORDER_REFUND_INTEGRAL_CONSUMER, increaseIntegral * (-1), 0L, tradeOrderId, tradeOrderNum);
 
         //20240604 推荐人(上级用户ID)
         Long ancesterUserId = tradeOrderMapper.selectAncesterByMemberUserId(orderUserId);
         //订单退款,收回消费者推荐人获得的冻结积分
-        integralService.updateUserIntegral(orderUserId,ancesterUserId, CaclEnum.ORDER_REFUND_INTEGRAL_ANCESTER, ancestorIncreaseIntegral*(-1),0L,tradeOrderId,tradeOrderNum);
+        integralService.updateUserIntegral(orderUserId, ancesterUserId, CaclEnum.ORDER_REFUND_INTEGRAL_ANCESTER, ancestorIncreaseIntegral * (-1), 0L, tradeOrderId, tradeOrderNum);
 
         //订单退款,收回消费者获得的冻结峰值
-        integralService.updateIntegralFreezeHighQuota(orderUserId,orderUserId, CaclEnum.ORDER_REFUND_ORDER_PAY_FREEZE_HIGH_QUOTA, freezeHighQuota,tradeOrderId,tradeOrderNum);
+        integralService.updateIntegralFreezeHighQuota(orderUserId, orderUserId, CaclEnum.ORDER_REFUND_ORDER_PAY_FREEZE_HIGH_QUOTA, freezeHighQuota, tradeOrderId, tradeOrderNum);
 
         // 发起退款单。注意,需要在事务提交后,再进行发起,避免重复发起
         createPayRefund(userIp, afterSale);
@@ -514,7 +512,7 @@ public class AfterSaleServiceImpl implements AfterSaleService {
                 AfterSaleStatusEnum.COMPLETE.getStatus());
 
         // 发送给微信用户售后消息
-        sentWcChatMessage(afterSale , AfterSaleStatusEnum.COMPLETE.getContent());
+        sentWcChatMessage(afterSale, AfterSaleStatusEnum.COMPLETE.getContent());
 
         // 更新交易订单项的售后状态为【已完成】
         tradeOrderUpdateService.updateOrderItemWhenAfterSaleSuccess(afterSale.getOrderItemId(), afterSale.getRefundPrice());
@@ -522,10 +520,11 @@ public class AfterSaleServiceImpl implements AfterSaleService {
 
     /**
      * 发送微信消息
-     * @param afterSale 售后订单
+     *
+     * @param afterSale   售后订单
      * @param afterStatus 是否同意退款
      */
-    private void sentWcChatMessage(AfterSaleDO afterSale,String afterStatus) {
+    private void sentWcChatMessage(AfterSaleDO afterSale, String afterStatus) {
         List<String> params = new ArrayList<>();
         params.add(afterSale.getNo());
         params.add(afterSale.getSpuName());
@@ -542,18 +541,18 @@ public class AfterSaleServiceImpl implements AfterSaleService {
     }
 
     private void createPayRefund(String userIp, AfterSaleDO afterSale) {
-        TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronization() {
-
-            @Override
-            public void afterCommit() {
-                // 创建退款单
-                PayRefundCreateReqDTO createReqDTO = AfterSaleConvert.INSTANCE.convert(userIp, afterSale, tradeOrderProperties)
-                        .setReason(StrUtil.format("退款【{}】", afterSale.getSpuName()));
-                Long payRefundId = payRefundApi.createRefund(createReqDTO);
-                // 更新售后单的退款单号
-                tradeAfterSaleMapper.updateById(new AfterSaleDO().setId(afterSale.getId()).setPayRefundId(payRefundId));
-            }
-        });
+//        TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronization() {
+
+//            @Override
+//            public void afterCommit() {
+        // 创建退款单
+        PayRefundCreateReqDTO createReqDTO = AfterSaleConvert.INSTANCE.convert(userIp, afterSale, tradeOrderProperties)
+                .setReason(StrUtil.format("退款【{}】", afterSale.getSpuName()));
+        Long payRefundId = payRefundApi.createRefund(createReqDTO);
+        // 更新售后单的退款单号
+        tradeAfterSaleMapper.updateById(new AfterSaleDO().setId(afterSale.getId()).setPayRefundId(payRefundId));
+//            }
+//        });
     }
 
     @Override
@@ -590,7 +589,7 @@ public class AfterSaleServiceImpl implements AfterSaleService {
         UserShopDetailsVO userShopDetails = userService.getUserShopDetails();
         reqVO.setShopId(userShopDetails.getShopId());
         reqVO.setMerchantId(userShopDetails.getMerId());
-        return tradeAfterSaleMapper.selectCountByUserIdAndStatus(userId, AfterSaleStatusEnum.APPLYING_STATUSES,reqVO);
+        return tradeAfterSaleMapper.selectCountByUserIdAndStatus(userId, AfterSaleStatusEnum.APPLYING_STATUSES, reqVO);
     }
 
     @Override
@@ -605,7 +604,7 @@ public class AfterSaleServiceImpl implements AfterSaleService {
         return tradeAfterSaleMapper.selectList(new LambdaQueryWrapperX<AfterSaleDO>()
                 .eq(AfterSaleDO::getSpuId, spuId)
                 .eqIfPresent(AfterSaleDO::getShopId, userShopDetails.getShopId())
-                .eqIfPresent(AfterSaleDO::getMerchantId,userShopDetails.getMerId())
+                .eqIfPresent(AfterSaleDO::getMerchantId, userShopDetails.getMerId())
         );
     }
 
@@ -626,27 +625,27 @@ public class AfterSaleServiceImpl implements AfterSaleService {
 
         Map<Integer, Long> counts = Maps.newLinkedHashMapWithExpectedSize(8);
         // 查询申请售后的售后订单
-        counts.put(AfterSaleStatusEnum.APPLY.getStatus(),tradeAfterSaleMapper.selectCount(AfterSaleStatusEnum.APPLY.getStatus(),pageVO));
+        counts.put(AfterSaleStatusEnum.APPLY.getStatus(), tradeAfterSaleMapper.selectCount(AfterSaleStatusEnum.APPLY.getStatus(), pageVO));
         // 查询商品待退货的售后订单
-        counts.put(AfterSaleStatusEnum.SELLER_AGREE.getStatus(),tradeAfterSaleMapper.selectCount(AfterSaleStatusEnum.SELLER_AGREE.getStatus(),pageVO));
+        counts.put(AfterSaleStatusEnum.SELLER_AGREE.getStatus(), tradeAfterSaleMapper.selectCount(AfterSaleStatusEnum.SELLER_AGREE.getStatus(), pageVO));
         // 查询商家待收货的售后订单
-        counts.put(AfterSaleStatusEnum.BUYER_DELIVERY.getStatus(),tradeAfterSaleMapper.selectCount(AfterSaleStatusEnum.BUYER_DELIVERY.getStatus(),pageVO));
+        counts.put(AfterSaleStatusEnum.BUYER_DELIVERY.getStatus(), tradeAfterSaleMapper.selectCount(AfterSaleStatusEnum.BUYER_DELIVERY.getStatus(), pageVO));
         // 查询等待退款的售后订单
-        counts.put(AfterSaleStatusEnum.WAIT_REFUND.getStatus(),tradeAfterSaleMapper.selectCount(AfterSaleStatusEnum.WAIT_REFUND.getStatus(),pageVO));
+        counts.put(AfterSaleStatusEnum.WAIT_REFUND.getStatus(), tradeAfterSaleMapper.selectCount(AfterSaleStatusEnum.WAIT_REFUND.getStatus(), pageVO));
         // 查询退款成功的售后订单
-        counts.put(AfterSaleStatusEnum.COMPLETE.getStatus(),tradeAfterSaleMapper.selectCount(AfterSaleStatusEnum.COMPLETE.getStatus(),pageVO));
+        counts.put(AfterSaleStatusEnum.COMPLETE.getStatus(), tradeAfterSaleMapper.selectCount(AfterSaleStatusEnum.COMPLETE.getStatus(), pageVO));
         // 查询买家取消的售后订单
-        counts.put(AfterSaleStatusEnum.BUYER_CANCEL.getStatus(),tradeAfterSaleMapper.selectCount(AfterSaleStatusEnum.BUYER_CANCEL.getStatus(),pageVO));
+        counts.put(AfterSaleStatusEnum.BUYER_CANCEL.getStatus(), tradeAfterSaleMapper.selectCount(AfterSaleStatusEnum.BUYER_CANCEL.getStatus(), pageVO));
         // 查询商家拒绝的售后订单
-        counts.put(AfterSaleStatusEnum.SELLER_DISAGREE.getStatus(),tradeAfterSaleMapper.selectCount(AfterSaleStatusEnum.SELLER_DISAGREE.getStatus(),pageVO));
+        counts.put(AfterSaleStatusEnum.SELLER_DISAGREE.getStatus(), tradeAfterSaleMapper.selectCount(AfterSaleStatusEnum.SELLER_DISAGREE.getStatus(), pageVO));
         // 查询商家拒收货的售后订单
-        counts.put(AfterSaleStatusEnum.SELLER_REFUSE.getStatus(),tradeAfterSaleMapper.selectCount(AfterSaleStatusEnum.SELLER_REFUSE.getStatus(),pageVO));
+        counts.put(AfterSaleStatusEnum.SELLER_REFUSE.getStatus(), tradeAfterSaleMapper.selectCount(AfterSaleStatusEnum.SELLER_REFUSE.getStatus(), pageVO));
         return counts;
     }
 
     @Override
     public Long selectCountByStatus(Long shopId, Long merId) {
-        return tradeAfterSaleMapper.selectCount(shopId,merId,AfterSaleStatusEnum.APPLY.getStatus(),
+        return tradeAfterSaleMapper.selectCount(shopId, merId, AfterSaleStatusEnum.APPLY.getStatus(),
                 AfterSaleStatusEnum.BUYER_DELIVERY.getStatus(),
                 AfterSaleStatusEnum.WAIT_REFUND.getStatus());
     }

+ 4 - 4
feifan-module-pay/feifan-module-pay-biz/src/main/java/cn/newfeifan/mall/module/pay/fuiou/client/RefundClient.java

@@ -27,11 +27,11 @@ public class RefundClient {
 		req.setMchnt_cd(mchnt_cd);
 		req.setTerm_id(term_id);
 		req.setRandom_str("20240713175056568974");
-		req.setMchnt_order_no("16103-202407112111001");
-		req.setRefund_order_no("16103-202407131750580");
+		req.setMchnt_order_no("16103-202408301647291");
+		req.setRefund_order_no("16103-202408301647299");
 		req.setOrder_type("WECHAT");
-		req.setTotal_amt("100");
-		req.setRefund_amt("100");
+		req.setTotal_amt("2");
+		req.setRefund_amt("2");
 		StringBuilder sb = new StringBuilder();
 		sb.append(req.getMchnt_cd()).append("|").append(req.getOrder_type()).append("|")
 		.append(req.getMchnt_order_no()).append("|").append(req.getRefund_order_no())

+ 5 - 1
feifan-module-pay/feifan-module-pay-biz/src/main/java/cn/newfeifan/mall/module/pay/service/fuyouorder/FuYouPayOrderServiceImpl.java

@@ -105,6 +105,10 @@ public class FuYouPayOrderServiceImpl implements FuYouPayOrderService {
                 updateRefundObj.setChannelErrorMsg(resp.getResult_msg());
                 refundMapper.updateById(updateRefundObj);
 
+                if(resp.getResult_msg().contains("余额不足")){
+                    throw exception(new ErrorCode(1_007_901_006, "{退款账户余额不足,请联系平台!!!}"));
+                }
+
                 ErrorCode ERROR = new ErrorCode(1_007_901_006, "请求退款失败");
                 throw exception(ERROR);
             }
@@ -129,7 +133,7 @@ public class FuYouPayOrderServiceImpl implements FuYouPayOrderService {
 
         } catch (Exception e) {
             log.error("向富友发起退款请求 == 异常:{}", e.getMessage());
-            ErrorCode ERROR = new ErrorCode(1_007_901_006, "异常! 请求退款失败");
+            ErrorCode ERROR = new ErrorCode(1_007_901_006, "退款错误!" + e.getMessage());
             throw exception(ERROR);
         }
     }

+ 1 - 0
feifan-module-pay/feifan-module-pay-biz/src/main/java/cn/newfeifan/mall/module/pay/service/refund/PayRefundServiceImpl.java

@@ -98,6 +98,7 @@ public class PayRefundServiceImpl implements PayRefundService {
     }
 
     @Override
+    @Transactional(rollbackFor = Exception.class)
     public Long createPayRefund(PayRefundCreateReqDTO reqDTO) {
         // 1.1 校验 App
         PayAppDO app = appService.validPayApp(reqDTO.getAppId());