소스 검색

更新多个模型文件,调整字段注释和填充字段,优化代码格式。确保模型文档更加清晰,提升可读性。

notfff 7 달 전
부모
커밋
9b320ad6d0

+ 5 - 15
app/Module/OpenAPI/Models/OpenApiRateLimit.php

@@ -6,24 +6,14 @@ use UCore\ModelCore;
 
 /**
  * OpenAPI频率限制记录模型
- * 
- * @property int $id
- * @property string $app_id 应用ID
- * @property string $ip_address IP地址
- * @property string $endpoint 接口端点
- * @property string $limit_type 限制类型
- * @property \Carbon\Carbon $window_start 时间窗口开始
- * @property int $request_count 请求次数
- * @property bool $is_blocked 是否被阻止
- * @property string|null $user_agent 用户代理
- * @property array|null $headers 请求头信息
- * @property \Carbon\Carbon $created_at
- * @property \Carbon\Carbon $updated_at
+ *
+ * field start 
+ * field end
  */
 class OpenApiRateLimit extends ModelCore
 {
-    // field start 
- * field end
+
+
 
     /**
      * 数据类型转换

+ 5 - 31
app/Module/OpenAPI/Models/OpenApiScope.php

@@ -8,38 +8,12 @@ use App\Module\OpenAPI\Enums\SCOPE_TYPE;
 /**
  * OpenAPI权限范围模型
  *
- * @property int $id
- * @property string $app_id 应用ID
- * @property string $scope 权限范围
- * @property string $name 权限名称
- * @property string $description 权限描述
- * @property string $category 权限分类
- * @property string $risk_level 风险级别
- * @property bool $is_active 是否激活
- * @property \Carbon\Carbon|null $granted_at 授权时间
- * @property \Carbon\Carbon|null $expires_at 过期时间
- * @property string|null $granted_by 授权人
- * @property string|null $notes 备注
- * @property \Carbon\Carbon $created_at
- * @property \Carbon\Carbon $updated_at
+ * field start 
+ * field end
  */
 class OpenApiScope extends ModelCore
 {
-    // field start
-    protected $fillable = [
-        'app_id',
-        'scope',
-        'name',
-        'description',
-        'category',
-        'risk_level',
-        'is_active',
-        'granted_at',
-        'expires_at',
-        'granted_by',
-        'notes',
-    ];
-    // field end
+
 
     /**
      * 数据类型转换
@@ -133,8 +107,8 @@ class OpenApiScope extends ModelCore
             'TRADE' => '交易管理',
             'ADMIN' => '系统管理',
             'SPECIAL' => '特殊权限',
-            'default' => $this->category
-        ];
+            default => $this->category
+        };
     }
 
     /**

+ 4 - 34
app/Module/OpenAPI/Models/OpenApiStats.php

@@ -6,43 +6,13 @@ use UCore\ModelCore;
 
 /**
  * OpenAPI统计数据模型
- * 
- * @property int $id
- * @property string $app_id 应用ID
- * @property string $date 统计日期
- * @property int $hour 统计小时(0-23)
- * @property string $endpoint 接口端点
- * @property int $request_count 请求次数
- * @property int $success_count 成功次数
- * @property int $error_count 错误次数
- * @property float $avg_response_time 平均响应时间(毫秒)
- * @property float $max_response_time 最大响应时间(毫秒)
- * @property float $min_response_time 最小响应时间(毫秒)
- * @property int $rate_limit_hits 限流命中次数
- * @property int $unique_ips 唯一IP数量
- * @property array|null $error_details 错误详情
- * @property \Carbon\Carbon $created_at
- * @property \Carbon\Carbon $updated_at
+ *
+ * field start 
+ * field end
  */
 class OpenApiStats extends ModelCore
 {
-    // field start
-    protected $fillable = [
-        'app_id',
-        'date',
-        'hour',
-        'endpoint',
-        'request_count',
-        'success_count',
-        'error_count',
-        'avg_response_time',
-        'max_response_time',
-        'min_response_time',
-        'rate_limit_hits',
-        'unique_ips',
-        'error_details',
-    ];
-    // field end
+
 
     /**
      * 数据类型转换

+ 3 - 36
app/Module/OpenAPI/Models/OpenApiWebhook.php

@@ -6,45 +6,12 @@ use UCore\ModelCore;
 
 /**
  * OpenAPI Webhook配置模型
- * 
- * @property int $id
- * @property string $app_id 应用ID
- * @property string $name Webhook名称
- * @property string $url 回调URL
- * @property array $events 监听的事件类型
- * @property string $secret 签名密钥
- * @property string $status 状态
- * @property int $timeout 超时时间(秒)
- * @property int $retry_count 重试次数
- * @property int $current_retry_count 当前重试次数
- * @property int $total_deliveries 总投递次数
- * @property int $successful_deliveries 成功投递次数
- * @property int $failed_deliveries 失败投递次数
- * @property \Carbon\Carbon|null $last_success_at 最后成功时间
- * @property \Carbon\Carbon|null $last_failure_at 最后失败时间
- * @property \Carbon\Carbon $created_at
- * @property \Carbon\Carbon $updated_at
+ *
+ * field start 
+ * field end
  */
 class OpenApiWebhook extends ModelCore
 {
-    // field start
-    protected $fillable = [
-        'app_id',
-        'name',
-        'url',
-        'events',
-        'secret',
-        'status',
-        'timeout',
-        'retry_count',
-        'current_retry_count',
-        'total_deliveries',
-        'successful_deliveries',
-        'failed_deliveries',
-        'last_success_at',
-        'last_failure_at',
-    ];
-    // field end
 
     /**
      * 数据类型转换

+ 6 - 0
app/Module/ThirdParty/Databases/GenerateSql/README.md

@@ -0,0 +1,6 @@
+# 自动生成的SQL文件目录
+
+**警告:这是自动生成的目录,请勿手动修改此目录下的任何文件!**
+
+此目录下的SQL文件由系统自动生成,用于记录数据库表结构。
+如需修改表结构,请修改对应的模型文件,然后重新运行生成命令。

+ 27 - 0
app/Module/ThirdParty/Databases/GenerateSql/thirdparty_credentials.sql

@@ -0,0 +1,27 @@
+-- ******************************************************************
+-- 表 kku_thirdparty_credentials 的创建SQL
+-- 对应的Model: App\Module\ThirdParty\Models\ThirdPartyCredential
+-- 警告: 此文件由系统自动生成,禁止修改!
+-- ******************************************************************
+
+CREATE TABLE `kku_thirdparty_credentials` (
+  `id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT '主键ID',
+  `service_id` bigint unsigned NOT NULL COMMENT '服务ID',
+  `name` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '凭证名称',
+  `type` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '凭证类型',
+  `credentials` json NOT NULL COMMENT '凭证信息(加密存储)',
+  `environment` varchar(20) COLLATE utf8mb4_unicode_ci DEFAULT 'production' COMMENT '环境(production/staging/development)',
+  `is_active` tinyint(1) DEFAULT '1' COMMENT '是否激活',
+  `expires_at` timestamp NULL DEFAULT NULL COMMENT '过期时间',
+  `last_used_at` timestamp NULL DEFAULT NULL COMMENT '最后使用时间',
+  `usage_count` bigint DEFAULT '0' COMMENT '使用次数',
+  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
+  `updated_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
+  PRIMARY KEY (`id`),
+  KEY `idx_service_id` (`service_id`),
+  KEY `idx_type` (`type`),
+  KEY `idx_environment` (`environment`),
+  KEY `idx_is_active` (`is_active`),
+  KEY `idx_expires_at` (`expires_at`),
+  CONSTRAINT `fk_credentials_service` FOREIGN KEY (`service_id`) REFERENCES `kku_thirdparty_services` (`id`) ON DELETE CASCADE
+) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='认证凭证表';

+ 38 - 0
app/Module/ThirdParty/Databases/GenerateSql/thirdparty_logs.sql

@@ -0,0 +1,38 @@
+-- ******************************************************************
+-- 表 kku_thirdparty_logs 的创建SQL
+-- 对应的Model: App\Module\ThirdParty\Models\ThirdPartyLog
+-- 警告: 此文件由系统自动生成,禁止修改!
+-- ******************************************************************
+
+CREATE TABLE `kku_thirdparty_logs` (
+  `id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT '主键ID',
+  `service_id` bigint unsigned NOT NULL COMMENT '服务ID',
+  `credential_id` bigint unsigned DEFAULT NULL COMMENT '凭证ID',
+  `request_id` varchar(50) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '请求ID(用于追踪)',
+  `method` varchar(10) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '请求方法',
+  `url` varchar(500) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '请求URL',
+  `headers` json DEFAULT NULL COMMENT '请求头',
+  `params` json DEFAULT NULL COMMENT '请求参数',
+  `body` text COLLATE utf8mb4_unicode_ci COMMENT '请求体',
+  `response_status` int DEFAULT NULL COMMENT '响应状态码',
+  `response_headers` json DEFAULT NULL COMMENT '响应头',
+  `response_body` text COLLATE utf8mb4_unicode_ci COMMENT '响应体',
+  `response_time` int DEFAULT NULL COMMENT '响应时间(毫秒)',
+  `error_message` text COLLATE utf8mb4_unicode_ci COMMENT '错误信息',
+  `level` varchar(20) COLLATE utf8mb4_unicode_ci DEFAULT 'INFO' COMMENT '日志级别',
+  `user_id` bigint unsigned DEFAULT NULL COMMENT '用户ID',
+  `ip_address` varchar(45) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'IP地址',
+  `user_agent` varchar(500) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'User Agent',
+  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
+  PRIMARY KEY (`id`),
+  KEY `idx_service_id` (`service_id`),
+  KEY `idx_credential_id` (`credential_id`),
+  KEY `idx_request_id` (`request_id`),
+  KEY `idx_method` (`method`),
+  KEY `idx_response_status` (`response_status`),
+  KEY `idx_level` (`level`),
+  KEY `idx_user_id` (`user_id`),
+  KEY `idx_created_at` (`created_at`),
+  CONSTRAINT `fk_logs_credential` FOREIGN KEY (`credential_id`) REFERENCES `kku_thirdparty_credentials` (`id`) ON DELETE SET NULL,
+  CONSTRAINT `fk_logs_service` FOREIGN KEY (`service_id`) REFERENCES `kku_thirdparty_services` (`id`) ON DELETE CASCADE
+) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='调用日志表';

+ 23 - 0
app/Module/ThirdParty/Databases/GenerateSql/thirdparty_monitors.sql

@@ -0,0 +1,23 @@
+-- ******************************************************************
+-- 表 kku_thirdparty_monitors 的创建SQL
+-- 对应的Model: App\Module\ThirdParty\Models\ThirdPartyMonitor
+-- 警告: 此文件由系统自动生成,禁止修改!
+-- ******************************************************************
+
+CREATE TABLE `kku_thirdparty_monitors` (
+  `id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT '主键ID',
+  `service_id` bigint unsigned NOT NULL COMMENT '服务ID',
+  `check_type` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '检查类型(health/performance/availability)',
+  `status` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '检查状态',
+  `response_time` int DEFAULT NULL COMMENT '响应时间(毫秒)',
+  `status_code` int DEFAULT NULL COMMENT 'HTTP状态码',
+  `error_message` text COLLATE utf8mb4_unicode_ci COMMENT '错误信息',
+  `details` json DEFAULT NULL COMMENT '详细信息',
+  `checked_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '检查时间',
+  PRIMARY KEY (`id`),
+  KEY `idx_service_id` (`service_id`),
+  KEY `idx_check_type` (`check_type`),
+  KEY `idx_status` (`status`),
+  KEY `idx_checked_at` (`checked_at`),
+  CONSTRAINT `fk_monitors_service` FOREIGN KEY (`service_id`) REFERENCES `kku_thirdparty_services` (`id`) ON DELETE CASCADE
+) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='监控记录表';

+ 29 - 0
app/Module/ThirdParty/Databases/GenerateSql/thirdparty_quotas.sql

@@ -0,0 +1,29 @@
+-- ******************************************************************
+-- 表 kku_thirdparty_quotas 的创建SQL
+-- 对应的Model: App\Module\ThirdParty\Models\ThirdPartyQuota
+-- 警告: 此文件由系统自动生成,禁止修改!
+-- ******************************************************************
+
+CREATE TABLE `kku_thirdparty_quotas` (
+  `id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT '主键ID',
+  `service_id` bigint unsigned NOT NULL COMMENT '服务ID',
+  `type` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '配额类型',
+  `limit_value` bigint NOT NULL COMMENT '限制值',
+  `used_value` bigint DEFAULT '0' COMMENT '已使用值',
+  `reset_at` timestamp NULL DEFAULT NULL COMMENT '重置时间',
+  `window_start` timestamp NULL DEFAULT NULL COMMENT '时间窗口开始',
+  `window_end` timestamp NULL DEFAULT NULL COMMENT '时间窗口结束',
+  `is_active` tinyint(1) DEFAULT '1' COMMENT '是否激活',
+  `alert_threshold` decimal(5,2) DEFAULT '80.00' COMMENT '告警阈值(百分比)',
+  `is_exceeded` tinyint(1) DEFAULT '0' COMMENT '是否已超限',
+  `exceeded_at` timestamp NULL DEFAULT NULL COMMENT '超限时间',
+  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
+  `updated_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
+  PRIMARY KEY (`id`),
+  UNIQUE KEY `uk_service_type` (`service_id`,`type`),
+  KEY `idx_type` (`type`),
+  KEY `idx_is_active` (`is_active`),
+  KEY `idx_is_exceeded` (`is_exceeded`),
+  KEY `idx_reset_at` (`reset_at`),
+  CONSTRAINT `fk_quotas_service` FOREIGN KEY (`service_id`) REFERENCES `kku_thirdparty_services` (`id`) ON DELETE CASCADE
+) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='配额管理表';

+ 40 - 0
app/Module/ThirdParty/Databases/GenerateSql/thirdparty_services.sql

@@ -0,0 +1,40 @@
+-- ******************************************************************
+-- 表 kku_thirdparty_services 的创建SQL
+-- 对应的Model: App\Module\ThirdParty\Models\ThirdPartyService
+-- 警告: 此文件由系统自动生成,禁止修改!
+-- ******************************************************************
+
+CREATE TABLE `kku_thirdparty_services` (
+  `id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT '主键ID',
+  `name` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '服务名称',
+  `code` varchar(50) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '服务代码(唯一标识)',
+  `type` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '服务类型',
+  `provider` varchar(50) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '服务提供商',
+  `description` text COLLATE utf8mb4_unicode_ci COMMENT '服务描述',
+  `base_url` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '基础URL',
+  `version` varchar(20) COLLATE utf8mb4_unicode_ci DEFAULT 'v1' COMMENT 'API版本',
+  `auth_type` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '认证类型',
+  `status` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'INACTIVE' COMMENT '服务状态',
+  `priority` int DEFAULT '0' COMMENT '优先级(数字越小优先级越高)',
+  `timeout` int DEFAULT '30' COMMENT '超时时间(秒)',
+  `retry_times` int DEFAULT '3' COMMENT '重试次数',
+  `retry_delay` int DEFAULT '1000' COMMENT '重试延迟(毫秒)',
+  `config` json DEFAULT NULL COMMENT '服务配置信息',
+  `headers` json DEFAULT NULL COMMENT '默认请求头',
+  `params` json DEFAULT NULL COMMENT '默认参数',
+  `webhook_url` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'Webhook回调地址',
+  `webhook_secret` varchar(100) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'Webhook密钥',
+  `health_check_url` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '健康检查URL',
+  `health_check_interval` int DEFAULT '300' COMMENT '健康检查间隔(秒)',
+  `last_health_check` timestamp NULL DEFAULT NULL COMMENT '最后健康检查时间',
+  `health_status` varchar(20) COLLATE utf8mb4_unicode_ci DEFAULT 'UNKNOWN' COMMENT '健康状态',
+  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
+  `updated_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
+  PRIMARY KEY (`id`),
+  UNIQUE KEY `uk_code` (`code`),
+  KEY `idx_type` (`type`),
+  KEY `idx_provider` (`provider`),
+  KEY `idx_status` (`status`),
+  KEY `idx_priority` (`priority`),
+  KEY `idx_created_at` (`created_at`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='第三方服务配置表';

+ 36 - 53
app/Module/ThirdParty/Models/ThirdPartyCredential.php

@@ -9,19 +9,21 @@ use Illuminate\Support\Facades\Crypt;
 
 /**
  * 第三方服务认证凭证模型
- * 
- * @property int $id 主键ID
- * @property int $service_id 服务ID
- * @property string $name 凭证名称
- * @property string $type 凭证类型
- * @property array $credentials 凭证信息
- * @property string $environment 环境
- * @property bool $is_active 是否激活
- * @property \Carbon\Carbon|null $expires_at 过期时间
- * @property \Carbon\Carbon|null $last_used_at 最后使用时间
- * @property int $usage_count 使用次数
- * @property \Carbon\Carbon $created_at 创建时间
- * @property \Carbon\Carbon $updated_at 更新时间
+ *
+ * field start 
+ * @property  int  $id  主键ID
+ * @property  int  $service_id  服务ID
+ * @property  string  $name  凭证名称
+ * @property  string  $type  凭证类型
+ * @property  array  $credentials  凭证信息(加密存储)
+ * @property  string  $environment  环境(production/staging/development)
+ * @property  bool  $is_active  是否激活
+ * @property  \Carbon\Carbon  $expires_at  过期时间
+ * @property  \Carbon\Carbon  $last_used_at  最后使用时间
+ * @property  int  $usage_count  使用次数
+ * @property  \Carbon\Carbon  $created_at  创建时间
+ * @property  \Carbon\Carbon  $updated_at  更新时间
+ * field end
  */
 class ThirdPartyCredential extends ModelCore
 {
@@ -32,26 +34,7 @@ class ThirdPartyCredential extends ModelCore
      */
     protected $table = 'thirdparty_credentials';
 
-    // field start
-    /**
-     * 可批量赋值的属性
-     *
-     * @var array
-     */
-    // attrlist start
-    protected $fillable = [
-        'service_id',
-        'name',
-        'type',
-        'credentials',
-        'environment',
-        'is_active',
-        'expires_at',
-        'last_used_at',
-        'usage_count',
-    ];
-    // attrlist end
-    // field end
+
 
     /**
      * 属性类型转换
@@ -108,7 +91,7 @@ class ThirdPartyCredential extends ModelCore
         if (!$this->expires_at) {
             return false;
         }
-        
+
         return now()->gt($this->expires_at);
     }
 
@@ -123,7 +106,7 @@ class ThirdPartyCredential extends ModelCore
         if (!$this->expires_at) {
             return false;
         }
-        
+
         return now()->addDays($days)->gte($this->expires_at);
     }
 
@@ -147,7 +130,7 @@ class ThirdPartyCredential extends ModelCore
         if (!$this->credentials) {
             return [];
         }
-        
+
         $decrypted = [];
         foreach ($this->credentials as $key => $value) {
             try {
@@ -157,7 +140,7 @@ class ThirdPartyCredential extends ModelCore
                 $decrypted[$key] = $value;
             }
         }
-        
+
         return $decrypted;
     }
 
@@ -178,7 +161,7 @@ class ThirdPartyCredential extends ModelCore
                 $encrypted[$key] = $value;
             }
         }
-        
+
         $this->credentials = $encrypted;
     }
 
@@ -202,7 +185,7 @@ class ThirdPartyCredential extends ModelCore
             'app_secret',
             'webhook_secret',
         ];
-        
+
         return in_array(strtolower($field), $sensitiveFields);
     }
 
@@ -242,37 +225,37 @@ class ThirdPartyCredential extends ModelCore
         $authType = $this->getAuthTypeEnum();
         $credentials = $this->getDecryptedCredentials();
         $headers = [];
-        
+
         switch ($authType) {
             case AUTH_TYPE::API_KEY:
                 $headers[$authType->getHeaderName()] = $credentials['api_key'] ?? '';
                 break;
-                
+
             case AUTH_TYPE::BEARER:
                 $headers[$authType->getHeaderName()] = $authType->getHeaderPrefix() . ($credentials['access_token'] ?? '');
                 break;
-                
+
             case AUTH_TYPE::BASIC:
                 $username = $credentials['username'] ?? '';
                 $password = $credentials['password'] ?? '';
                 $headers[$authType->getHeaderName()] = $authType->getHeaderPrefix() . base64_encode($username . ':' . $password);
                 break;
-                
+
             case AUTH_TYPE::JWT:
                 $headers[$authType->getHeaderName()] = $authType->getHeaderPrefix() . ($credentials['jwt_token'] ?? '');
                 break;
-                
+
             case AUTH_TYPE::SIGNATURE:
                 // 签名认证需要根据具体的签名算法生成
                 $headers['X-Signature'] = $this->generateSignature($credentials);
                 break;
-                
+
             case AUTH_TYPE::CUSTOM:
                 // 自定义认证方式
                 $headers = $credentials['custom_headers'] ?? [];
                 break;
         }
-        
+
         return $headers;
     }
 
@@ -290,9 +273,9 @@ class ThirdPartyCredential extends ModelCore
         $appSecret = $credentials['app_secret'] ?? '';
         $timestamp = time();
         $nonce = uniqid();
-        
+
         $signString = $appKey . $timestamp . $nonce . $appSecret;
-        
+
         return hash('sha256', $signString);
     }
 
@@ -316,14 +299,14 @@ class ThirdPartyCredential extends ModelCore
         $authType = $this->getAuthTypeEnum();
         $requiredFields = $authType->getRequiredFields();
         $credentials = $this->getDecryptedCredentials();
-        
+
         $missingFields = [];
         foreach ($requiredFields as $field) {
             if (empty($credentials[$field])) {
                 $missingFields[] = $field;
             }
         }
-        
+
         return [
             'valid' => empty($missingFields),
             'missing_fields' => $missingFields,
@@ -340,14 +323,14 @@ class ThirdPartyCredential extends ModelCore
     {
         $credential = new static();
         $credential->fill($data);
-        
+
         // 加密敏感信息
         if (isset($data['credentials'])) {
             $credential->setEncryptedCredentials($data['credentials']);
         }
-        
+
         $credential->save();
-        
+
         return $credential;
     }
 }

+ 38 - 64
app/Module/ThirdParty/Models/ThirdPartyLog.php

@@ -8,26 +8,28 @@ use Illuminate\Database\Eloquent\Relations\BelongsTo;
 
 /**
  * 第三方服务调用日志模型
- * 
- * @property int $id 主键ID
- * @property int $service_id 服务ID
- * @property int|null $credential_id 凭证ID
- * @property string $request_id 请求ID
- * @property string $method 请求方法
- * @property string $url 请求URL
- * @property array|null $headers 请求头
- * @property array|null $params 请求参数
- * @property string|null $body 请求体
- * @property int|null $response_status 响应状态码
- * @property array|null $response_headers 响应头
- * @property string|null $response_body 响应体
- * @property int|null $response_time 响应时间
- * @property string|null $error_message 错误信息
- * @property string $level 日志级别
- * @property int|null $user_id 用户ID
- * @property string|null $ip_address IP地址
- * @property string|null $user_agent User Agent
- * @property \Carbon\Carbon $created_at 创建时间
+ *
+ * field start 
+ * @property  int  $id  主键ID
+ * @property  int  $service_id  服务ID
+ * @property  int  $credential_id  凭证ID
+ * @property  string  $request_id  请求ID(用于追踪)
+ * @property  string  $method  请求方法
+ * @property  string  $url  请求URL
+ * @property  array  $headers  请求头
+ * @property  array  $params  请求参数
+ * @property  string  $body  请求体
+ * @property  int  $response_status  响应状态码
+ * @property  array  $response_headers  响应头
+ * @property  string  $response_body  响应体
+ * @property  int  $response_time  响应时间(毫秒)
+ * @property  string  $error_message  错误信息
+ * @property  string  $level  日志级别
+ * @property  int  $user_id  用户ID
+ * @property  string  $ip_address  IP地址
+ * @property  string  $user_agent  User Agent
+ * @property  \Carbon\Carbon  $created_at  创建时间
+ * field end
  */
 class ThirdPartyLog extends ModelCore
 {
@@ -45,35 +47,7 @@ class ThirdPartyLog extends ModelCore
      */
     public $timestamps = false;
 
-    // field start
-    /**
-     * 可批量赋值的属性
-     *
-     * @var array
-     */
-    // attrlist start
-    protected $fillable = [
-        'service_id',
-        'credential_id',
-        'request_id',
-        'method',
-        'url',
-        'headers',
-        'params',
-        'body',
-        'response_status',
-        'response_headers',
-        'response_body',
-        'response_time',
-        'error_message',
-        'level',
-        'user_id',
-        'ip_address',
-        'user_agent',
-        'created_at',
-    ];
-    // attrlist end
-    // field end
+
 
     /**
      * 属性类型转换
@@ -162,11 +136,11 @@ class ThirdPartyLog extends ModelCore
         if (!$this->response_time) {
             return '-';
         }
-        
+
         if ($this->response_time < 1000) {
             return $this->response_time . 'ms';
         }
-        
+
         return number_format($this->getResponseTimeInSeconds(), 2) . 's';
     }
 
@@ -180,7 +154,7 @@ class ThirdPartyLog extends ModelCore
         if (!$this->response_status) {
             return '无响应';
         }
-        
+
         $statusTexts = [
             200 => 'OK',
             201 => 'Created',
@@ -195,7 +169,7 @@ class ThirdPartyLog extends ModelCore
             503 => 'Service Unavailable',
             504 => 'Gateway Timeout',
         ];
-        
+
         return $statusTexts[$this->response_status] ?? 'Unknown';
     }
 
@@ -209,19 +183,19 @@ class ThirdPartyLog extends ModelCore
         if (!$this->response_status) {
             return 'secondary';
         }
-        
+
         if ($this->response_status >= 200 && $this->response_status < 300) {
             return 'success';
         }
-        
+
         if ($this->response_status >= 300 && $this->response_status < 400) {
             return 'info';
         }
-        
+
         if ($this->response_status >= 400 && $this->response_status < 500) {
             return 'warning';
         }
-        
+
         return 'danger';
     }
 
@@ -236,11 +210,11 @@ class ThirdPartyLog extends ModelCore
         if (!$this->body) {
             return '';
         }
-        
+
         if (strlen($this->body) <= $maxLength) {
             return $this->body;
         }
-        
+
         return substr($this->body, 0, $maxLength) . '...';
     }
 
@@ -255,11 +229,11 @@ class ThirdPartyLog extends ModelCore
         if (!$this->response_body) {
             return '';
         }
-        
+
         if (strlen($this->response_body) <= $maxLength) {
             return $this->response_body;
         }
-        
+
         return substr($this->response_body, 0, $maxLength) . '...';
     }
 
@@ -322,12 +296,12 @@ class ThirdPartyLog extends ModelCore
         if (!isset($data['created_at'])) {
             $data['created_at'] = now();
         }
-        
+
         // 自动生成请求ID
         if (!isset($data['request_id'])) {
             $data['request_id'] = static::generateRequestId();
         }
-        
+
         // 自动设置日志级别
         if (!isset($data['level'])) {
             if (isset($data['response_status'])) {
@@ -342,7 +316,7 @@ class ThirdPartyLog extends ModelCore
                 $data['level'] = LOG_LEVEL::INFO->value;
             }
         }
-        
+
         return static::create($data);
     }
 

+ 18 - 34
app/Module/ThirdParty/Models/ThirdPartyMonitor.php

@@ -7,16 +7,18 @@ use Illuminate\Database\Eloquent\Relations\BelongsTo;
 
 /**
  * 第三方服务监控记录模型
- * 
- * @property int $id 主键ID
- * @property int $service_id 服务ID
- * @property string $check_type 检查类型
- * @property string $status 检查状态
- * @property int|null $response_time 响应时间
- * @property int|null $status_code HTTP状态码
- * @property string|null $error_message 错误信息
- * @property array|null $details 详细信息
- * @property \Carbon\Carbon $checked_at 检查时间
+ *
+ * field start 
+ * @property  int  $id  主键ID
+ * @property  int  $service_id  服务ID
+ * @property  string  $check_type  检查类型(health/performance/availability)
+ * @property  string  $status  检查状态
+ * @property  int  $response_time  响应时间(毫秒)
+ * @property  int  $status_code  HTTP状态码
+ * @property  string  $error_message  错误信息
+ * @property  array  $details  详细信息
+ * @property  \Carbon\Carbon  $checked_at  检查时间
+ * field end
  */
 class ThirdPartyMonitor extends ModelCore
 {
@@ -34,25 +36,7 @@ class ThirdPartyMonitor extends ModelCore
      */
     public $timestamps = false;
 
-    // field start
-    /**
-     * 可批量赋值的属性
-     *
-     * @var array
-     */
-    // attrlist start
-    protected $fillable = [
-        'service_id',
-        'check_type',
-        'status',
-        'response_time',
-        'status_code',
-        'error_message',
-        'details',
-        'checked_at',
-    ];
-    // attrlist end
-    // field end
+
 
     /**
      * 属性类型转换
@@ -199,11 +183,11 @@ class ThirdPartyMonitor extends ModelCore
         if (!$this->response_time) {
             return '-';
         }
-        
+
         if ($this->response_time < 1000) {
             return $this->response_time . 'ms';
         }
-        
+
         return number_format($this->getResponseTimeInSeconds(), 2) . 's';
     }
 
@@ -217,7 +201,7 @@ class ThirdPartyMonitor extends ModelCore
         if (!$this->response_time) {
             return 'N/A';
         }
-        
+
         if ($this->response_time <= 200) {
             return 'A';
         } elseif ($this->response_time <= 500) {
@@ -298,7 +282,7 @@ class ThirdPartyMonitor extends ModelCore
         if (!isset($data['checked_at'])) {
             $data['checked_at'] = now();
         }
-        
+
         // 根据响应时间和状态码自动判断状态
         if (!isset($data['status'])) {
             if (isset($data['status_code'])) {
@@ -319,7 +303,7 @@ class ThirdPartyMonitor extends ModelCore
                 $data['status'] = self::STATUS_UNKNOWN;
             }
         }
-        
+
         return static::create($data);
     }
 

+ 37 - 56
app/Module/ThirdParty/Models/ThirdPartyQuota.php

@@ -8,21 +8,23 @@ use Illuminate\Database\Eloquent\Relations\BelongsTo;
 
 /**
  * 第三方服务配额管理模型
- * 
- * @property int $id 主键ID
- * @property int $service_id 服务ID
- * @property string $type 配额类型
- * @property int $limit_value 限制值
- * @property int $used_value 已使用值
- * @property \Carbon\Carbon|null $reset_at 重置时间
- * @property \Carbon\Carbon|null $window_start 时间窗口开始
- * @property \Carbon\Carbon|null $window_end 时间窗口结束
- * @property bool $is_active 是否激活
- * @property float $alert_threshold 告警阈值
- * @property bool $is_exceeded 是否已超限
- * @property \Carbon\Carbon|null $exceeded_at 超限时间
- * @property \Carbon\Carbon $created_at 创建时间
- * @property \Carbon\Carbon $updated_at 更新时间
+ *
+ * field start 
+ * @property  int  $id  主键ID
+ * @property  int  $service_id  服务ID
+ * @property  string  $type  配额类型
+ * @property  int  $limit_value  限制值
+ * @property  int  $used_value  已使用值
+ * @property  \Carbon\Carbon  $reset_at  重置时间
+ * @property  \Carbon\Carbon  $window_start  时间窗口开始
+ * @property  \Carbon\Carbon  $window_end  时间窗口结束
+ * @property  bool  $is_active  是否激活
+ * @property  float  $alert_threshold  告警阈值(百分比)
+ * @property  bool  $is_exceeded  是否已超限
+ * @property  \Carbon\Carbon  $exceeded_at  超限时间
+ * @property  \Carbon\Carbon  $created_at  创建时间
+ * @property  \Carbon\Carbon  $updated_at  更新时间
+ * field end
  */
 class ThirdPartyQuota extends ModelCore
 {
@@ -33,28 +35,7 @@ class ThirdPartyQuota extends ModelCore
      */
     protected $table = 'thirdparty_quotas';
 
-    // field start
-    /**
-     * 可批量赋值的属性
-     *
-     * @var array
-     */
-    // attrlist start
-    protected $fillable = [
-        'service_id',
-        'type',
-        'limit_value',
-        'used_value',
-        'reset_at',
-        'window_start',
-        'window_end',
-        'is_active',
-        'alert_threshold',
-        'is_exceeded',
-        'exceeded_at',
-    ];
-    // attrlist end
-    // field end
+
 
     /**
      * 属性类型转换
@@ -106,7 +87,7 @@ class ThirdPartyQuota extends ModelCore
         if ($this->limit_value <= 0) {
             return 0;
         }
-        
+
         return min(100, ($this->used_value / $this->limit_value) * 100);
     }
 
@@ -148,22 +129,22 @@ class ThirdPartyQuota extends ModelCore
     public function needsReset(): bool
     {
         $quotaType = $this->getQuotaTypeEnum();
-        
+
         // 总计类型不需要重置
         if ($quotaType === QUOTA_TYPE::TOTAL) {
             return false;
         }
-        
+
         // 检查是否超过了当前时间窗口
         if ($this->window_end && now()->gt($this->window_end)) {
             return true;
         }
-        
+
         // 检查重置时间
         if ($this->reset_at && now()->gte($this->reset_at)) {
             return true;
         }
-        
+
         return false;
     }
 
@@ -175,14 +156,14 @@ class ThirdPartyQuota extends ModelCore
     public function resetQuota(): bool
     {
         $quotaType = $this->getQuotaTypeEnum();
-        
+
         // 计算新的时间窗口
         $windowStart = $quotaType->getCurrentWindowStart();
         $windowEnd = $quotaType->getCurrentWindowEnd();
-        
+
         // 计算下次重置时间
         $resetAt = $quotaType === QUOTA_TYPE::TOTAL ? null : $windowEnd;
-        
+
         return $this->update([
             'used_value' => 0,
             'window_start' => $windowStart,
@@ -206,16 +187,16 @@ class ThirdPartyQuota extends ModelCore
             $this->resetQuota();
             $this->refresh();
         }
-        
+
         $newUsedValue = $this->used_value + $amount;
         $updateData = ['used_value' => $newUsedValue];
-        
+
         // 检查是否超限
         if ($newUsedValue >= $this->limit_value && !$this->is_exceeded) {
             $updateData['is_exceeded'] = true;
             $updateData['exceeded_at'] = now();
         }
-        
+
         return $this->update($updateData);
     }
 
@@ -230,12 +211,12 @@ class ThirdPartyQuota extends ModelCore
         if (!$this->is_active) {
             return false;
         }
-        
+
         // 检查是否需要重置
         if ($this->needsReset()) {
             return $amount <= $this->limit_value;
         }
-        
+
         return ($this->used_value + $amount) <= $this->limit_value;
     }
 
@@ -249,15 +230,15 @@ class ThirdPartyQuota extends ModelCore
         if (!$this->is_active) {
             return 'inactive';
         }
-        
+
         if ($this->isExceeded()) {
             return 'exceeded';
         }
-        
+
         if ($this->isNearThreshold()) {
             return 'warning';
         }
-        
+
         return 'normal';
     }
 
@@ -320,19 +301,19 @@ class ThirdPartyQuota extends ModelCore
     public static function createQuota(array $data): static
     {
         $quotaType = QUOTA_TYPE::from($data['type']);
-        
+
         // 设置时间窗口
         if ($quotaType->isTimeWindow()) {
             $data['window_start'] = $quotaType->getCurrentWindowStart();
             $data['window_end'] = $quotaType->getCurrentWindowEnd();
             $data['reset_at'] = $data['window_end'];
         }
-        
+
         // 设置默认值
         $data['used_value'] = $data['used_value'] ?? 0;
         $data['is_active'] = $data['is_active'] ?? true;
         $data['alert_threshold'] = $data['alert_threshold'] ?? 80.0;
-        
+
         return static::create($data);
     }
 

+ 37 - 67
app/Module/ThirdParty/Models/ThirdPartyService.php

@@ -10,32 +10,34 @@ use Illuminate\Database\Eloquent\Relations\HasMany;
 
 /**
  * 第三方服务模型
- * 
- * @property int $id 主键ID
- * @property string $name 服务名称
- * @property string $code 服务代码
- * @property string $type 服务类型
- * @property string $provider 服务提供商
- * @property string|null $description 服务描述
- * @property string|null $base_url 基础URL
- * @property string $version API版本
- * @property string $auth_type 认证类型
- * @property string $status 服务状态
- * @property int $priority 优先级
- * @property int $timeout 超时时间
- * @property int $retry_times 重试次数
- * @property int $retry_delay 重试延迟
- * @property array|null $config 服务配置信息
- * @property array|null $headers 默认请求头
- * @property array|null $params 默认参数
- * @property string|null $webhook_url Webhook回调地址
- * @property string|null $webhook_secret Webhook密钥
- * @property string|null $health_check_url 健康检查URL
- * @property int $health_check_interval 健康检查间隔
- * @property \Carbon\Carbon|null $last_health_check 最后健康检查时间
- * @property string $health_status 健康状态
- * @property \Carbon\Carbon $created_at 创建时间
- * @property \Carbon\Carbon $updated_at 更新时间
+ *
+ * field start 
+ * @property  int  $id  主键ID
+ * @property  string  $name  服务名称
+ * @property  string  $code  服务代码(唯一标识)
+ * @property  string  $type  服务类型
+ * @property  string  $provider  服务提供商
+ * @property  string  $description  服务描述
+ * @property  string  $base_url  基础URL
+ * @property  string  $version  API版本
+ * @property  string  $auth_type  认证类型
+ * @property  string  $status  服务状态
+ * @property  int  $priority  优先级(数字越小优先级越高)
+ * @property  int  $timeout  超时时间(秒)
+ * @property  int  $retry_times  重试次数
+ * @property  int  $retry_delay  重试延迟(毫秒)
+ * @property  array  $config  服务配置信息
+ * @property  array  $headers  默认请求头
+ * @property  array  $params  默认参数
+ * @property  string  $webhook_url  Webhook回调地址
+ * @property  string  $webhook_secret  Webhook密钥
+ * @property  string  $health_check_url  健康检查URL
+ * @property  int  $health_check_interval  健康检查间隔(秒)
+ * @property  \Carbon\Carbon  $last_health_check  最后健康检查时间
+ * @property  string  $health_status  健康状态
+ * @property  \Carbon\Carbon  $created_at  创建时间
+ * @property  \Carbon\Carbon  $updated_at  更新时间
+ * field end
  */
 class ThirdPartyService extends ModelCore
 {
@@ -46,39 +48,7 @@ class ThirdPartyService extends ModelCore
      */
     protected $table = 'thirdparty_services';
 
-    // field start
-    /**
-     * 可批量赋值的属性
-     *
-     * @var array
-     */
-    // attrlist start
-    protected $fillable = [
-        'name',
-        'code',
-        'type',
-        'provider',
-        'description',
-        'base_url',
-        'version',
-        'auth_type',
-        'status',
-        'priority',
-        'timeout',
-        'retry_times',
-        'retry_delay',
-        'config',
-        'headers',
-        'params',
-        'webhook_url',
-        'webhook_secret',
-        'health_check_url',
-        'health_check_interval',
-        'last_health_check',
-        'health_status',
-    ];
-    // attrlist end
-    // field end
+
 
     /**
      * 属性类型转换
@@ -199,11 +169,11 @@ class ThirdPartyService extends ModelCore
     {
         $baseUrl = rtrim($this->base_url, '/');
         $endpoint = ltrim($endpoint, '/');
-        
+
         if (empty($endpoint)) {
             return $baseUrl;
         }
-        
+
         return $baseUrl . '/' . $endpoint;
     }
 
@@ -215,14 +185,14 @@ class ThirdPartyService extends ModelCore
     public function getDefaultHeaders(): array
     {
         $headers = $this->headers ?? [];
-        
+
         // 添加认证相关的默认头
         $authType = $this->getAuthTypeEnum();
         if ($authType->getHeaderName()) {
             $headers['Content-Type'] = 'application/json';
             $headers['Accept'] = 'application/json';
         }
-        
+
         return $headers;
     }
 
@@ -318,11 +288,11 @@ class ThirdPartyService extends ModelCore
         if (!$this->health_check_url) {
             return false;
         }
-        
+
         if (!$this->last_health_check) {
             return true;
         }
-        
+
         $nextCheck = $this->last_health_check->addSeconds($this->health_check_interval);
         return now()->gte($nextCheck);
     }
@@ -338,7 +308,7 @@ class ThirdPartyService extends ModelCore
     {
         $code = strtolower($provider . '_' . str_replace(' ', '_', $name));
         $code = preg_replace('/[^a-z0-9_]/', '', $code);
-        
+
         // 确保代码唯一
         $counter = 1;
         $originalCode = $code;
@@ -346,7 +316,7 @@ class ThirdPartyService extends ModelCore
             $code = $originalCode . '_' . $counter;
             $counter++;
         }
-        
+
         return $code;
     }
 }