package user import ( "go_dreamfactory/comm" "go_dreamfactory/modules" "go_dreamfactory/pb" "go_dreamfactory/lego/core" ) func NewModule() core.IModule { m := new(User) return m } type User struct { modules.ModuleBase api *apiComp modelUser *ModelUser modelSession *ModelSession configure *modules.MCompConfigure } func (this *User) GetType() core.M_Modules { return comm.ModuleUser } func (this *User) Init(service core.IService, module core.IModule, options core.IModuleOptions) (err error) { err = this.ModuleBase.Init(service, module, options) return } func (this *User) OnInstallComp() { this.ModuleBase.OnInstallComp() this.api = this.RegisterComp(new(apiComp)).(*apiComp) this.modelUser = this.RegisterComp(new(ModelUser)).(*ModelUser) this.modelSession = this.RegisterComp(new(ModelSession)).(*ModelSession) } //获取英雄列表 func (this *User) GetUser(uid string) *pb.DBUser { return this.modelUser.GetUser(uid) } //查询用户属性值 例如 金币 经验 func (this *User) QueryAttributeValue(uid string, attr string) (value int32) { user := this.modelUser.GetUser(uid) if user == nil { return } switch attr { case comm.ResGold: return user.Gold case comm.ResExp: return user.Exp } return } //用户资源 func (this *User) AddAttributeValue(uid string, attr string, add int32) (code pb.ErrorCode) { update := make(map[string]interface{}) switch attr { case comm.ResGold: update[comm.ResGold] = add case comm.ResExp: update[comm.ResExp] = add } if err := this.modelUser.updateUserAttr(uid, update); err != nil { code = pb.ErrorCode_DBError } return }