Files
tyapi-server/internal/domains/user/entities/enterprise_info.go

69 lines
2.6 KiB
Go
Raw Normal View History

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