Files
xianyan/docs/toolsapi/application/admin/controller/FeatureFlag.php
Developer f91be94e9c refactor: 完成项目架构重构,统一模块导入路径
- 清理大量废弃的 barrel 导出文件,移除冗余的中间导出层
- 修复所有相对路径导入错误,统一调整为扁平化模块引用
- 更新多平台 pubspec 版本号与依赖库版本
- 补充后端功能问题管理后台与脚本工具
- 调整部分页面的快捷方式文案适配新功能
- 更新部分翻译覆盖率与API文档
2026-06-12 08:53:57 +08:00

112 lines
7.1 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
namespace app\admin\controller;
use app\common\controller\Backend;
/**
* 功能标志管理
* @icon fa fa-flag
* @time 2026-06-12
* @description 管理Feature Flag远程配置支持灰度发布和A/B测试
*/
class FeatureFlag extends Backend
{
protected $model = null;
protected $searchFields = 'id,flag_key,name';
public function _initialize()
{
parent::_initialize();
$this->model = new \app\admin\model\FeatureFlag;
}
/**
* @name 安装/初始化数据表
* @desc 创建tool_feature_flag表并插入默认数据
*/
public function install()
{
$sql = <<<SQL
CREATE TABLE IF NOT EXISTS `tool_feature_flag` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`flag_key` varchar(64) NOT NULL DEFAULT '' COMMENT '标志键名',
`name` varchar(100) NOT NULL DEFAULT '' COMMENT '功能名称',
`description` varchar(500) NOT NULL DEFAULT '' COMMENT '功能描述',
`emoji` varchar(16) NOT NULL DEFAULT '' COMMENT '图标emoji',
`enabled` tinyint(1) NOT NULL DEFAULT 0 COMMENT '是否启用 0否1是',
`status` enum('developing','testing','preview','released') NOT NULL DEFAULT 'developing' COMMENT '状态',
`progress` decimal(3,2) NOT NULL DEFAULT 0.00 COMMENT '开发进度 0.00~1.00',
`rollout_percentage` decimal(3,2) NOT NULL DEFAULT 0.00 COMMENT '灰度比例 0.00~1.00',
`target_group` varchar(100) DEFAULT NULL COMMENT 'A/B测试分组',
`expires_at` varchar(30) DEFAULT NULL COMMENT '过期时间',
`weigh` int(11) NOT NULL DEFAULT 0 COMMENT '排序权重',
`status_text` varchar(30) NOT NULL DEFAULT '' COMMENT '状态标签文本',
`createtime` int(11) unsigned NOT NULL DEFAULT 0 COMMENT '创建时间',
`updatetime` int(11) unsigned NOT NULL DEFAULT 0 COMMENT '更新时间',
PRIMARY KEY (`id`),
UNIQUE KEY `uk_flag_key` (`flag_key`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='功能标志配置表';
SQL;
try {
\think\Db::execute($sql);
// 插入默认数据(如已有则跳过)
$defaults = [
['flag_key' => 'ai_summary', 'name' => '图片编辑器', 'description' => '全功能全量的图片编辑能力', 'emoji' => '🎨', 'enabled' => 1, 'status' => 'developing', 'progress' => 0.70, 'rollout_percentage' => 0.30, 'target_group' => '', 'expires_at' => '', 'weigh' => 100, 'status_text' => '开发中'],
['flag_key' => 'theme_store', 'name' => '工具中心', 'description' => '自定义导入工具,更完善的工具', 'emoji' => '🔧', 'enabled' => 0, 'status' => 'developing', 'progress' => 0.40, 'rollout_percentage' => 0.10, 'target_group' => '', 'expires_at' => '', 'weigh' => 90, 'status_text' => '开发中'],
['flag_key' => 'reading_report', 'name' => '阅读报告', 'description' => '年度/月度阅读数据可视化', 'emoji' => '📊', 'enabled' => 1, 'status' => 'preview', 'progress' => 0.90, 'rollout_percentage' => 0.50, 'target_group' => '', 'expires_at' => '', 'weigh' => 80, 'status_text' => '预览中'],
['flag_key' => 'cross_device_sync', 'name' => '跨设备同步', 'description' => '实时同步阅读进度和收藏', 'emoji' => '🔄', 'enabled' => 0, 'status' => 'developing', 'progress' => 0.30, 'rollout_percentage' => 0.00, 'target_group' => '', 'expires_at' => '', 'weigh' => 70, 'status_text' => '开发中'],
['flag_key' => 'voice_reading', 'name' => '语音朗读', 'description' => '全文朗读功能,连贯的语音朗读,不受打断', 'emoji' => '🎵', 'enabled' => 1, 'status' => 'testing', 'progress' => 0.60, 'rollout_percentage' => 0.20, 'target_group' => 'ab_test_voice', 'expires_at' => '', 'weigh' => 60, 'status_text' => '测试中'],
['flag_key' => 'home_widget', 'name' => '桌面小组件', 'description' => 'iOS/Android/Harmony桌面Widget', 'emoji' => '📱', 'enabled' => 1, 'status' => 'preview', 'progress' => 0.85, 'rollout_percentage' => 0.80, 'target_group' => '', 'expires_at' => '', 'weigh' => 50, 'status_text' => '预览中'],
['flag_key' => 'nearby_discovery', 'name' => '近场发现', 'description' => '基于蓝牙/WiFi的近场内容发现', 'emoji' => '📡', 'enabled' => 0, 'status' => 'developing', 'progress' => 0.15, 'rollout_percentage' => 0.00, 'target_group' => '', 'expires_at' => '', 'weigh' => 40, 'status_text' => '开发中'],
['flag_key' => 'shader_background', 'name' => '特效背景', 'description' => 'Metal/Vulkan着色器动态背景', 'emoji' => '✨', 'enabled' => 0, 'status' => 'developing', 'progress' => 0.25, 'rollout_percentage' => 0.00, 'target_group' => '', 'expires_at' => '', 'weigh' => 30, 'status_text' => '开发中'],
['flag_key' => 'plus_chat', 'name' => '插件', 'description' => '完整的插件功能可提升用户体验', 'emoji' => '🔌', 'enabled' => 0, 'status' => 'preview', 'progress' => 0.25, 'rollout_percentage' => 0.80, 'target_group' => '', 'expires_at' => '', 'weigh' => 20, 'status_text' => '预览中'],
['flag_key' => 'collaboration_canvas', 'name' => '协作画布', 'description' => '实时多人协作绘制画布,支持画笔/形状/橡皮/同步/导出', 'emoji' => '🎨', 'enabled' => 0, 'status' => 'developing', 'progress' => 0.50, 'rollout_percentage' => 0.00, 'target_group' => '', 'expires_at' => '', 'weigh' => 10, 'status_text' => '开发中'],
['flag_key' => 'screen_share', 'name' => '屏幕共享', 'description' => '实时共享屏幕画面,支持远程观看和受限操作', 'emoji' => '📺', 'enabled' => 0, 'status' => 'developing', 'progress' => 0.35, 'rollout_percentage' => 0.00, 'target_group' => '', 'expires_at' => '', 'weigh' => 5, 'status_text' => '开发中'],
];
$count = \think\Db::name('feature_flag')->count();
if ($count == 0) {
$now = time();
foreach ($defaults as &$item) {
$item['createtime'] = $now;
$item['updatetime'] = $now;
}
\think\Db::name('feature_flag')->insertAll($defaults);
$this->success('安装成功,已插入 ' . count($defaults) . ' 条默认数据');
} else {
$this->success('数据表已存在,已有 ' . $count . ' 条数据');
}
} catch (\Exception $e) {
$this->error('安装失败: ' . $e->getMessage());
}
}
/**
* @name 同步status_text字段
* @desc 根据status自动更新status_text标签文本
*/
public function sync_status_text()
{
$map = [
'developing' => '开发中',
'testing' => '测试中',
'preview' => '预览中',
'released' => '已发布',
];
$updated = 0;
foreach ($map as $status => $text) {
$cnt = \think\Db::name('feature_flag')
->where('status', $status)
->where('status_text', '<>', $text)
->update(['status_text' => $text, 'updatetime' => time()]);
$updated += $cnt;
}
$this->success("同步完成,更新 {$updated} 条记录");
}
}