LiuJ před 4 měsíci
rodič
revize
092621ff29
1 změnil soubory, kde provedl 70 přidání a 74 odebrání
  1. 70 74
      app/JsonRpc/WebsiteService.php

+ 70 - 74
app/JsonRpc/WebsiteService.php

@@ -2230,11 +2230,6 @@ class WebsiteService implements WebsiteServiceInterface
             $errorMessage = "请先添加 " . implode(" 和 ", $missingTypes) . "!";
             $errorMessage = "请先添加 " . implode(" 和 ", $missingTypes) . "!";
             return Result::error($errorMessage, 0);
             return Result::error($errorMessage, 0);
         }
         }
-        // '站点状态0:关闭 1:开启
-        $web = Website::where('website.id', $data['website_id'])->first();
-        if($web['status'] == 0){
-            return Result::error("此网站已关闭!", 0);
-        }
         return Result::success($result);
         return Result::success($result);
     }
     }
     /**
     /**
@@ -2253,6 +2248,7 @@ class WebsiteService implements WebsiteServiceInterface
         if ($result['status'] == 2) {
         if ($result['status'] == 2) {
             return Result::error("此网站的模板正在应用中,暂不可编辑!", 0);
             return Result::error("此网站的模板正在应用中,暂不可编辑!", 0);
         }
         }
+
         // 订单状态:1:通过;2:驳回;3:撤回;4:修改;5:过期;6:待审核;7:结束
         // 订单状态:1:通过;2:驳回;3:撤回;4:修改;5:过期;6:待审核;7:结束
         $order = Order::where('website_id', $data['website_id'])->where('status', 1)->first();
         $order = Order::where('website_id', $data['website_id'])->where('status', 1)->first();
         if (!empty($order)) {
         if (!empty($order)) {
@@ -3422,38 +3418,23 @@ class WebsiteService implements WebsiteServiceInterface
      */
      */
     public function addWhiteRouter(array $data): array
     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']];
-            // 过滤空值并去重
-            $websiteIds = array_filter($websiteIds);
-            $websiteIds = array_unique($websiteIds);
-            // 将数组中的值转换为整数
-            $websiteIds = array_map(function ($value) {
-                return (int)$value;
-            }, $websiteIds);
-            // 转换为 JSON 字符串存储
-            $data['website_id'] = json_encode($websiteIds);
-
-            $result = WhiteRouter::insertGetId($data);
-            if (empty($result)) {
-                return Result::error("添加失败", 0);
-            }
-            return Result::success($result);
-        }catch (\Exception $e){
-            return Result::error("路由已经存在", 0);
+        // 确保 website_id 是数组
+        $websiteIds = is_array($data['website_id']) ? $data['website_id'] : [$data['website_id']];
+        // 过滤空值并去重
+        $websiteIds = array_filter($websiteIds);
+        $websiteIds = array_unique($websiteIds);
+        // 将数组中的值转换为整数
+        $websiteIds = array_map(function ($value) {
+            return (int)$value;
+        }, $websiteIds);
+        // 转换为 JSON 字符串存储
+        $data['website_id'] = json_encode($websiteIds);
+
+        $result = WhiteRouter::insertGetId($data);
+        if (empty($result)) {
+            return Result::error("添加失败", 0);
         }
         }
-
+        return Result::success($result);
     }
     }
     /**
     /**
      * 修改网站白名单路由地址
      * 修改网站白名单路由地址
@@ -3462,45 +3443,26 @@ class WebsiteService implements WebsiteServiceInterface
      */
      */
     public function upWhiteRouter(array $data): array
     public function upWhiteRouter(array $data): array
     {
     {
-        try {
-            $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']];
-            // 过滤空值并去重
-            $websiteIds = array_filter($websiteIds);
-            $websiteIds = array_unique($websiteIds);
-            // 将数组中的值转换为整数
-            $websiteIds = array_map(function ($value) {
-                return (int)$value;
-            }, $websiteIds);
-            // 转换为 JSON 字符串存储
-            $data['website_id'] = json_encode($websiteIds);
-
-            $result = WhiteRouter::where($where)->update($data);
-            if (empty($result)) {
-                return Result::error("修改失败", 0);
-            }
-            return Result::success($result);
-        }catch (\Exception $e){
-            var_dump($e->getMessage());
-            return Result::error("路由已经存在", 0);
+        $where = [
+            'id' => $data['id'],
+        ];
+        // 确保 website_id 是数组
+        $websiteIds = is_array($data['website_id']) ? $data['website_id'] : [$data['website_id']];
+        // 过滤空值并去重
+        $websiteIds = array_filter($websiteIds);
+        $websiteIds = array_unique($websiteIds);
+        // 将数组中的值转换为整数
+        $websiteIds = array_map(function ($value) {
+            return (int)$value;
+        }, $websiteIds);
+        // 转换为 JSON 字符串存储
+        $data['website_id'] = json_encode($websiteIds);
+
+        $result = WhiteRouter::where($where)->update($data);
+        if (empty($result)) {
+            return Result::error("修改失败", 0);
         }
         }
-
+        return Result::success($result);
     }
     }
     /**
     /**
      * 删除网站白名单路由地址
      * 删除网站白名单路由地址
@@ -3665,4 +3627,38 @@ class WebsiteService implements WebsiteServiceInterface
             return Result::error($e->getMessage(), 0);
             return Result::error($e->getMessage(), 0);
         }
         }
     }
     }
+
+    public function checkPath(array $data): array
+    {
+        var_dump("检查路径");
+        // return Result::success([]);
+        // website_category查找相同path的数据,返回那些数据重复了
+        // 查找所有具有相同path的重复记录
+        $duplicatePaths = WebsiteCategory::select('path', DB::raw('COUNT(*) as count'))
+            ->where('website_id', $data['website_id'])
+            ->groupBy('path')
+            ->havingRaw('COUNT(*) > 1')
+            ->get();
+
+        if ($duplicatePaths->isEmpty()) {
+            return Result::success([]);
+        }
+
+        // 获取所有重复记录的详细信息
+        $duplicateRecords = [];
+        foreach ($duplicatePaths as $duplicatePath) {
+            $records = WebsiteCategory::where(['path' => $duplicatePath->path])
+                ->where('website_id', $data['website_id'])
+                ->orderBy('id')
+                ->get();
+
+            $duplicateRecords[] = [
+
+                'path' => $duplicatePath->path,
+                'count' => $duplicatePath->count,
+                'records' => $records
+            ];
+        }
+        return Result::success($duplicateRecords);
+    }
 }
 }