feat:完善信息
This commit is contained in:
@ -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
|
||||
}
|
||||
|
||||
|
@ -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 {
|
||||
|
Reference in New Issue
Block a user