rkljw 3 өдөр өмнө
parent
commit
8c108492c9

+ 146 - 1
app/JsonRpc/WebsiteService.php

@@ -45,6 +45,7 @@ use PhpParser\Node\Stmt\Return_;
 use function PHPUnit\Framework\isNull;
 use Overtrue\Pinyin\Pinyin;
 use App\Tools\buildTree;
+use App\Model\WhiteRouter;
 #[RpcService(name: "WebsiteService", protocol: "jsonrpc-http", server: "jsonrpc-http")]
 class WebsiteService implements WebsiteServiceInterface
 {
@@ -1096,8 +1097,14 @@ class WebsiteService implements WebsiteServiceInterface
             'website_id' => $data['website_id'],
         ];
         $result = WebsiteCategory::where($where)->orderBy('sort', 'asc')->get();
+        $list = [];
         if ($result) {
-            return Result::success($result);
+            foreach ($result->toArray() as $val) {
+                array_push($list, json_decode($val['category_arr_id']));
+            }
+        }
+        if ($result) {
+            return Result::success($list);
         } else {
             return Result::error("查询失败", 0);
         }
@@ -2687,4 +2694,142 @@ class WebsiteService implements WebsiteServiceInterface
         return Result::success($result);
     }
     // --自助建站-----------20250522fr----------------------end
+
+    /**
+     * 获取网站白名单路由地址
+     * @param array $data
+     * @return array
+     */
+    public function getWhiteRouterList(array $data): array
+    {
+        // 构建基础查询
+        $baseQuery = WhiteRouter::query();
+
+        // 功能名称模糊查询
+        if (!empty($data['function_name'])) {
+            $baseQuery->where('function_name', 'like', '%' . $data['function_name'] . '%');
+        }
+
+        // 网站ID查询 - 使用 JSON_CONTAINS 检查数组中是否包含指定的 website_id
+        if (!empty($data['website_id'])) {
+            $baseQuery->whereRaw('JSON_CONTAINS(website_id, ?)', [json_encode((int)$data['website_id'])]);
+        }
+
+        // 获取总数
+        $count = $baseQuery->count();
+
+        // 分页查询
+        $result = $baseQuery->orderBy('updated_at', 'desc')
+            ->limit($data['pageSize'])
+            ->offset(($data['page'] - 1) * $data['pageSize'])
+            ->get();
+
+        if (empty($result)) {
+            return Result::error("暂无数据", 0);
+        }
+
+        // 处理结果,将 website_id 转换为数组并获取对应的网站名称
+        $result->transform(function ($item) {
+            $websiteIds = json_decode($item->website_id, true);
+            $websiteNames = Website::whereIn('id', $websiteIds)
+                ->pluck('website_name')
+                ->toArray();
+            $item->website_names = $websiteNames;
+            $item->website_id = $websiteIds; // 将 website_id 转换为数组
+            return $item;
+        });
+
+        return Result::success([
+            'rows' => $result->toArray(),
+            'count' => $count
+        ]);
+    }
+    /**
+     * 添加网站白名单路由地址
+     * @param array $data
+     * @return array
+     */
+    public function addWhiteRouter(array $data): array
+    {
+        // 确保 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);
+    }
+    /**
+     * 修改网站白名单路由地址
+     * @param array $data
+     * @return array        
+     */
+    public function upWhiteRouter(array $data): array
+    {
+        $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);
+    }
+    /**
+     * 删除网站白名单路由地址
+     * @param array $data
+     * @return array
+     */
+    public function delWhiteRouter(array $data): array
+    {
+        $where = [
+            'id' => $data['id'],
+        ];  
+        $result = WhiteRouter::where($where)->delete();
+        if (empty($result)) {
+            return Result::error("删除失败", 0);
+        }
+        return Result::success($result);
+        
+    }
+    /**
+     * 获取网站白名单路由地址详情
+     * @param array $data
+     * @return array
+     */
+    public function getWhiteRouterInfo(array $data): array
+    {
+        $where = [
+            'id' => $data['id'],
+        ];      
+        $result = WhiteRouter::where($where)->first();  
+        if (empty($result)) {
+            return Result::error("没有查找到相关数据", 0);
+        }
+        // 将 website_id 从 JSON 字符串转换为数组
+        $result->website_id = json_decode($result->website_id, true);
+        return Result::success($result);
+    }
 }

+ 5 - 0
app/JsonRpc/WebsiteServiceInterface.php

@@ -150,4 +150,9 @@ interface WebsiteServiceInterface
     public function addStaticResource(array $data): array;
     public function delStaticResource(array $data): array;
     public function getStaticResourceInfo(array $data): array;
+    public function getWhiteRouterList(array $data): array;
+    public function addWhiteRouter(array $data): array;
+    public function upWhiteRouter(array $data): array;
+    public function delWhiteRouter(array $data): array;
+    public function getWhiteRouterInfo(array $data): array;
 }

+ 27 - 0
app/Model/WhiteRouter.php

@@ -0,0 +1,27 @@
+<?php
+
+declare(strict_types=1);
+
+namespace App\Model;
+
+use Hyperf\DbConnection\Model\Model;
+
+/**
+ */
+class WhiteRouter extends Model
+{
+    /**
+     * The table associated with the model.
+     */
+    protected ?string $table = 'white_router';
+
+    /**
+     * The attributes that are mass assignable.
+     */
+    protected array $fillable = [];
+
+    /**
+     * The attributes that should be cast to native types.
+     */
+    protected array $casts = [];
+}

+ 1 - 0
vendor/composer/autoload_classmap.php

@@ -80,6 +80,7 @@ return array(
     'App\\Model\\WebsiteRoleUser' => $baseDir . '/app/Model/WebsiteRoleUser.php',
     'App\\Model\\WebsiteTemplate' => $baseDir . '/app/Model/WebsiteTemplate.php',
     'App\\Model\\WebsiteTemplateInfo' => $baseDir . '/app/Model/WebsiteTemplateInfo.php',
+    'App\\Model\\WhiteRouter' => $baseDir . '/app/Model/WhiteRouter.php',
     'App\\Service\\MinioService' => $baseDir . '/app/Service/MinioService.php',
     'App\\Tools\\Result' => $baseDir . '/app/Tools/Result.php',
     'Attribute' => $vendorDir . '/symfony/polyfill-php80/Resources/stubs/Attribute.php',

+ 1 - 0
vendor/composer/autoload_static.php

@@ -794,6 +794,7 @@ class ComposerStaticInita4fab8fe7069cf132d8088fb346f5c2a
         'App\\Model\\WebsiteRoleUser' => __DIR__ . '/../..' . '/app/Model/WebsiteRoleUser.php',
         'App\\Model\\WebsiteTemplate' => __DIR__ . '/../..' . '/app/Model/WebsiteTemplate.php',
         'App\\Model\\WebsiteTemplateInfo' => __DIR__ . '/../..' . '/app/Model/WebsiteTemplateInfo.php',
+        'App\\Model\\WhiteRouter' => __DIR__ . '/../..' . '/app/Model/WhiteRouter.php',
         'App\\Service\\MinioService' => __DIR__ . '/../..' . '/app/Service/MinioService.php',
         'App\\Tools\\Result' => __DIR__ . '/../..' . '/app/Tools/Result.php',
         'Attribute' => __DIR__ . '/..' . '/symfony/polyfill-php80/Resources/stubs/Attribute.php',