This commit is contained in:
henry
2021-11-24 09:59:29 +08:00
parent cf91d55ab2
commit f007168919
21 changed files with 360 additions and 93 deletions

View File

@ -1,7 +1,9 @@
package model
import (
"SciencesServer/config"
"SciencesServer/utils"
"strings"
)
type Gender struct {
@ -108,6 +110,23 @@ type Area struct {
Address string `gorm:"column:address;type:varchar(255);default:null;comment:详细地址" json:"address"`
}
func (m *Area) FormatBasic() string {
address := make([]string, 0)
address = append(address, config.SettingAreaInfo[config.DefaultChinaAreaCode][m.Province])
if m.City != "" {
address = append(address, config.SettingAreaInfo[m.Province][m.City])
}
if m.District != "" {
address = append(address, config.SettingAreaInfo[m.City][m.District])
}
return strings.Join(address, "-")
}
func (m *Area) FormatDetail() string {
return m.FormatBasic() + "" + m.Address
}
// Position 坐标信息
type Position struct {
Longitude float64 `json:"longitude"` // 经度

View File

@ -10,23 +10,34 @@ import (
type UserInstance struct {
Model
Local
UUID uint64 `gorm:"column:uuid;uniqueIndex:idx_tenant_user_uuid;type:int;default:0;comment:用户唯一UUID" json:"-"`
Name string `gorm:"column:name;type:varchar(20);default:null;comment:真实姓名" json:"name"`
Mobile string `gorm:"column:mobile;index:idx_user_instance_mobile;type:varchar(15);default:null;comment:联系方式" json:"mobile"`
Identity int `gorm:"column:identity;type:int(8);default:0;comment:身份信息" json:"-"`
Password string `gorm:"column:password;type:varchar(100);default:null;comment:密码" json:"-"`
Salt string `gorm:"column:salt;type:varchar(10);default:null;comment:盐值" json:"-"`
UUID uint64 `gorm:"column:-;uniqueIndex:idx_tenant_user_uuid;type:int;default:0;comment:用户唯一UUID" json:"-"`
Source UserInstanceSource `gorm:"column:source;type:tinyint(1);default:1;comment:账号来源" json:"source"`
Name string `gorm:"column:name;type:varchar(20);default:null;comment:真实姓名" json:"name"`
Mobile string `gorm:"column:mobile;index:idx_user_instance_mobile;type:varchar(15);default:null;comment:联系方式" json:"mobile"`
Identity int `gorm:"column:identity;type:int(8);default:0;comment:身份信息" json:"-"`
Password string `gorm:"column:password;type:varchar(100);default:null;comment:密码" json:"-"`
Salt string `gorm:"column:salt;type:varchar(10);default:null;comment:盐值" json:"-"`
AccountStatus
ModelDeleted
ModelAt
}
// UserInstanceSource 账号来源
type UserInstanceSource int
const (
// UserInstanceSourceForLocal 本地注册
UserInstanceSourceForLocal UserInstanceSource = iota + 1
// UserInstanceSourceForWechat 微信登陆
UserInstanceSourceForWechat
)
func (m *UserInstance) TableName() string {
return "user_instance"
}
func (m *UserInstance) BeforeCreate(db *gorm.DB) error {
m.NewPassword()
m.SetPasswordAttribute()
snowflake, _ := utils.NewSnowflake(1)
m.UUID = uint64(snowflake.GetID())
m.Status = AccountStatusForEnable
@ -34,7 +45,7 @@ func (m *UserInstance) BeforeCreate(db *gorm.DB) error {
return nil
}
func (m *UserInstance) NewPassword() {
func (m *UserInstance) SetPasswordAttribute() {
m.Salt = utils.GetRandomString(8)
m.Password = utils.HashString([]byte(utils.Md5String(m.Password, m.Salt)))
}

View File

@ -32,14 +32,32 @@ type IUserIdentity interface {
type (
// UserIdentityForCompany 公司信息
UserIdentityForCompany struct {
Industry string `json:"industry"`
Keyword string `json:"keyword"`
Industry string `json:"industry"`
Keyword string `json:"keyword"`
CreatedAt time.Time `json:"created_at"`
}
// UserIdentityForExpert 专家信息
UserIdentityForExpert struct {
Industry string `json:"industry"`
Keyword string `json:"keyword"`
Research string `json:"research"`
Industry string `json:"industry"`
Keyword string `json:"keyword"`
Research string `json:"research"`
CreatedAt time.Time `json:"created_at"`
}
// UserIdentityForResearch 研究机构信息
UserIdentityForResearch struct {
Name string `json:"name"`
Industry string `json:"industry"`
Keyword string `json:"keyword"`
Research string `json:"research"`
CreatedAt time.Time `json:"created_at"`
}
// UserIdentityForLaboratory 实验室信息
UserIdentityForLaboratory struct {
Name string `json:"name"`
Industry string `json:"industry"`
Keyword string `json:"keyword"`
Research string `json:"research"`
CreatedAt time.Time `json:"created_at"`
}
)
@ -53,6 +71,16 @@ func (this *UserIdentityForExpert) Analysis(src string) interface{} {
return this
}
func (this *UserIdentityForResearch) Analysis(src string) interface{} {
utils.FromJSON(src, this)
return this
}
func (this *UserIdentityForLaboratory) Analysis(src string) interface{} {
utils.FromJSON(src, this)
return this
}
type UserManageSelected int
const (