longgexx
d6f8ac0226
fix(billing): 修复计费漏洞
...
- 允许余额透支策略
## 问题
- 扣费失败时只记录日志,不阻止请求完成
- 用户可以用极少余额无限次免费使用服务
- 数据库层使用 BalanceGTE 条件防止余额变负,导致余额不足时扣费失败
## 修复
- 移除 DeductBalance 方法中的 BalanceGTE 条件,允许余额变为负数
- 修改错误返回:用户不存在时返回 ErrUserNotFound
- 实现透支策略:余额不足时允许本次请求完成,余额变负后阻止后续请求
## 测试
- 更新 TestDeductBalance_InsufficientFunds 测试,验证透支功能
- 更新 TestDeductBalance_NotFound 测试,验证正确的错误类型
- 新增 TestDeductBalance_AllowsOverdraft 测试,专门测试透支场景
- 所有测试通过 ✅
2026-01-05 18:48:49 +08:00
ianshaw
519b0b245a
fix(lint): 修复 golangci-lint 检查问题
...
- 格式化代码 (gofmt)
- 修复 rows.Close() 返回值未检查 (errcheck)
- 删除未使用的 usage_clamp.go 文件 (unused)
- 删除临时测试目录
2026-01-03 06:57:08 -08:00
ianshaw
112a2d0866
chore: 更新依赖、配置和代码生成
...
主要更新:
- 更新 go.mod/go.sum 依赖
- 重新生成 Ent ORM 代码
- 更新 Wire 依赖注入配置
- 添加 docker-compose.override.yml 到 .gitignore
- 更新 README 文档(Simple Mode 说明和已知问题)
- 清理调试日志
- 其他代码优化和格式修复
2026-01-03 06:37:08 -08:00
Edric Li
404bf0f8d2
refactor: migrate wechat to user attributes and enhance users list
...
Migrate the hardcoded wechat field to the new extensible user
attributes system and improve the users management UI.
Migration:
- Add migration 019 to move wechat data to user_attribute_values
- Remove wechat field from User entity, DTOs, and API contracts
- Clean up wechat-related code from backend and frontend
UsersView enhancements:
- Add text labels to action buttons (Filter Settings, Column Settings,
Attributes Config) for better UX
- Change status column to show colored dot + Chinese text instead of
English text
- Add dynamic attribute columns support with batch loading
- Add column visibility settings with localStorage persistence
- Add filter settings modal for search and filter preferences
- Update i18n translations
🤖 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com >
2026-01-01 18:59:38 +08:00
yangjianbo
682f546c0e
fix(lint): 修复 golangci-lint 报告的代码问题
...
- errcheck: 修复类型断言未检查返回值的问题
- pool.go: 添加 sync.Map 类型断言安全检查
- req_client_pool.go: 添加 sync.Map 类型断言安全检查
- concurrency_cache_benchmark_test.go: 显式忽略断言返回值
- gateway_service.go: 显式忽略 WriteString 返回值
- gofmt: 修复代码格式问题
- redis.go: 注释对齐
- api_key_repo.go: 结构体字段对齐
- concurrency_cache.go: 字段对齐
- http_upstream.go: 注释对齐
- unused: 删除未使用的代码
- user_repo.go: 删除未使用的 sql 字段
- usage_service.go: 删除未使用的 calculateStats 函数
🤖 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com >
2025-12-31 14:51:58 +08:00
yangjianbo
5906f9ab98
fix(数据层): 修复数据完整性与仓储一致性问题
...
## 数据完整性修复 (fix-critical-data-integrity)
- 添加 error_translate.go 统一错误转换层
- 修复 nil 输入和 NotFound 错误处理
- 增强仓储层错误一致性
## 仓储一致性修复 (fix-high-repository-consistency)
- Group schema 添加 default_validity_days 字段
- Account schema 添加 proxy edge 关联
- 新增 UsageLog ent schema 定义
- 修复 UpdateBalance/UpdateConcurrency 受影响行数校验
## 数据卫生修复 (fix-medium-data-hygiene)
- UserSubscription 添加软删除支持 (SoftDeleteMixin)
- RedeemCode/Setting 添加硬删除策略文档
- account_groups/user_allowed_groups 的 created_at 声明 timestamptz
- 停止写入 legacy users.allowed_groups 列
- 新增迁移: 011-014 (索引优化、软删除、孤立数据审计、列清理)
## 测试补充
- 添加 UserSubscription 软删除测试
- 添加迁移回归测试
- 添加 NotFound 错误测试
🤖 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com >
2025-12-31 14:11:57 +08:00
yangjianbo
aacbc98aec
fix(仓储): 修复查询关闭错误并迁移集成测试
...
修复 rows.Close 失败时的错误返回逻辑
迁移网关路由集成测试到 ent 事务基建
补齐仓储接口变更对应的测试桩方法
新增 backend/Makefile 统一测试命令
测试: GOTOOLCHAIN=go1.24.11 go test ./...
测试: golangci-lint run ./... --timeout=5m
测试: make test-integration
2025-12-30 16:41:45 +08:00
yangjianbo
ae191f72a4
fix(仓储): 修复软删除过滤与事务测试
...
修复软删除拦截器使用错误,确保默认查询过滤已删记录
仓储层改用 ent.Tx 与扫描辅助,避免 sql.Tx 断言问题
同步更新集成测试以覆盖事务与统计变动
2025-12-29 19:23:49 +08:00
yangjianbo
4dab18a94f
fix(用户): 修复删除用户软删除钩子
...
避免软删除钩子类型断言失败导致 500\n删除无记录时返回未找到错误并记录日志
2025-12-29 16:57:50 +08:00
yangjianbo
5584709ac9
fix(仓储层): 修复事务 ent client 调用 Close() 导致的 panic
...
问题:创建用户时发生 panic,错误信息为
"interface conversion: sql.ExecQuerier is *sql.Tx, not *sql.DB"
原因:基于事务创建的 ent client 在调用 Close() 时,ent 的 sql driver
会尝试将 ExecQuerier 断言为 *sql.DB 来关闭连接,但实际类型是 *sql.Tx
修复:移除对 txClient.Close() 的调用,事务的清理通过
sqlTx.Rollback() 和 sqlTx.Commit() 完成即可
影响范围:
- user_repo.go: Create 和 Update 方法
- group_repo.go: Delete 方法
🤖 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com >
2025-12-29 15:49:20 +08:00
yangjianbo
3d617de577
refactor(数据库): 迁移持久层到 Ent 并清理 GORM
...
将仓储层/基础设施改为 Ent + 原生 SQL 执行路径,并移除 AutoMigrate 与 GORM 依赖。
重构内容包括:
- 仓储层改用 Ent/SQL(含 usage_log/account 等复杂查询),统一错误映射
- 基础设施与 setup 初始化切换为 Ent + SQL migrations
- 集成测试与 fixtures 迁移到 Ent 事务模型
- 清理遗留 GORM 模型/依赖,补充迁移与文档说明
- 增加根目录 Makefile 便于前后端编译
测试:
- go test -tags unit ./...
- go test -tags integration ./...
2025-12-29 10:03:27 +08:00
Forest
e5a77853b0
refactor: 调整项目结构为单向依赖
2025-12-26 16:45:40 +08:00
Forest
eeaff85e47
refactor: 自定义业务错误
2025-12-25 21:06:40 +08:00
Forest
836c4dda2b
refactor: 重命名 go module
2025-12-24 21:07:21 +08:00
dexcoder6
0b8e84f942
feat: 增强用户管理功能,添加用户名、微信号和备注字段
...
- 新增User模型字段:username(用户名)、wechat(微信号)、notes(备注)
- 扩展用户搜索功能,支持通过用户名和微信号搜索
- 添加用户个人资料更新功能,用户可自行编辑用户名和微信号
- 管理员用户列表新增用户名、微信号、备注显示列
- 备注字段仅对管理员可见,增强数据安全性
- 完善中英文国际化翻译
- 修复国际化文件中重复属性的TypeScript错误
🤖 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com >
2025-12-23 11:26:22 +08:00
shaw
f0fabf89a1
feat: 用户列表显示订阅分组及剩余天数
...
- User模型新增Subscriptions关联
- 用户列表批量加载订阅信息避免N+1查询
- GroupBadge组件支持显示剩余天数(过期红色、<=3天红色、<=7天橙色)
- 用户管理页面新增订阅分组列
2025-12-23 11:03:10 +08:00
shaw
587012396b
feat: 支持创建管理员APIKEY
2025-12-20 15:11:43 +08:00
Forest
e99b344b2b
refactor(backend): 引入端口接口模式
2025-12-19 21:26:19 +08:00
shaw
642842c29e
First commit
2025-12-18 13:50:39 +08:00