From edd0797223a3627285d6edd7ea68181a916be2d3 Mon Sep 17 00:00:00 2001 From: hujiebin Date: Tue, 21 Feb 2023 17:28:24 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E9=92=BB=E7=9F=B3=E6=95=B0=E5=8F=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- protocol/userProxy.proto | 5 +++++ rpc/user.go | 41 +++++++++++++++++++++++++++++++++++++--- rpc/user_center_func.go | 28 +++++++++++++++++---------- 3 files changed, 61 insertions(+), 13 deletions(-) diff --git a/protocol/userProxy.proto b/protocol/userProxy.proto index ff525b8..27ca2bc 100644 --- a/protocol/userProxy.proto +++ b/protocol/userProxy.proto @@ -351,6 +351,11 @@ message RoomInviteMember { string group_id = 1; } +/* id == 145 钻石变化 */ +message DiamondChange { + uint32 remainDiamond = 1; +} + /* id == 146 游戏横幅 */ message GlobalGameBanner { uint32 gameType = 1; // 0.h5游戏 1.ludo 2.uno 3.dice 4.lucky wheel 5.lucky box 6.fruit diff --git a/rpc/user.go b/rpc/user.go index d13dc51..cbc77b8 100644 --- a/rpc/user.go +++ b/rpc/user.go @@ -64,9 +64,9 @@ func GetUserLevel(model *domain.Model, userId mysql.ID) (CvUserLevel, error) { // 批量获取用户等级 func MGetUserLevel(model *domain.Model, userIds []mysql.ID) (map[mysql.ID]CvUserLevel, error) { type Response struct { - Code int `json:"code"` - Message string `json:"message"` - Data map[mysql.ID]CvUserLevel + Code int `json:"code"` + Message string `json:"message"` + Data map[mysql.ID]CvUserLevel `json:"data"` } var res = make(map[mysql.ID]CvUserLevel) if len(userIds) <= 0 { @@ -99,6 +99,41 @@ func MGetUserLevel(model *domain.Model, userIds []mysql.ID) (map[mysql.ID]CvUser return res, nil } +type CvUserBag struct { + BagId mysql.ID `json:"bagId"` // 背包id + ResType mysql.Type `json:"resType"` // 道具类型 1:礼物道具 + ResId mysql.ID `json:"resId"` // 道具资源id + Name string `json:"name"` // 资源名称 + DiamondNum mysql.Num `json:"diamondNum"` // 钻石数量 + IconUrl string `json:"iconUrl"` // icon url + SvgaUrl string `json:"svgaUrl"` // svga url + Count mysql.Num `json:"count"` // 拥有数量 + RemainDays int `json:"remainDays"` // 有效天数 +} + +// 批量用户背包 +func GetUserBag(model *domain.Model, bagId mysql.ID) (CvUserBag, error) { + type Response struct { + Code int `json:"code"` + Message string `json:"message"` + Data CvUserBag `json:"data"` + } + _url := fmt.Sprintf("%v://%v/inner/user/bag", defaultUserServerScheme, getUserHost()) + resp, err := HttpGet(model, _url, nil, map[string][]string{ + "bagId": {fmt.Sprintf("%d", bagId)}, + }) + if err != nil { + model.Log.Errorf("GetUserBag fail:%v", err) + return CvUserBag{}, err + } + response := new(Response) + if err = json.Unmarshal(resp, response); err != nil { + model.Log.Errorf("GetUserBag json fail:%v", err) + return CvUserBag{}, err + } + return response.Data, nil +} + func getUserHost() string { l := len(UserServerHost) r := rand.Intn(l) // 随机一个 diff --git a/rpc/user_center_func.go b/rpc/user_center_func.go index 7fc07b8..ac1090e 100644 --- a/rpc/user_center_func.go +++ b/rpc/user_center_func.go @@ -67,18 +67,26 @@ func SendGlobalRocketNotice(groupId string, period string, round uint32, stage u } // 发送钻石变化通知 -func SendDiamondChange(userId uint64) error { - rspUids, err := multicast([]uint64{userId}, MsgDiamondChange, []byte("")) - //记录socket,注意闭包问题 - go func(userId uint64, rspUids []uint64, err error) { - AddRpcLog(MsgDiamondChange, userId, "", rspUids, err) - }(userId, rspUids, err) +func SendDiamondChange(userId uint64, diamond uint32) error { + msg := &userProxy.DiamondChange{ + RemainDiamond: diamond, + } + if buffer, err := proto.Marshal(msg); err == nil { + rspUids, err := multicast([]uint64{userId}, MsgDiamondChange, buffer) + //记录socket,注意闭包问题 + go func(userId uint64, msg *userProxy.DiamondChange, rspUids []uint64, err error) { + buf, _ := json.Marshal(msg) + AddRpcLog(MsgDiamondChange, userId, string(buf[:]), rspUids, err) + }(userId, msg, rspUids, err) - if err != nil { - mylogrus.MyLog.Errorf("grpc SendDiamondChange send fail") - return err + if err != nil { + mylogrus.MyLog.Errorf("grpc SendDiamondChange send fail") + return err + } else { + mylogrus.MyLog.Info("grpc SendDiamondChange send success") + } } else { - mylogrus.MyLog.Info("grpc SendDiamondChange send success") + return err } return nil } -- 2.22.0