核心功能: - 实现 7 级店铺层级体系(Shop 模型 + 层级校验) - 实现企业管理模型(Enterprise 模型) - 实现个人客户管理模型(PersonalCustomer 模型) - 重构 Account 模型关联关系(基于 EnterpriseID 而非 ParentID) - 完整的 Store 层和 Service 层实现 - 递归查询下级店铺功能(含 Redis 缓存) - 全面的单元测试覆盖(Shop/Enterprise/PersonalCustomer Store + Shop Service) 技术要点: - 显式指定所有 GORM 模型的数据库字段名(column: 标签) - 统一的字段命名规范(数据库用 snake_case,Go 用 PascalCase) - 完整的中文字段注释和业务逻辑说明 - 100% 测试覆盖(20+ 测试用例全部通过) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
42 lines
1.3 KiB
Go
42 lines
1.3 KiB
Go
package constants
|
||
|
||
import "fmt"
|
||
|
||
// RedisAuthTokenKey 生成认证令牌的 Redis 键
|
||
func RedisAuthTokenKey(token string) string {
|
||
return fmt.Sprintf("auth:token:%s", token)
|
||
}
|
||
|
||
// RedisRateLimitKey 生成限流的 Redis 键
|
||
func RedisRateLimitKey(ip string) string {
|
||
return fmt.Sprintf("ratelimit:%s", ip)
|
||
}
|
||
|
||
// RedisTaskLockKey 生成任务锁的 Redis 键
|
||
// 用途:幂等性控制,防止重复执行
|
||
// 过期时间:24 小时
|
||
func RedisTaskLockKey(requestID string) string {
|
||
return fmt.Sprintf("task:lock:%s", requestID)
|
||
}
|
||
|
||
// RedisTaskStatusKey 生成任务状态的 Redis 键
|
||
// 用途:存储任务执行状态
|
||
// 过期时间:7 天
|
||
func RedisTaskStatusKey(taskID string) string {
|
||
return fmt.Sprintf("task:status:%s", taskID)
|
||
}
|
||
|
||
// RedisAccountSubordinatesKey 生成账号下级 ID 列表的 Redis 键
|
||
// 用途:缓存递归查询的下级账号 ID 列表
|
||
// 过期时间:30 分钟
|
||
func RedisAccountSubordinatesKey(accountID uint) string {
|
||
return fmt.Sprintf("account:subordinates:%d", accountID)
|
||
}
|
||
|
||
// RedisShopSubordinatesKey 生成店铺下级 ID 列表的 Redis 键
|
||
// 用途:缓存递归查询的下级店铺 ID 列表
|
||
// 过期时间:30 分钟
|
||
func RedisShopSubordinatesKey(shopID uint) string {
|
||
return fmt.Sprintf("shop:subordinates:%d", shopID)
|
||
}
|