Parcourir la source

订单新增门店信息

skyline il y a 2 semaines
Parent
commit
2c91cdd35e

+ 1 - 2
haha-entity/src/main/java/com/haha/entity/Order.java

@@ -122,13 +122,12 @@ public class Order implements Serializable {
     @TableField(exist = false)
     private String deviceName;
 
-    @TableField(exist = false)
+    /** 门店名称快照(下单时写入,不受后续门店改名影响) */
     private String storeName;
 
     @TableField(exist = false)
     private String shopName;
 
-    @TableField(exist = false)
     @JsonSerialize(using = ToStringSerializer.class)
     private Long shopId;
 

+ 1 - 0
haha-mp/src/api/order.ts

@@ -43,6 +43,7 @@ export interface OrderInfo {
   statusText?: string;
   createTime: string;
   payTime?: string;
+  storeName?: string; // 门店名称
   videoUrl?: string;
   confidence?: number;
   products: OrderProduct[];

+ 39 - 3
haha-service/src/main/java/com/haha/service/impl/OrderServiceImpl.java

@@ -436,6 +436,21 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
             order.setActivityId(activityId);                          // 开门会话ID
             order.setUserId(Long.parseLong(userId));                  // 用户ID
             order.setDeviceId(deviceId);                              // 设备ID
+
+            // 下单时写入门店信息,避免后续设备换门店导致历史订单门店失真
+            try {
+                Device device = deviceMapper.selectByDeviceId(deviceId);
+                if (device != null && device.getShopId() != null) {
+                    order.setShopId(device.getShopId());
+                    Shop shop = shopMapper.selectById(device.getShopId());
+                    if (shop != null) {
+                        order.setStoreName(shop.getName());
+                    }
+                }
+            } catch (Exception e) {
+                log.warn("写入订单门店信息失败: deviceId={}", deviceId, e);
+            }
+
             order.setTotalAmount(BigDecimal.ZERO);                    // 初始金额为0,等待回调更新
             order.setItems(skuListStr);                               // 商品列表JSON(包含code和quantity)
             order.setStatus(OrderConstants.STATUS_PENDING_PAYMENT);   // 订单状态:待支付
@@ -529,14 +544,14 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
                 }
             }
 
-            // 根据 deviceId 查询设备信息,获取门店名称
+            // 补充设备名称;历史订单未写入门店信息时,回退到 device→shop 查询
             if (order.getDeviceId() != null && !order.getDeviceId().isEmpty()) {
                 try {
                     Device device = deviceMapper.selectByDeviceId(order.getDeviceId());
                     if (device != null) {
                         order.setDeviceName(device.getName());
-                        order.setShopId(device.getShopId());
-                        if (device.getShopId() != null) {
+                        if (order.getShopId() == null && device.getShopId() != null) {
+                            order.setShopId(device.getShopId());
                             Shop shop = shopMapper.selectById(device.getShopId());
                             if (shop != null) {
                                 order.setShopName(shop.getName());
@@ -766,6 +781,26 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
             return null;
         }
 
+        // 补充设备名称;历史订单未写入门店信息时,回退到 device→shop 查询
+        if (order.getDeviceId() != null && !order.getDeviceId().isEmpty()) {
+            try {
+                Device device = deviceMapper.selectByDeviceId(order.getDeviceId());
+                if (device != null) {
+                    order.setDeviceName(device.getName());
+                    if (order.getShopId() == null && device.getShopId() != null) {
+                        order.setShopId(device.getShopId());
+                        Shop shop = shopMapper.selectById(device.getShopId());
+                        if (shop != null) {
+                            order.setShopName(shop.getName());
+                            order.setStoreName(shop.getName());
+                        }
+                    }
+                }
+            } catch (Exception e) {
+                log.warn("获取订单关联门店信息失败: orderId={}, deviceId={}", order.getId(), order.getDeviceId(), e);
+            }
+        }
+
         Map<String, Object> detail = buildOrderMap(order);
         detail.put("statusText", OrderConstants.getStatusDesc(order.getStatus()));
         return detail;
@@ -824,6 +859,7 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
         orderMap.put("orderName", order.getOrderName() != null ? order.getOrderName() : "");
         orderMap.put("outTradeNo", order.getOutTradeNo());
         orderMap.put("deviceId", order.getDeviceId());
+        orderMap.put("storeName", order.getStoreName() != null ? order.getStoreName() : "");
         orderMap.put("totalAmount", order.getTotalAmount());
         orderMap.put("discountAmount", order.getDiscountAmount() != null ? order.getDiscountAmount() : 0);
         orderMap.put("paidAmount", order.getPaidAmount() != null ? order.getPaidAmount() : order.getTotalAmount());