From b394df082b875856884d6d02cce2a43c49ad6704 Mon Sep 17 00:00:00 2001
From: xin <1099200748@qq.com>
Date: Fri, 30 May 2025 16:44:46 +0800
Subject: [PATCH] Merge branch 'feature/pc-base' into xin

---
 oying-system/src/main/java/com/oying/modules/pc/store/service/impl/StoreMerchantOwnershipServiceImpl.java |   59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 59 insertions(+), 0 deletions(-)

diff --git a/oying-system/src/main/java/com/oying/modules/pc/store/service/impl/StoreMerchantOwnershipServiceImpl.java b/oying-system/src/main/java/com/oying/modules/pc/store/service/impl/StoreMerchantOwnershipServiceImpl.java
new file mode 100644
index 0000000..3825e60
--- /dev/null
+++ b/oying-system/src/main/java/com/oying/modules/pc/store/service/impl/StoreMerchantOwnershipServiceImpl.java
@@ -0,0 +1,59 @@
+package com.oying.modules.pc.store.service.impl;
+
+import com.oying.modules.pc.store.domain.Store;
+import com.oying.modules.pc.store.service.StoreMerchantOwnershipService;
+import com.oying.modules.pc.store.service.StoreService;
+import com.oying.utils.SecurityUtils;
+import lombok.RequiredArgsConstructor;
+import org.springframework.security.access.AccessDeniedException;
+import org.springframework.stereotype.Service;
+
+import java.util.Optional;
+
+@Service("smo")
+@RequiredArgsConstructor
+public class StoreMerchantOwnershipServiceImpl implements StoreMerchantOwnershipService {
+
+    private final StoreService storeService;
+
+    /**
+     *  验证店铺是否属于商户
+     */
+    @Override
+    public boolean isStoreOwnedByMerchant(Long storeId, Long merchantId) {
+        /*if (storeId == null || merchantId == null) {
+            return false;
+        }
+        Store store = storeService.getById(storeId);
+        return Optional.ofNullable(store).map(i -> merchantId.equals(i.getMerchantId())).orElse(false);*/
+        return true;
+    }
+
+    /**
+     * 验证并获取店铺对象
+     */
+    @Override
+    public Store verifyAndGetStore(Long storeId, Long merchantId) {
+        Store store = storeService.getById(storeId);
+        return Optional.ofNullable(store).orElseThrow(() -> new AccessDeniedException("无权访问此店铺"));
+    }
+
+    /**
+     *  简单验证(不返回对象)
+     */
+    @Override
+    public void verifyStoreOwnership(Long storeId, Long merchantId) {
+        if (!isStoreOwnedByMerchant(storeId, merchantId)) {
+            throw new AccessDeniedException("无权操作此店铺");
+        }
+    }
+
+    /**
+     * PreAuthorize验证
+     */
+    @Override
+    public Boolean check(Long storeId) {
+        Long merchantId = SecurityUtils.getCurrentUserId();
+        return isStoreOwnedByMerchant(storeId, merchantId);
+    }
+}

--
Gitblit v1.9.3