Commit a068eb5a by xuzhenhao

增加了返回个人排行信息的时候可以看到前后玩家信息的功能

1 parent 6e3f6187
......@@ -137,10 +137,11 @@ func SingleRank(c *gin.Context) {
gtid := c.Query("gtid")
gid := c.Query("gid")
toptype := c.Query("toptype")
prerank := c.Query("prerank")
nextrank := c.Query("nextrank")
log.Printf("SingleRank uid[%s] gtid[%s] gid[%s] toptype[%s] prerank[%s] nextrank[%s]\n", uid, gtid, gid, toptype, prerank, nextrank)
log.Printf("SingleRank uid[%s] gtid[%s] gid[%s] toptype[%s]\n", uid, gtid, gid, toptype)
igt := sdkredis.IceGameTopRedisGetSingleUserRankInfo(uid, gtid, gid, toptype)
igt := sdkredis.IceGameTopRedisGetSingleUserRankInfo(uid, gtid, gid, toptype, prerank, nextrank)
fmt.Println(igt)
msg := new(Msg)
if igt == nil {
......
......@@ -269,7 +269,7 @@ func IceGametopRedisSubmitScore(uid string, gtid string, gid string, score strin
/**
* 获取单个用户的排名信息
*/
func IceGameTopRedisGetSingleUserRankInfo(uid string, gtid string, gid string, toptype string) (igt *IGT) {
func IceGameTopRedisGetSingleUserRankInfo(uid string, gtid string, gid string, toptype string, prerank string, nextrank string) (igt *IGT) {
// 连接redis
redisConn := RedisClient.GetConn()
defer RedisClose(redisConn)
......@@ -289,15 +289,49 @@ func IceGameTopRedisGetSingleUserRankInfo(uid string, gtid string, gid string, t
} else {
return
}
// 获取当前用户排名
rank, err := RedisZRank(redisConn, "sortset:gtid:"+gtid+":gid:"+gid+":toptype:"+toptype, member)
if err != nil {
log.Println("RedisZRANK err[%v]", err)
return
}
rankIndex := rank.(int)
// 获取当前用户前x位和后x位的排名数据
var prerankIndex int
var nextrankIndex int
if prerank == "" {
prerankIndex = 1
} else {
prerankIndex, err = strconv.Atoi(prerank)
if err != nil {
log.Println("String to Int err: ", err)
return
}
}
if nextrank == "" {
nextrankIndex = 1
} else {
nextrankIndex, err = strconv.Atoi(nextrank)
if err != nil {
log.Println("String to Int err: ", err)
return
}
}
if rankIndex-prerankIndex < 0 {
prerankIndex = 0
} else {
prerankIndex = rankIndex - prerankIndex
}
nextrankIndex = rankIndex + nextrankIndex
// 排序
var strList []string
var sorterr error
if sorceorder == "0" {
strList, sorterr = RedisSort(redisConn, "sortset:gtid:"+gtid+":gid:"+gid+":toptype:"+toptype, 0, -1)
strList, sorterr = RedisSort(redisConn, "sortset:gtid:"+gtid+":gid:"+gid+":toptype:"+toptype, prerankIndex, nextrankIndex)
} else if sorceorder == "1" {
strList, sorterr = RedisReverseSort(redisConn, "sortset:gtid:"+gtid+":gid:"+gid+":toptype:"+toptype, 0, -1)
strList, sorterr = RedisReverseSort(redisConn, "sortset:gtid:"+gtid+":gid:"+gid+":toptype:"+toptype, prerankIndex, nextrankIndex)
}
if sorterr != nil {
log.Println("RedisSort err[%v]", sorterr)
......@@ -319,7 +353,6 @@ func IceGameTopRedisGetSingleUserRankInfo(uid string, gtid string, gid string, t
endIndex := strings.Index(strList[i], ":gtid")
currUID := common.Substr2(strList[i], startIndex, endIndex)
if currUID == uid {
igt.UID = uid
igt.RankIndex = index
igt.MyKey = strList[i+1]
......@@ -347,7 +380,6 @@ func IceGameTopRedisGetSingleUserRankInfo(uid string, gtid string, gid string, t
igt.NickName = result[0] //第一个为昵称
igt.HeadPortraitURL = result[1] //第二个为头像url
}
}
index++
}
......
......@@ -216,3 +216,10 @@ func RedisIncrBy(conn redis.Conn, key string, num int64) (reply interface{}, err
return
}
/*
* zrank
*/
func RedisZRank(conn redis.Conn, key string, member string) (reply interface{}, err error) {
return RedisCommand(conn, "zrank", key, member)
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!