From 8891d07d7105cd88d7ed8de2d57af1856415ccfd Mon Sep 17 00:00:00 2001 From: wh_zcy Date: Thu, 27 Oct 2022 11:35:57 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E8=B5=84=E6=BA=90=E8=B7=A8=E6=9C=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/friend/api_cross_randlist.go | 10 ++++++ modules/user/module.go | 47 ++++++++++++++++++++++------ 2 files changed, 47 insertions(+), 10 deletions(-) diff --git a/modules/friend/api_cross_randlist.go b/modules/friend/api_cross_randlist.go index fe0262979..3922a178f 100644 --- a/modules/friend/api_cross_randlist.go +++ b/modules/friend/api_cross_randlist.go @@ -6,6 +6,8 @@ import ( "go_dreamfactory/utils" "google.golang.org/protobuf/proto" + + cfg "go_dreamfactory/sys/configure/structs" ) func (this *apiComp) RandlistCheck(session comm.IUserSession, req *pb.FriendRandlistReq) (code pb.ErrorCode) { @@ -87,6 +89,14 @@ func (this *apiComp) Randlist(session comm.IUserSession, req *pb.FriendRandlistR } + this.moduleFriend.DispenseRes(session, []*cfg.Gameatn{ + { + A: "attr", + T: "gold", + N: 10, + }, + }, true) + rsp := &pb.FriendRandlistResp{ List: userList, } diff --git a/modules/user/module.go b/modules/user/module.go index 375e3519f..106c4d13b 100644 --- a/modules/user/module.go +++ b/modules/user/module.go @@ -183,7 +183,19 @@ func (this *User) SearchRmoteUser(nickname string) ([]*pb.DBUser, error) { //查询用户属性值 例如 金币 经验 func (this *User) QueryAttributeValue(uid string, attr string) (value int64) { - user := this.modelUser.GetUser(uid) + var ( + user *pb.DBUser + err error + ) + if this.IsCross() { + user, err = this.GetRmoteUser(uid) + if err != nil { + return + } + } else { + user = this.modelUser.GetUser(uid) + } + if user == nil { return } @@ -206,15 +218,30 @@ func (this *User) change(session comm.IUserSession, attr string, add int32) (cha return } - user := this.GetUser(session.GetUserId()) - if user == nil { - code = pb.ErrorCode_UserSessionNobeing - return + uid := session.GetUserId() + var ( + user *pb.DBUser + userEx *pb.DBUserExpand + err error + ) + if this.IsCross() { + user, err = this.GetRmoteUser(uid) + if err != nil { + code = pb.ErrorCode_UserSessionNobeing + return + } + + } else { + user = this.GetUser(uid) + userEx, err = this.GetUserExpand(uid) + if err != nil { + code = pb.ErrorCode_UserExpandNull + return + } } - userEx, err := this.GetUserExpand(session.GetUserId()) - if userEx == nil || err != nil { - code = pb.ErrorCode_UserExpandNull + if user == nil { + code = pb.ErrorCode_UserSessionNobeing return } @@ -275,12 +302,12 @@ func (this *User) change(session comm.IUserSession, attr string, add int32) (cha comm.ResFriend: change.Friend, } - if err := this.modelUser.updateUserAttr(session.GetUserId(), update); err != nil { + if err := this.modelUser.updateUserAttr(uid, update); err != nil { this.Errorf("AddAttributeValue err:%v", err) code = pb.ErrorCode_DBError } - if err := this.modelExpand.ChangeUserExpand(session.GetUserId(), updateEx); err != nil { + if err := this.modelExpand.ChangeUserExpand(uid, updateEx); err != nil { this.Errorf("AddAttributeValue ex err:%v", err) code = pb.ErrorCode_DBError } From a325afb4a71290ee2aa339a1a0ab0ab41cfdf073 Mon Sep 17 00:00:00 2001 From: wh_zcy Date: Thu, 27 Oct 2022 11:53:03 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E8=B5=84=E6=BA=90=E8=B7=A8=E6=9C=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/user/model_user.go | 13 ++++++++++++- modules/user/module.go | 5 +++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/modules/user/model_user.go b/modules/user/model_user.go index 683a2b85b..40c01e914 100644 --- a/modules/user/model_user.go +++ b/modules/user/model_user.go @@ -81,7 +81,18 @@ func (this *ModelUser) GetUser(uid string) (user *pb.DBUser) { //设置属性 func (this *ModelUser) updateUserAttr(uid string, data map[string]interface{}) error { - return this.Change(uid, data) + if this.module.IsCross() { + if model, err := this.module.GetDBNoduleByUid(uid, this.TableName, this.Expired); err != nil { + this.module.Errorln(err) + } else { + if err = model.Change(uid, data); err != nil { + this.module.Errorf("err:%v", err) + } + } + } else { + return this.Change(uid, data) + } + return nil } //是否今天首次登录 diff --git a/modules/user/module.go b/modules/user/module.go index 106c4d13b..d9da7b734 100644 --- a/modules/user/module.go +++ b/modules/user/module.go @@ -231,6 +231,11 @@ func (this *User) change(session comm.IUserSession, attr string, add int32) (cha return } + userEx, err = this.GetUserExpand(uid) + if err != nil { + code = pb.ErrorCode_UserExpandNull + return + } } else { user = this.GetUser(uid) userEx, err = this.GetUserExpand(uid)