id(); $table->string('provider', 50)->index()->comment('厂商标识(如 deepseek, qwen, openai)'); $table->string('name', 100)->comment('厂商显示名称'); $table->text('api_key')->comment('API Key(加密存储)'); $table->string('api_endpoint', 255)->comment('API 端点地址'); $table->string('model', 100)->comment('使用的模型名称'); $table->decimal('temperature', 3, 2)->default(0.30)->comment('温度参数'); $table->integer('max_tokens')->default(2048)->comment('最大 Token 数'); $table->boolean('is_enabled')->default(true)->index()->comment('是否启用'); $table->boolean('is_default')->default(false)->comment('是否为默认厂商'); $table->integer('sort_order')->default(0)->comment('排序(故障转移时按此顺序)'); $table->timestamps(); }); // AI 使用日志表 Schema::create('ai_usage_logs', function (Blueprint $table) { $table->id(); $table->foreignId('user_id')->nullable()->constrained('users')->nullOnDelete()->comment('使用者'); $table->string('provider', 50)->comment('AI 厂商标识'); $table->string('model', 100)->comment('使用的模型'); $table->string('action', 50)->default('chatbot')->comment('操作类型'); $table->integer('prompt_tokens')->default(0)->comment('输入 Token 数'); $table->integer('completion_tokens')->default(0)->comment('输出 Token 数'); $table->integer('total_tokens')->default(0)->comment('总 Token 数'); $table->decimal('cost', 10, 6)->default(0)->comment('费用'); $table->integer('response_time_ms')->default(0)->comment('响应时间(毫秒)'); $table->boolean('success')->default(true)->comment('是否成功'); $table->text('error_message')->nullable()->comment('错误信息'); $table->timestamps(); // 索引 $table->index(['provider', 'created_at']); }); } /** * 回滚迁移:删除 AI 相关的两张数据表 */ public function down(): void { Schema::dropIfExists('ai_usage_logs'); Schema::dropIfExists('ai_provider_configs'); } };