Parcourir la source

删除网站网址

rkljw il y a 2 jours
Parent
commit
cbc50e911c
2 fichiers modifiés avec 35 ajouts et 0 suppressions
  1. 33 0
      app/JsonRpc/WebsiteService.php
  2. 2 0
      app/JsonRpc/WebsiteServiceInterface.php

+ 33 - 0
app/JsonRpc/WebsiteService.php

@@ -3365,4 +3365,37 @@ class WebsiteService implements WebsiteServiceInterface
             return Result::error($e->getMessage(), 0);
         }
     }
+    /**
+     * 删除网站url
+     * @param array $data
+     * @return array
+     */
+    public function delWebsiteUrl(array $data): array{
+        try {
+            $wensiteInfo = Website::where(["id" => $data['website_id']])->first();
+            if (empty($wensiteInfo)) {
+                return Result::error("找不到该网站", 0);
+            }
+
+            $websiteUrlArray = [];
+            if (!empty($wensiteInfo->website_url)) {
+                $decoded = json_decode((string) $wensiteInfo->website_url, true);
+                $websiteUrlArray = is_array($decoded) ? $decoded : [];
+            }
+
+            // 从数组中按值删除对应的 URL
+            $index = array_search($data['website_url'] ?? null, $websiteUrlArray, true);
+            if ($index !== false) {
+                unset($websiteUrlArray[$index]);
+                // 重新索引,保持为连续的 JSON 数组
+                $websiteUrlArray = array_values($websiteUrlArray);
+            }
+
+            $newWebsiteUrlJson = json_encode($websiteUrlArray, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
+            Website::where(["id" => $data['website_id']])->update(["website_url" => $newWebsiteUrlJson]);
+            return Result::success([]);
+        } catch (\Exception $e) {
+            return Result::error($e->getMessage(), 0);
+        }
+    }
 }

+ 2 - 0
app/JsonRpc/WebsiteServiceInterface.php

@@ -174,4 +174,6 @@ interface WebsiteServiceInterface
     public function updateWebsiteStatus(array $data): array;
 
     public function getWebsiteAllinfo(array $data): array;
+
+    public function delWebsiteUrl(array $data): array;
 }