53 lines
1.3 KiB
Go
53 lines
1.3 KiB
Go
package user
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/lego/core"
|
|
"go_dreamfactory/lego/sys/log"
|
|
"go_dreamfactory/lego/sys/redis"
|
|
"go_dreamfactory/modules"
|
|
"go_dreamfactory/pb"
|
|
)
|
|
|
|
// 记录一些扩展数据
|
|
type ModelExpand struct {
|
|
modules.MCompModel
|
|
moduleUser *User
|
|
}
|
|
|
|
func (this *ModelExpand) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
|
|
this.TableName = comm.TableUserExpand
|
|
err = this.MCompModel.Init(service, module, comp, options)
|
|
this.moduleUser = module.(*User)
|
|
return
|
|
}
|
|
|
|
//获取用户
|
|
func (this *ModelExpand) getUserSession(uid string) (cuser *pb.CacheUser) {
|
|
cuser = &pb.CacheUser{}
|
|
if err := this.Get(uid, cuser); err != nil {
|
|
log.Errorf("GetUserSession err:%v", err)
|
|
return
|
|
}
|
|
return
|
|
}
|
|
|
|
//获取用户通过扩展表
|
|
func (this *ModelExpand) GetUserExpand(uid string) (result *pb.DBUserExpand, err error) {
|
|
result = &pb.DBUserExpand{}
|
|
if err = this.moduleUser.modelExpand.Get(uid, result); err != nil && redis.RedisNil != err {
|
|
return
|
|
}
|
|
err = nil
|
|
return result, err
|
|
}
|
|
|
|
//修改用户扩展数据
|
|
func (this *ModelExpand) ChangeUserExpand(uid string, value map[string]interface{}) (err error) {
|
|
if len(value) == 0 {
|
|
return nil
|
|
}
|
|
return this.moduleUser.modelExpand.Change(uid, value)
|
|
|
|
}
|