功能:VIP 赞助会员系统

- 新建 vip_levels 表(名称、图标、颜色、经验/金币倍率、专属进入/离开模板)
- 默认4个等级种子:白银🥈(×1.5)、黄金🥇(×2.0)、钻石💎(×3.0)、至尊👑(×5.0)
- 后台 VIP 等级 CRUD 管理(新增/编辑/删除,配置模板和倍率)
- 后台用户编辑弹窗支持设置 VIP 等级和到期时间
- ChatController 心跳经验按 VIP 倍率加成
- FishingController 正向奖励按 VIP 倍率加成(负面惩罚不变)
- 在线名单显示 VIP 图标和管理员🛡️标识
- VIP 用户进入/离开使用专属颜色和标题
- 后台侧栏新增「👑 VIP 会员等级」入口
This commit is contained in:
2026-02-26 21:30:07 +08:00
parent ea06328885
commit fd3214eaff
22 changed files with 2293 additions and 19 deletions

View File

@@ -0,0 +1,126 @@
<?php
/**
* 文件功能AI 厂商配置模型
*
* 对应 ai_provider_configs 表,管理多个 AI 厂商的 API 配置。
* 支持多厂商切换、默认配置、自动故障转移等功能。
*
* @author ChatRoom Laravel
*
* @version 1.0.0
*/
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Crypt;
class AiProviderConfig extends Model
{
/**
* 关联的数据库表名
*
* @var string
*/
protected $table = 'ai_provider_configs';
/**
* 可批量赋值的属性
*
* @var array<int, string>
*/
protected $fillable = [
'provider',
'name',
'api_key',
'api_endpoint',
'model',
'temperature',
'max_tokens',
'is_enabled',
'is_default',
'sort_order',
];
/**
* 属性类型转换
*
* @return array<string, string>
*/
protected function casts(): array
{
return [
'temperature' => 'float',
'max_tokens' => 'integer',
'is_enabled' => 'boolean',
'is_default' => 'boolean',
'sort_order' => 'integer',
];
}
/**
* 获取解密后的 API Key
*
* @return string|null 解密后的 API Key
*/
public function getDecryptedApiKey(): ?string
{
if (empty($this->api_key)) {
return null;
}
try {
return Crypt::decryptString($this->api_key);
} catch (\Exception) {
// 如果解密失败(可能是明文存储的旧数据),直接返回原值
return $this->api_key;
}
}
/**
* 设置加密存储的 API Key
*
* @param string $value 原始 API Key
*/
public function setApiKeyEncrypted(string $value): void
{
$this->api_key = Crypt::encryptString($value);
}
/**
* 获取当前默认的 AI 配置
*
* 返回 is_default=1 is_enabled=1 的第一条配置。
* 如果没有设置默认,则返回第一条已启用的配置。
*/
public static function getDefault(): ?self
{
// 优先获取标记为默认且已启用的
$default = static::where('is_default', true)
->where('is_enabled', true)
->first();
if ($default) {
return $default;
}
// 退而求其次,取第一个已启用的
return static::where('is_enabled', true)
->orderBy('sort_order')
->first();
}
/**
* 获取所有已启用的 AI 厂商配置(按 sort_order 排序)
*
* 用于故障转移时依次尝试备用厂商。
*/
public static function getEnabledProviders(): \Illuminate\Database\Eloquent\Collection
{
return static::where('is_enabled', true)
->orderBy('is_default', 'desc') // 默认的排最前面
->orderBy('sort_order')
->get();
}
}