feat:完善信息

This commit is contained in:
henry
2021-09-30 16:20:00 +08:00
parent 161df42060
commit bd788b8b7e
7 changed files with 118 additions and 37 deletions

View File

@ -1,8 +1,18 @@
package config
// Area 区域
type Area struct {
Province uint64 `json:"province"`
City uint64 `json:"city"`
District uint64 `json:"district"`
Address string `json:"address"`
}
type (
// IdentityForCompany 公身份信息
IdentityForCompany struct {
Name string `json:"name"` // 公司企业名称
Code string `json:"code"` // 企业代码
Area
}
)

View File

@ -0,0 +1,21 @@
package config
// TenantUserIdentity 租户用户身份信息
type TenantUserIdentity int
const (
TenantUserIdentityForPerson int = 0 // 0
TenantUserIdentityForCompany int = 1 // 1
TenantUserIdentityForExpert int = 1 << 1 // 2
TenantUserIdentityForResearch int = 1 << 2 // 4
TenantUserIdentityForLaboratory int = 1 << 3 // 8
TenantUserIdentityForAgent int = 1 << 4 // 16
)
// TenantUserIdentityData 用户身份信息
var TenantUserIdentityData = map[int]string{
TenantUserIdentityForPerson: "个人",
TenantUserIdentityForCompany: "企业", TenantUserIdentityForExpert: "专家",
TenantUserIdentityForResearch: "研究机构", TenantUserIdentityForLaboratory: "实验室",
TenantUserIdentityForAgent: "科技经纪人",
}

View File

@ -66,9 +66,11 @@ const (
AccountStatusForDisable
)
// Format 格式化
func (m *AccountStatus) Format() string {
return utils.AnyToJSON(m)
type Area struct {
Province uint64 `gorm:"column:province;type:int;default:0;comment:所在省" json:"province"`
City uint64 `gorm:"column:city;type:int;default:0;comment:所在市" json:"city"`
District uint64 `gorm:"column:district;type:int;default:0;comment:所在区/县" json:"district"`
Address string `gorm:"column:address;type:varchar(255);default:null;comment:详细地址" json:"address"`
}
// Position 坐标信息

View File

@ -9,19 +9,16 @@ import (
type UserTenant struct {
Model
ModelTenant
UID uint64 `gorm:"column:uid;index:idx_tenant_user_uuid;type:int;default:0;comment:用户表UUID" json:"-"`
UUID uint64 `gorm:"column:uuid;uniqueIndex:idx_tenant_user_uuid;type:int;default:0;comment:用户唯一UUID" json:"-"`
Avatar string `gorm:"column:avatar;type:varchar(255);default:null;comment:头像" json:"avatar"`
Name string `gorm:"column:name;type:varchar(20);default:null;comment:真实姓名" json:"name"`
Email string `gorm:"column:email;type:varchar(50);default:null;comment:邮箱" json:"email"`
Identity int `gorm:"column:identity;type:tinyint(3);default:0;comment:身份信息" json:"-"`
Province uint64 `gorm:"column:province;type:int;default:0;comment:所在省" json:"province"`
City uint64 `gorm:"column:city;type:int;default:0;comment:所在市" json:"city"`
District uint64 `gorm:"column:district;type:int;default:0;comment:所在区/县" json:"district"`
Address string `gorm:"column:address;type:varchar(255);default:null;comment:详细地址" json:"address"`
UID uint64 `gorm:"column:uid;index:idx_tenant_user_uuid;type:int;default:0;comment:用户表UUID" json:"-"`
UUID uint64 `gorm:"column:uuid;uniqueIndex:idx_tenant_user_uuid;type:int;default:0;comment:用户唯一UUID" json:"-"`
Avatar string `gorm:"column:avatar;type:varchar(255);default:null;comment:头像" json:"avatar"`
Name string `gorm:"column:name;type:varchar(20);default:null;comment:真实姓名" json:"name"`
Email string `gorm:"column:email;type:varchar(50);default:null;comment:邮箱" json:"email"`
Identity int `gorm:"column:identity;type:tinyint(3);default:0;comment:身份信息" json:"-"`
Area
Selected UserTenantSelected `gorm:"column:selected;type:tinyint(1);default:0;comment:最后一次选中的身份状态,用于下次登陆展示" json:"-"`
Other string `gorm:"column:other;type:varchar(255);default:null;comment:其他信息" json:"-"`
Status int `gorm:"column:status;type:tinyint(0);default:0;comment:状态" json:"-"`
Status int `gorm:"column:status;type:tinyint(0);default:0;comment:状态-未使用" json:"-"`
ModelDeleted
ModelAt
}
@ -31,7 +28,7 @@ type UserTenantSelected int
const (
// UserTenantSelectedForNo 未选中
UserTenantSelectedForNo UserTenantSelected = iota
// UserTenantSelectedForYes 选中
// UserTenantSelectedForYes 选中
UserTenantSelectedForYes
)

View File

@ -1,10 +1,12 @@
package controller
import "SciencesServer/config"
import (
"SciencesServer/app/basic/config"
)
type Config struct{}
func (c *Config) Identity() map[uint]string {
func (c *Config) Identity() map[int]string {
return config.TenantUserIdentityData
}

View File

@ -2,7 +2,15 @@ package user
import (
"SciencesServer/app/basic/config"
model2 "SciencesServer/app/common/model"
"SciencesServer/app/enterprise/model"
"SciencesServer/app/service"
config2 "SciencesServer/config"
"SciencesServer/serve/orm"
"SciencesServer/utils"
"errors"
"gorm.io/gorm"
"time"
)
type Instance struct{ *service.SessionEnterprise }
@ -28,8 +36,68 @@ func (c *Instance) User() {
}
// Perfect 完善信息
func (c *Instance) Perfect(params *InstancePerfectParams) {
func (c *Instance) Perfect(params *InstancePerfectParams) error {
// 查询用户身份信息
mUserTenant := model.NewUserTenant()
_, err := model2.FirstField(mUserTenant.UserTenant, []string{"id", "name", "identity"},
model2.NewWhere("uuid", c.UID))
if err != nil {
return err
}
mUserTenant.Avatar = params.Avatar
mUserTenant.Name = params.Name
mUserTenant.Email = params.Email
mUserTenant.Area = model2.Area{Province: params.Province, City: params.City, District: params.District, Address: params.Address}
// 更新身份信息
if mUserTenant.Identity == 0 {
mUserTenant.Identity = c.CurrentIdentity
}
orm.GetDB().Transaction(func(tx *gorm.DB) error {
return nil
})
return nil
}
// ChangeIdentity 更改身份信息
func (c *Instance) ChangeIdentity(identity int) error {
if _, has := config.TenantUserIdentityData[identity]; !has {
return errors.New("未知的身份信息")
}
if c.CurrentIdentity == identity {
return nil
}
// 已存在相应的身份,更新最后
if c.Identity&identity > 0 {
mUserTenant := model.NewUserTenant()
// 查询用户身份信息
_, err := model2.FirstField(mUserTenant.UserTenant, []string{"id", "uuid", "identity"},
model2.NewWhere("uuid", c.UID), model2.NewWhere("identity", identity))
if err != nil {
return err
}
c.UID = mUserTenant.UUID
now := time.Now()
if err = orm.GetDB().Transaction(func(tx *gorm.DB) error {
if err = model2.UpdatesWhere(mUserTenant.UserTenant, map[string]interface{}{
"selected": model2.UserTenantSelectedForNo, "updated_at": now,
}, []*model2.ModelWhere{model2.NewWhere("uuid", c.UID)}, tx); err != nil {
return err
}
return model2.UpdatesWhere(mUserTenant.UserTenant, map[string]interface{}{
"selected": model2.UserTenantSelectedForYes, "updated_at": now,
}, []*model2.ModelWhere{model2.NewWhere("uuid", c.UID),
model2.NewWhere("identity", identity)}, tx)
}); err != nil {
return err
}
}
c.CurrentIdentity = identity
service.Publish(config2.EventForRedisHashProduce, config2.RedisKeyForAccount, utils.UintToString(c.UID), c.SessionEnterprise)
return nil
}
func NewInstance() InstanceHandle {

View File

@ -1,19 +0,0 @@
package config
// TenantUserIdentity 租户用户身份信息
type TenantUserIdentity uint
const (
TenantUserIdentityForCompany uint = 1 // 1
TenantUserIdentityForExpert uint = 1 << 1 // 2
TenantUserIdentityForResearch uint = 1 << 2 // 4
TenantUserIdentityForLaboratory uint = 1 << 3 // 8
TenantUserIdentityForAgent uint = 1 << 4 // 16
)
// TenantUserIdentityData 用户身份信息
var TenantUserIdentityData = map[uint]string{
TenantUserIdentityForCompany: "企业", TenantUserIdentityForExpert: "专家",
TenantUserIdentityForResearch: "研究机构", TenantUserIdentityForLaboratory: "实验室",
TenantUserIdentityForAgent: "即可经纪人",
}