package model import ( "encoding/base64" "rocommon" "rocommon/service" "rocommon/util" ) const ( SDKPlatform_PC = "PC" SDKPlatform_Quick = "SDKQuick" SDKPlatform_Hw_Quick = "SDKHwQuick" SDKPlatform_NBSDK = "SDKNB" SDKPlatform_UniSDK = "SDKUni" //SDKUni SDKPlatform_YouYi = "SDKYOUYI" SDKPlatform_YouYi_IOS = "SDKYOUYI_IOS" SDKPlatform_Quick_Android = "Quick_Android" SDKPlatform_Quick_Ios = "Quick_IOS" /* sub_platform changemeng_xjgl 畅梦包 changemeng_gdt_xjgl 畅梦广通包 quick_wy_gzyw 网易quick wangyi_youyi 游易网易 */ ) const ( //服务器关闭/开启注册功能 ServerPrefix = "server:reg" ServerCompetitionPrefix = "server:com" //地图通关进度排名 MapRankPrefix = "rank:map" //困难地图通关进度排名 MapHardRankPrefix = "rank_hard:map" //历史最大战力 MaxFightPowerRankPrefix = "rank:fight" //当前积分排行(用来匹配使用) ArenaRankMatchPrefix = "rank:arenamatch" //当前积分排行(参加过玩家的积分排行) ArenaRankPrefix = "rank:arena" ArenaPreRankPrefix = "rank:arenapre" //上赛季参赛玩家积分排行列表 //积分达到对应段位后的排行(积分下降后从该排行榜中移除) ArenaTopRankPrefix = "rank:arenatop" //rank:arenatop1 历史top排行 //competition //赛季对应大地图排行数据 CompetitionMapRankPrefix = "rank:comp:map" //1 CompetitionScoreRankPrefix = "rank:com:score" //2 CompetitionDuoBaoScoreRankPrefix = "rank:com:wheel" //3 CompetitionZhanBuScoreRankPrefix = "rank:com:zhanbu" //4 CompetitionIdolScoreRankPrefix = "rank:com:idol" //5 CompetitionIdolBoxRankPrefix = "rank:com:idolbox" CompetitionIdolFansVotePrefix = "rank:com:idolfans" TowerLevelRankPrefix = "rank:tower" TowerFightpowerRankPrefix = "rank:towerfight" CardCollectRankPrefix = "rank:cardcollect" KeepSakeCollectRankPrefix = "rank:keepsakecollect" //战斗记录(不包括过程数据) BattleRecordMapPrefix = "brecord:map" //战斗过程详细数据,结构序列化数据,key-val格式用来设置过期使用 BattleRecordDetailPrefix = "brecord" //验证存储合法性 BattleRecordDetailCheckPrefix = "brecord:id" //公会base GuildBasePrefix = "guild:guildbase" //公会成员 GuildMemberPrefix = "guild:guildmember" //公会申请列表 GuildApplyPrefix = "guild:guildapply" //公会日志列表 GuildLogPrefix = "guild:guildlog" //玩家申请列表 RoleApplyPrefix = "guild:roleapply" //公会名字索引 GuildNameIndexPrefix = "guild:nameindex" //公会 GuildRoleToGuildPrefix = "guild:roletoguildindex" //公会最新ID GuildCurGuildIdPrefix = "guild:curguildidindex" //公会推荐列表 GuildRecommendPrefix = "guild:recommendindex" //公会boss GuildBossPrefix = "guild:bossindex" //公会魔王 GuildDemonPrefix = "guild:guilddemon" //公会魔王奖励 GuildDemonRewardPrefix = "guild:guilddemonreward" //公会魔王,公会最总伤害排名 GuildDemonGuildPrefix = "guild:demonguildindex" //公会魔王,公会MVP伤害排名 GuildDemonMVPPrefix = "guild:demonmvpindex" //爬塔排行榜系统数据 RushTowerPrefix = "tower:rushtower" //爬塔最终榜单 RushTowerRankPrefix = "tower:rushrank" //爬塔排行榜系统数据 RushArenaPrefix = "arena:rusharena" //爬塔最终榜单 RushArenaRankPrefix = "arena:rushrank" //推图冲榜积分榜 RushMapScorePrefix = "arena:rushmapscore" //推图冲榜系统数据 RushMapPrefix = "arena:rushmap" //推图冲榜最终积分榜 RushMapRankPrefix = "arena:rushmaprank" //勇士积分排行榜 ExpeditionScoreRankPrefix = "rank:expedition" //宠物冲榜相关 RushPetScorePrefix = "pet:rushpetscore" //宠物冲榜系统数据 RushPetPrefix = "pet:rushpet" //宠物冲榜最终数据 RushPetRankPrefix = "pet:rushpetrank" //宠物冲榜,宠物数据 RushPetDataPrefix = "pet:rushpetdatarank" //技能冲榜相关 RushSkillScorePrefix = "pet:rushskillscore" //技能冲榜系统数据 RushSkillPrefix = "pet:rushskill" //技能冲榜最终数据 RushSkillRankPrefix = "pet:rushskillrank" //pay PayOrderPrefix = "pay" //所有订单信息 PayOrderOKIdListPrefix = "payoklist:" //成功但是没有获取奖励的订单id payoklist:uid //百人道场 DaoChang100Prefix = "dc100" //map有数据表示挑战过该位置(机器人/玩家) DaoChang100RewardPrefix = "dc100posreward" //list占位奖励列表 RoleDaoChang100Prefix = "role_dc100" //map RoleDaoChang100LogPrefix = "role_dc100_log" RoleDaoChang100GuildRankPrefix = "dc100guild" RoleDaoChang100WheeLogPrefix = "dc100wheel_log" //百人道场转盘日志 //精彩活动 ActivitiesCollectionDataPrefix = "act:num" ) // 排行榜每日重置时使用,切记!!! func GetRankScoreDailyReset(val uint64, passTime uint64) uint64 { //score var scoreStr = val if scoreStr >= (1 << 40) { scoreStr = (1 << 40) - 1 } //时间修改成以一天内的时间 tmpTime := util.GetCurrentTimeNow() passTime = uint64(tmpTime.Hour()*60*60+tmpTime.Minute()*60+tmpTime.Second()+tmpTime.Day()) * 1000 scoreStr <<= 24 scoreStr |= 0xfffffffff - passTime/50 return scoreStr } func GetValByRankScoreDailyReset(score float64) uint64 { val := uint64(score) >> 24 return val } // 通用排行榜积分处理 func GetRankScoreCommon(val uint64, passTime uint64) uint64 { //score var scoreStr = val if scoreStr >= (1 << 28) { scoreStr = (1 << 28) - 1 } scoreStr <<= 36 scoreStr |= 0xfffffffff - passTime/50 return scoreStr } func GetValByRankScoreCommon(score float64) uint64 { val := uint64(score) >> 36 return val } type CompetitionType int32 const ( CompetitionType_ZhaoMu CompetitionType = iota + 1 //招募季 CompetitionType_XuanBa //选拔季 贡献道具获取积分 CompetitionType_DuoBao //夺宝季 转盘获取积分 CompetitionType_ZhanBu //占卜季 CompetitionType_Idol //偶像季 ) // 数据库相关操作 func GetMessageFromRedis(module, key string, msg interface{}) error { ret, err := service.GetRedis().Get(module + key).Result() if err != nil { if err != service.NIL { util.InfoF("GetMessageFromRedis get key=%v err=%v\n", module+key, err) } return err } if ret == "" { //util.InfoF("key(%v:%v)->val empty", module, key) return nil } return GetDecodeMessage(msg, ret) } func SetMessageToRedis(module, key string, msg interface{}) error { msgData, err := rocommon.GetCodec().Marshal(msg) if err != nil { return err } msgStr := base64.StdEncoding.EncodeToString(msgData.([]byte)) ret, err := service.GetRedis().Set(module+key, msgStr, 0).Result() if err != nil { util.InfoF("SetMessageToRedis err=%v ret=%v", module+key, ret) return err } //log.Printf("[SetMessageToRedis] [%v]ret:%v\n", module + key, ret) return nil } func SetMessageToRedisExpire(module, key string, msg interface{}) error { msgData, err := rocommon.GetCodec().Marshal(msg) if err != nil { return err } msgStr := base64.StdEncoding.EncodeToString(msgData.([]byte)) ret, err := service.GetRedis().HSet(module, key, msgStr).Result() if err != nil { util.InfoF("SetMessageToRedis err=%v ret=%v", module+key, ret) return err } //log.Printf("[SetMessageToRedis] [%v]ret:%v\n", module + key, ret) return nil } func GetEncodeMessage(msg interface{}) (error, string) { msgData, err := rocommon.GetCodec().Marshal(msg) if err != nil { return err, "" } msgStr := base64.StdEncoding.EncodeToString(msgData.([]byte)) return nil, msgStr } func GetDecodeMessage(msg interface{}, msgStr string) error { str, err := base64.StdEncoding.DecodeString(msgStr) if err != nil { //log.Printf("[GetMessageFromRedis] [%v] err:%v\n", module + key, err) return err } return rocommon.GetCodec().Unmarshal(str, msg) } func ExistKey(key string) bool { ret, err := service.GetRedis().Exists(key).Result() if err != nil { return false } return ret > 0 } func SetDataToRedis(key string, data string) error { ret, err := service.GetRedis().Set(key, data, 0).Result() if err != nil { util.InfoF("[SetDataToRedis] err:[%v]ret:%v", key, ret) return err } //log.Printf("[SetMessageToRedis] [%v]ret:%v\n", module + key, ret) return nil } // 区分不同平台 func ConvertPlatform(openId, platform string) string { if platform == SDKPlatform_YouYi || platform == SDKPlatform_YouYi_IOS { //除了quick和nb其他渠道都要加上渠道标识 openId = platform + openId } return openId }