rkljw 5 miesięcy temu
rodzic
commit
74382cdf95
1 zmienionych plików z 24 dodań i 0 usunięć
  1. 24 0
      app/JsonRpc/WebsiteService.php

+ 24 - 0
app/JsonRpc/WebsiteService.php

@@ -3422,6 +3422,16 @@ class WebsiteService implements WebsiteServiceInterface
     public function addWhiteRouter(array $data): array
     {
         try {
+            // 如果数据中包含 router_url,需要检查唯一性
+            if (isset($data['router_url'])) {
+                // 检查 router_url 是否已存在
+                $existingRouter = WhiteRouter::where('router_url', $data['router_url'])->first();
+                
+                if ($existingRouter) {
+                    return Result::error("路由地址已存在", 0);
+                }
+            }
+            
             // 确保 website_id 是数组
             $websiteIds = is_array($data['website_id']) ? $data['website_id'] : [$data['website_id']];
             // 过滤空值并去重
@@ -3455,6 +3465,19 @@ class WebsiteService implements WebsiteServiceInterface
             $where = [
                 'id' => $data['id'],
             ];
+            
+            // 如果更新数据中包含 router_url,需要检查唯一性
+            if (isset($data['router_url'])) {
+                // 检查 router_url 是否与其他记录冲突(排除当前记录)
+                $existingRouter = WhiteRouter::where('router_url', $data['router_url'])
+                    ->where('id', '!=', $data['id'])
+                    ->first();
+                
+                if ($existingRouter) {
+                    return Result::error("路由地址已存在", 0);
+                }
+            }
+            
             // 确保 website_id 是数组
             $websiteIds = is_array($data['website_id']) ? $data['website_id'] : [$data['website_id']];
             // 过滤空值并去重
@@ -3473,6 +3496,7 @@ class WebsiteService implements WebsiteServiceInterface
             }
             return Result::success($result);
         }catch (\Exception $e){
+            var_dump($e->getMessage());
             return Result::error("路由已经存在", 0);
         }