Files
junhong_cmp_fiber/internal/model/account.go
huang a36e4a79c0 实现用户和组织模型(店铺、企业、个人客户)
核心功能:
- 实现 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>
2026-01-09 18:02:46 +08:00

24 lines
1.2 KiB
Go
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.
package model
import (
"gorm.io/gorm"
)
// Account 账号模型
type Account struct {
gorm.Model
BaseModel `gorm:"embedded"`
Username string `gorm:"column:username;type:varchar(50);uniqueIndex:idx_account_username,where:deleted_at IS NULL;not null;comment:用户名" json:"username"`
Phone string `gorm:"column:phone;type:varchar(20);uniqueIndex:idx_account_phone,where:deleted_at IS NULL;not null;comment:手机号" json:"phone"`
Password string `gorm:"column:password;type:varchar(255);not null;comment:密码" json:"-"` // 不返回给客户端
UserType int `gorm:"column:user_type;type:int;not null;index;comment:用户类型 1=超级管理员 2=平台用户 3=代理账号 4=企业账号" json:"user_type"`
ShopID *uint `gorm:"column:shop_id;index;comment:店铺ID代理账号必填" json:"shop_id,omitempty"`
EnterpriseID *uint `gorm:"column:enterprise_id;index;comment:企业ID企业账号必填" json:"enterprise_id,omitempty"`
Status int `gorm:"column:status;type:int;not null;default:1;comment:状态 0=禁用 1=启用" json:"status"`
}
// TableName 指定表名
func (Account) TableName() string {
return "tb_account"
}