fix:修复因切换身份的bug
This commit is contained in:
@ -4,6 +4,7 @@ import (
|
||||
"SciencesServer/app/api/enterprise/controller/user"
|
||||
"SciencesServer/app/basic/api"
|
||||
"SciencesServer/app/session"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
|
@ -9,8 +9,9 @@ import (
|
||||
config2 "SciencesServer/config"
|
||||
"SciencesServer/serve/orm"
|
||||
"errors"
|
||||
"gorm.io/gorm"
|
||||
"time"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type Identity struct{ *session.Enterprise }
|
||||
@ -213,7 +214,7 @@ func (c *Identity) Switch(identity int) error {
|
||||
if c.Identity&identity > 0 {
|
||||
mUserIdentity := model.NewUserIdentity()
|
||||
// 查询用户身份
|
||||
isExist, err := model2.FirstField(mUserIdentity.UserIdentity, []string{"id", "name", "uuid"},
|
||||
isExist, err := model2.FirstField(mUserIdentity.UserIdentity, []string{"id", "name", "uid"},
|
||||
model2.NewWhere("uid", c.UID), model2.NewWhere("identity", identity))
|
||||
|
||||
if err != nil {
|
||||
@ -224,7 +225,7 @@ func (c *Identity) Switch(identity int) error {
|
||||
if err = orm.GetDB().Transaction(func(tx *gorm.DB) error {
|
||||
if err = model2.UpdatesWhere(mUserIdentity.UserIdentity, map[string]interface{}{
|
||||
"is_selected": model2.UserIdentitySelectedForNo, "updated_at": now,
|
||||
}, []*model2.ModelWhere{model2.NewWhere("uuid", c.IdentityUID)}, tx); err != nil {
|
||||
}, []*model2.ModelWhere{model2.NewWhere("uid", c.IdentityUID)}, tx); err != nil {
|
||||
return err
|
||||
}
|
||||
return model2.Updates(mUserIdentity.UserIdentity, map[string]interface{}{
|
||||
@ -235,7 +236,7 @@ func (c *Identity) Switch(identity int) error {
|
||||
}
|
||||
}
|
||||
c.SelectIdentity = identity
|
||||
service.Publish(config2.EventForAccountLoginProduce, config2.RedisKeyForAccountEnterprise, c.GetStringUID(), c.Enterprise)
|
||||
service.Publish(config2.EventForRedisHashProduce, config2.RedisKeyForAccountEnterprise, c.GetStringUID(), c.Enterprise)
|
||||
return nil
|
||||
}
|
||||
return errors.New("操作错误,无效的身份信息")
|
||||
|
@ -7,6 +7,7 @@ import (
|
||||
"SciencesServer/app/basic/api"
|
||||
"SciencesServer/app/session"
|
||||
"SciencesServer/config"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
@ -480,6 +481,9 @@ func registerEnterpriseAPI(app *gin.Engine) {
|
||||
{
|
||||
_api := new(api3.User)
|
||||
userV1.GET("/info", _api.Info)
|
||||
userV1.POST("/identity", _api.IdentityBasic)
|
||||
userV1.POST("/identity/detail", _api.IdentityDetail)
|
||||
userV1.POST("/identity/switch", _api.IdentitySwitch)
|
||||
userV1.POST("/back", _api.Back)
|
||||
userV1.POST("/back/bind", _api.BackBind)
|
||||
userV1.POST("/back/unbind", _api.BackUnbind)
|
||||
|
Reference in New Issue
Block a user