package entities import ( "fmt" "time" "github.com/google/uuid" "gorm.io/gorm" ) // EnterpriseInfo 企业信息实体 // 存储用户在认证过程中验证后的企业信息,认证完成后不可修改 // 与用户是一对一关系,每个用户最多对应一个企业信息 type EnterpriseInfo struct { // 基础标识 ID string `gorm:"primaryKey;type:varchar(36)" json:"id" comment:"企业信息唯一标识"` UserID string `gorm:"type:varchar(36);not null;uniqueIndex" json:"user_id" comment:"关联用户ID"` // 企业四要素 - 企业认证的核心信息 CompanyName string `gorm:"type:varchar(255);not null" json:"company_name" comment:"企业名称"` UnifiedSocialCode string `gorm:"type:varchar(50);not null;index" json:"unified_social_code" comment:"统一社会信用代码"` LegalPersonName string `gorm:"type:varchar(100);not null" json:"legal_person_name" comment:"法定代表人姓名"` LegalPersonID string `gorm:"type:varchar(50);not null" json:"legal_person_id" comment:"法定代表人身份证号"` LegalPersonPhone string `gorm:"type:varchar(50);not null" json:"legal_person_phone" comment:"法定代表人手机号"` // 时间戳字段 CreatedAt time.Time `gorm:"autoCreateTime" json:"created_at" comment:"创建时间"` UpdatedAt time.Time `gorm:"autoUpdateTime" json:"updated_at" comment:"更新时间"` DeletedAt gorm.DeletedAt `gorm:"index" json:"-" comment:"软删除时间"` // 关联关系 User *User `gorm:"foreignKey:UserID" json:"user,omitempty" comment:"关联的用户信息"` } // TableName 指定数据库表名 func (EnterpriseInfo) TableName() string { return "enterprise_infos" } // IsComplete 检查企业四要素是否完整 // 验证企业名称、统一社会信用代码、法定代表人姓名、身份证号是否都已填写 func (e *EnterpriseInfo) IsComplete() bool { return e.CompanyName != "" && e.UnifiedSocialCode != "" && e.LegalPersonName != "" && e.LegalPersonID != "" } // Validate 验证企业信息是否有效 // 这里可以添加企业信息的业务验证逻辑 // 比如统一社会信用代码格式验证、身份证号格式验证等 func (e *EnterpriseInfo) Validate() error { if !e.IsComplete() { return fmt.Errorf("企业信息不完整") } // 这里可以添加企业信息的业务验证逻辑 // 比如统一社会信用代码格式验证、身份证号格式验证等 return nil } // BeforeCreate GORM钩子:创建前自动生成UUID func (e *EnterpriseInfo) BeforeCreate(tx *gorm.DB) error { if e.ID == "" { e.ID = uuid.New().String() } return nil }