Explorar el Código

商家端 核销增加商家效验逻辑

qinxuyang hace 1 mes
padre
commit
af900d2de1

+ 41 - 0
alien-store/src/main/java/shop/alien/store/service/impl/StoreReservationServiceImpl.java

@@ -34,8 +34,11 @@ import com.alibaba.fastjson.JSONObject;
 import com.fasterxml.jackson.databind.ObjectMapper;
 import shop.alien.entity.store.LifeNotice;
 import shop.alien.entity.store.LifeUser;
+import shop.alien.entity.store.StoreUser;
 import shop.alien.mapper.LifeNoticeMapper;
 import shop.alien.mapper.LifeUserMapper;
+import shop.alien.mapper.StoreUserMapper;
+import shop.alien.util.common.JwtUtil;
 import org.springframework.util.StringUtils;
 import javax.annotation.PostConstruct;
 import java.text.ParseException;
@@ -67,6 +70,7 @@ public class StoreReservationServiceImpl extends ServiceImpl<StoreReservationMap
     private final UserReservationTableMapper userReservationTableMapper;
     private final LifeNoticeMapper lifeNoticeMapper;
     private final LifeUserMapper lifeUserMapper;
+    private final StoreUserMapper storeUserMapper;
     private final MerchantPaymentStrategyFactory merchantPaymentStrategyFactory;
     private final StoreBookingBusinessHoursService storeBookingBusinessHoursService;
     private final StoreBookingSettingsService storeBookingSettingsService;
@@ -623,6 +627,19 @@ public class StoreReservationServiceImpl extends ServiceImpl<StoreReservationMap
             throw new RuntimeException("预约不存在或已被删除");
         }
 
+        // 校验门店:核销码必须属于当前登录的门店
+        Integer currentStoreId = getCurrentStoreId();
+        if (currentStoreId == null) {
+            log.warn("无法获取当前登录门店ID,跳过门店校验");
+        } else {
+            Integer reservationStoreId = reservation.getStoreId();
+            if (reservationStoreId == null || !currentStoreId.equals(reservationStoreId)) {
+                log.error("核销码不属于本门店,当前门店ID={}, 预约门店ID={}, verificationCode={}", 
+                        currentStoreId, reservationStoreId, verificationCode);
+                throw new RuntimeException("此预订码不属于本门店,不予核销");
+            }
+        }
+
         // 校验预约状态(必须是已确认状态才能核销)
         if (reservation.getStatus() == null || reservation.getStatus() != 1) {
             throw new RuntimeException("预约状态不正确,只有已确认的预约才能核销");
@@ -1325,4 +1342,28 @@ public class StoreReservationServiceImpl extends ServiceImpl<StoreReservationMap
             return shop.alien.entity.result.R.fail("退款失败:" + e.getMessage());
         }
     }
+
+    /**
+     * 获取当前登录的门店ID
+     * 从JWT中获取用户ID,然后查询StoreUser获取门店ID
+     *
+     * @return 门店ID,如果未登录或查询失败返回null
+     */
+    private Integer getCurrentStoreId() {
+        try {
+            JSONObject userInfo = JwtUtil.getCurrentUserInfo();
+            if (userInfo != null) {
+                Integer userId = userInfo.getInteger("userId");
+                if (userId != null) {
+                    StoreUser storeUser = storeUserMapper.selectById(userId);
+                    if (storeUser != null) {
+                        return storeUser.getStoreId();
+                    }
+                }
+            }
+        } catch (Exception e) {
+            log.warn("获取当前登录门店ID失败: {}", e.getMessage());
+        }
+        return null;
+    }
 }