wangming 1 dag sedan
förälder
incheckning
1e8c5e626a

+ 3 - 6
yami-shop-api/src/main/java/com/yami/shop/api/controller/OrderRefundController.java

@@ -19,7 +19,7 @@ import com.yami.shop.common.config.Constant;
 import com.yami.shop.common.exception.GlobalException;
 import com.yami.shop.common.util.Arith;
 import com.yami.shop.common.util.PageParam;
-import com.yami.shop.common.util.R;
+import com.yami.shop.common.util.RefundSnUtils;
 import com.yami.shop.dao.OrderRefundRecordMapper;
 import com.yami.shop.dao.OrderRefundSkuMapper;
 import com.yami.shop.delivery.comment.api.paotui.PaoTuiApi;
@@ -185,7 +185,7 @@ public class OrderRefundController {
         newOrderRefund.setUserId(order.getUserId());
         newOrderRefund.setOrderId(order.getOrderId());
         newOrderRefund.setOrderNumber(order.getOrderNumber());
-        newOrderRefund.setRefundSn(String.valueOf(snowflake.nextId()));
+        newOrderRefund.setRefundSn(RefundSnUtils.generate());
         newOrderRefund.setRefundType(orderRefundParam.getRefundType());
 
         newOrderRefund.setRefundAmount(orderRefundParam.getRefundAmount());
@@ -273,11 +273,8 @@ public class OrderRefundController {
     public ResponseEntity<String> apply(@Valid @RequestBody OrderRefundParam orderRefundParam) {
         log.info("小程序申请退款参数:{}", JSONObject.toJSONString(orderRefundParam));
         List<OrderRefundSku> orderRefundSkuList = orderRefundParam.getOrderRefundSkuList();
-        System.out.println("orderRefundSkuList-------"+orderRefundSkuList);
         CullenUtils.validateDataThrowException(orderRefundSkuList.isEmpty(), "退款商品不能为空...");
-        System.out.println("过-------");
         String userId = SecurityUtils.getUser().getUserId();
-        System.out.println("userId-------"+userId);
 //        String userId = "36726893042d492aba446439c5f00584";
         // 获取订单信息
         Order order = orderService.getOrderByOrderNumberAndUserId(orderRefundParam.getOrderNumber(), userId, true);
@@ -338,7 +335,7 @@ public class OrderRefundController {
         newOrderRefund.setUserId(order.getUserId());
         newOrderRefund.setOrderId(order.getOrderId());
         newOrderRefund.setOrderNumber(order.getOrderNumber());
-        newOrderRefund.setRefundSn(String.valueOf(snowflake.nextId()));
+        newOrderRefund.setRefundSn(RefundSnUtils.generate());
         newOrderRefund.setRefundType(orderRefundParam.getRefundType());
 
         newOrderRefund.setRefundAmount(orderRefundParam.getRefundAmount());

+ 21 - 0
yami-shop-common/src/main/java/com/yami/shop/common/util/RefundSnUtils.java

@@ -0,0 +1,21 @@
+package com.yami.shop.common.util;
+
+import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
+import java.util.concurrent.ThreadLocalRandom;
+
+public final class RefundSnUtils {
+
+    private static final DateTimeFormatter FMT = DateTimeFormatter.ofPattern("yyyyMMddHHmmss");
+
+    /**
+     * 生成订单编号
+     * 格式:D + yyyyMMddHHmmss + 4位随机数字
+     */
+    public static String generate() {
+        String timestamp = LocalDateTime.now().format(FMT);
+        int random4 = ThreadLocalRandom.current().nextInt(1000, 10000); // 1000~9999
+        return "D" + timestamp + random4;
+    }
+
+}