From c7ebd49dc62d1123ec474f1c9a3edb8558612c1a Mon Sep 17 00:00:00 2001 From: 陆恒 Date: Tue, 2 Jun 2020 11:49:45 +0800 Subject: [PATCH] 提交新街口 --- src/HttpServer/logic/datadef.go | 26 ++++++++++++++++++++++++++ src/HttpServer/logic/httpserver.go | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/common/redis/def.go | 7 +++++++ src/mysql/dbmysql.go | 19 +++++++++++++++++++ 4 files changed, 112 insertions(+), 0 deletions(-) diff --git a/src/HttpServer/logic/datadef.go b/src/HttpServer/logic/datadef.go index 4978d02..4e32762 100644 --- a/src/HttpServer/logic/datadef.go +++ b/src/HttpServer/logic/datadef.go @@ -724,3 +724,29 @@ type UserData struct { LoginDay int } +//--------------------------------------------------------------------------------------------------------------------- +//聊天相关 +type ChatInfoDesc struct { + Uuid int `json:"uuid"` + Headurl string `json:"headurl"` + Nickname string `json:"nickname"` + Sex int `json:"sex"` //1男0女 + ChatTime int `json:"chattime"` + Message string `json:"message"` + +} + +//聊天单个页签信息 +type ChatRoomInfo struct { + Chats []ChatInfoDesc `json:"chats"` + Pos int `json:"pos"` + Isnew int `json:"isnew"` //是否有新聊天 +} + +type ChatRoomInfos []ChatRoomInfo + +type ChatMessagesInfo struct { + World ChatRoomInfo `json:"world"` + Team ChatRoomInfo `json:"team"` + Private ChatRoomInfos `json:"privete"` +} \ No newline at end of file diff --git a/src/HttpServer/logic/httpserver.go b/src/HttpServer/logic/httpserver.go index ea6a0c0..def5632 100644 --- a/src/HttpServer/logic/httpserver.go +++ b/src/HttpServer/logic/httpserver.go @@ -51,6 +51,7 @@ func startServerHttpServe() { //------------------------------------------------------------- http.HandleFunc("/catcafe/ClearData", ClearData) //情况账号的测试接口 http.HandleFunc("/catcafe/AddWhiteList", AddWhiteList) //情况账号的测试接口 + http.HandleFunc("/catcafe/AddGoldAndLove", AddGoldAndLove) //情况账号的测试接口 http.HandleFunc("/catcafe/QueryAllAccount", QueryAllAccount) //查询所有账号的等级信息等数据 //------------------------------------------------------------- http.HandleFunc("/catcafe/login", UserLogin) //游客登录 @@ -183,6 +184,65 @@ func QueryAllAccount(w http.ResponseWriter, r *http.Request) { } +func AddGoldAndLove(w http.ResponseWriter, r *http.Request) { + + query := r.URL.Query() + suuid := query.Get("uuid") + sgold := query.Get("gold") + slove := query.Get("love") + uuid,_ := strconv.Atoi(suuid) + gold,_ := strconv.Atoi(sgold) + love,_ := strconv.Atoi(slove) + logger.Info("ClearData , uuid:%v,gold:%v,love:%v", suuid,sgold,slove) + if suuid == "" { + fmt.Fprint(w, "uuid is nil,please check") + return + } + var wilteist []int + rkey := "CATCAFE_REDIS_CAN_RESETDATA_LIST" + vv,err := redishandler.GetRedisClient().HGetAllKeys(rkey) + if err != nil { + fmt.Fprint(w,"获取白名单失败!,请检查") + } + + for _,val := range vv { + bytestr := string(val.([]byte)) + bytenum,_ := strconv.Atoi(bytestr) + wilteist = append(wilteist,bytenum) + + } + logger.Info("AddGoldAndLove white list wilteist=%v",wilteist) + isinwhitelist := false + for _,val := range wilteist { + if val == uuid { + isinwhitelist = true + break + } + } + + if !isinwhitelist { + //不在白名单 + fmt.Fprint(w, "你要加金币的数据不在白名单内,请联系管理员") + return + } + + //加金币 + err = mysql.DoAddGold(uuid,gold,love) + if err != nil { + fmt.Fprint(w, "加金币失败了,错误码%v",err) + } + + //清楚redis + rediskey1 := "cat:cafe:userext:where:user_id:" + suuid + err = redishandler.GetRedisClient().Delete(rediskey1) + if err != nil { + fmt.Fprint(w, "加金币失败了,错误码%v",err) + } + + //将id从白名单删除 + redishandler.GetRedisClient().HDel(rkey,suuid) +} + func AddWhiteList(w http.ResponseWriter, r *http.Request) { query := r.URL.Query() diff --git a/src/common/redis/def.go b/src/common/redis/def.go index 89d991b..8892b08 100644 --- a/src/common/redis/def.go +++ b/src/common/redis/def.go @@ -21,4 +21,11 @@ const ( USER_INVITEWORK_RELATION = "CATCAFE_USER_INVITEWORK_RELATION" //玩家被邀请打工记录表 USER_BACKUP_DATA = "CATCAFE_USER_BACKUP_DATA" //玩家数据保存的备份 USER_NEW_DATA_KEY = "cat:cafe:data_new:where:data_uid:" //玩家数据保存的新的key + + USER_CHAT_ISNEW = "CATCAFE_USER_CHAT_ISNEW" //hset field为uuid 存在表示有新消息了不用再去计算 否则需要挨个去判断 + WORLD_CHAT_INFO_KEY = "CATCAFE_WORLD_CHAT_INFO_KEY" //存储的是世界聊天 list结构 最新的消息在最头部 + USER_CHAT_TEAM_LASTGET_KEY ="CATCAFE_USER_CHAT_TEAM_LASTGET_KEY" // 结构是hset field是uuid value是存储的是最后一次获取工会聊天的时间戳,用于和工会聊天最新一条消息做对比,如果时间比最新一条小则有新的消息 + USER_CHAT_TEAM_INFO_KEY = "CATCAFE_USER_CHAT_TEAM_INFO_KEY" // 加teamid 存储的是队伍聊天的信息 list结构 最新的消息在最头部 + USER_CHAT_PRIVATE_LASTGET_KEY = "CATCAFE_USER_CHAT_PRIVATE_LASTGET_KEY" // hset key加自己的uuid field为目标的uuid value为时间戳 + USER_CHAT_PRIVATE_INFO_KEY = "CATCAFE_USER_CHAT_PRIVATE_INFO_KEY" //list key需要加上自己的uuid 存储的是和自己相关的所有聊天信息 ) diff --git a/src/mysql/dbmysql.go b/src/mysql/dbmysql.go index 4b4e16d..39b8772 100644 --- a/src/mysql/dbmysql.go +++ b/src/mysql/dbmysql.go @@ -83,6 +83,25 @@ func TestClearData(uid int) (int,error) { return value,nil } +func DoAddGold(uuid,gold,love int) error { + for i:=0;i<10;i++ { + tablename := "b_base_data_0" + strconv.Itoa(i) + cmd := "update " + tablename + "set coin = " + strconv.Itoa(gold) + " where user_id= " + strconv.Itoa(uuid) + err := ExcuteCmd(cmd) + if err != nil { + logger.Error("DoAddGold err=%v,cmd=%v",err,cmd) + return err + } + cmd = "update " + tablename + "set love_exp = " + strconv.Itoa(love) + " where user_id= " + strconv.Itoa(uuid) + err = ExcuteCmd(cmd) + if err != nil { + logger.Error("DoAddGold err=%v,cmd=%v",err,cmd) + return err + } + } + return nil +} + func DoClearData(uuid int) error{ //先删除十张分表的数据 for i:=0;i<10;i++ { -- libgit2 0.21.0