package cp_cv import ( "fmt" "git.hilo.cn/hilo-common/resource/mysql" "github.com/bluele/gcache" "hilo-user/_const/enum/cp_e" "hilo-user/cv/user_cv" "hilo-user/domain/model/res_m" "time" ) // cp信息 type CvCpInfo struct { UserInfo user_cv.UserTiny `json:"userInfo"` // 用户信息 CpUserInfo user_cv.UserTiny `json:"cpUserInfo"` // cp用户信息 CpDays int `json:"cpDays"` // cp天数 VisitTimes int `json:"visitTimes"` // 空间访问量 } // cp等级 type CvCpGrade struct { Grade cp_e.CpGrade `json:"grade"` // 等级 0:无称号 1:恋爱CP 2:甜蜜CP 3:忠诚CP 4:炽热CP 5:荣耀CP Exp uint32 `json:"exp"` // 经验值 NextExp uint32 `json:"nextExp,omitempty"` // 下个等级所需经验值 RemainExp uint32 `json:"remainExp,omitempty"` // 还需要多少经验值到下一个级别 ExpireAt string `json:"expireAt,omitempty"` // 有效期 } // 资源等级 type CvResGrade struct { Grade cp_e.CpGrade `json:"grade"` // 等级 Icon string `json:"icon"` // 等级icon图 } // 特权信息 type CvPrivilege struct { Type cp_e.CpPrivilege `json:"type"` // 特权id 1:空间 2:横幅 3:等级勋章 4:证书 5:进场特效 6:头像头饰 7:动态资料卡 8:麦位特效 NameMsgId uint `json:"-"` // 名称-翻译id Name string `json:"name"` // 名称 Icon string `json:"icon"` // 图标 } // cp空间页 type CvSpace struct { CpInfo CvCpInfo `json:"cpInfo"` // cp信息 CpGrade CvCpGrade `json:"cpGrade"` // cp等级 ResGradeList []CvResGrade `json:"resGradeList"` // 资源等级列表,无称号/恋爱CP/甜蜜CP/忠诚CP/炽热CP/荣耀CP PrivilegeList []CvPrivilege `json:"privilegeList"` // 等级特权 } var CvResGradeList = []CvResGrade{ {cp_e.CpGrade0, cp_e.CpGradeIcon[cp_e.CpGrade0]}, {cp_e.CpGrade1, cp_e.CpGradeIcon[cp_e.CpGrade1]}, {cp_e.CpGrade2, cp_e.CpGradeIcon[cp_e.CpGrade2]}, {cp_e.CpGrade3, cp_e.CpGradeIcon[cp_e.CpGrade3]}, {cp_e.CpGrade4, cp_e.CpGradeIcon[cp_e.CpGrade4]}, {cp_e.CpGrade5, cp_e.CpGradeIcon[cp_e.CpGrade5]}, } var CpGradePrivilegeList = map[cp_e.CpGrade][]CvPrivilege{ cp_e.CpGrade0: {}, cp_e.CpGrade1: { {cp_e.CpPrivilegeSpace, cp_e.CpPrivilegeNameMsgId[cp_e.CpPrivilegeSpace], "", cp_e.CpPrivilegeIcon[cp_e.CpPrivilegeSpace]}, {cp_e.CpPrivilegeBanner, cp_e.CpPrivilegeNameMsgId[cp_e.CpPrivilegeBanner], "", cp_e.CpPrivilegeIcon[cp_e.CpPrivilegeBanner]}, {cp_e.CpPrivilegeMedal, cp_e.CpPrivilegeNameMsgId[cp_e.CpPrivilegeMedal], "", cp_e.CpPrivilegeIcon[cp_e.CpPrivilegeMedal]}, {cp_e.CpPrivilegeCert, cp_e.CpPrivilegeNameMsgId[cp_e.CpPrivilegeCert], "", cp_e.CpPrivilegeIcon[cp_e.CpPrivilegeCert]}, }, cp_e.CpGrade2: { {cp_e.CpPrivilegeSpace, cp_e.CpPrivilegeNameMsgId[cp_e.CpPrivilegeSpace], "", cp_e.CpPrivilegeIcon[cp_e.CpPrivilegeSpace]}, {cp_e.CpPrivilegeBanner, cp_e.CpPrivilegeNameMsgId[cp_e.CpPrivilegeBanner], "", cp_e.CpPrivilegeIcon[cp_e.CpPrivilegeBanner]}, {cp_e.CpPrivilegeMedal, cp_e.CpPrivilegeNameMsgId[cp_e.CpPrivilegeMedal], "", cp_e.CpPrivilegeIcon[cp_e.CpPrivilegeMedal]}, {cp_e.CpPrivilegeCert, cp_e.CpPrivilegeNameMsgId[cp_e.CpPrivilegeCert], "", cp_e.CpPrivilegeIcon[cp_e.CpPrivilegeCert]}, {cp_e.CpPrivilegeRoomEffect, cp_e.CpPrivilegeNameMsgId[cp_e.CpPrivilegeRoomEffect], "", cp_e.CpPrivilegeIcon[cp_e.CpPrivilegeRoomEffect]}, }, cp_e.CpGrade3: { {cp_e.CpPrivilegeSpace, cp_e.CpPrivilegeNameMsgId[cp_e.CpPrivilegeSpace], "", cp_e.CpPrivilegeIcon[cp_e.CpPrivilegeSpace]}, {cp_e.CpPrivilegeBanner, cp_e.CpPrivilegeNameMsgId[cp_e.CpPrivilegeBanner], "", cp_e.CpPrivilegeIcon[cp_e.CpPrivilegeBanner]}, {cp_e.CpPrivilegeMedal, cp_e.CpPrivilegeNameMsgId[cp_e.CpPrivilegeMedal], "", cp_e.CpPrivilegeIcon[cp_e.CpPrivilegeMedal]}, {cp_e.CpPrivilegeCert, cp_e.CpPrivilegeNameMsgId[cp_e.CpPrivilegeCert], "", cp_e.CpPrivilegeIcon[cp_e.CpPrivilegeCert]}, {cp_e.CpPrivilegeRoomEffect, cp_e.CpPrivilegeNameMsgId[cp_e.CpPrivilegeRoomEffect], "", cp_e.CpPrivilegeIcon[cp_e.CpPrivilegeRoomEffect]}, {cp_e.CpPrivilegeHeadwear, cp_e.CpPrivilegeNameMsgId[cp_e.CpPrivilegeHeadwear], "", cp_e.CpPrivilegeIcon[cp_e.CpPrivilegeHeadwear]}, }, cp_e.CpGrade4: { {cp_e.CpPrivilegeSpace, cp_e.CpPrivilegeNameMsgId[cp_e.CpPrivilegeSpace], "", cp_e.CpPrivilegeIcon[cp_e.CpPrivilegeSpace]}, {cp_e.CpPrivilegeBanner, cp_e.CpPrivilegeNameMsgId[cp_e.CpPrivilegeBanner], "", cp_e.CpPrivilegeIcon[cp_e.CpPrivilegeBanner]}, {cp_e.CpPrivilegeMedal, cp_e.CpPrivilegeNameMsgId[cp_e.CpPrivilegeMedal], "", cp_e.CpPrivilegeIcon[cp_e.CpPrivilegeMedal]}, {cp_e.CpPrivilegeCert, cp_e.CpPrivilegeNameMsgId[cp_e.CpPrivilegeCert], "", cp_e.CpPrivilegeIcon[cp_e.CpPrivilegeCert]}, {cp_e.CpPrivilegeRoomEffect, cp_e.CpPrivilegeNameMsgId[cp_e.CpPrivilegeRoomEffect], "", cp_e.CpPrivilegeIcon[cp_e.CpPrivilegeRoomEffect]}, {cp_e.CpPrivilegeHeadwear, cp_e.CpPrivilegeNameMsgId[cp_e.CpPrivilegeHeadwear], "", cp_e.CpPrivilegeIcon[cp_e.CpPrivilegeHeadwear]}, {cp_e.CpPrivilegeActiveProfile, cp_e.CpPrivilegeNameMsgId[cp_e.CpPrivilegeActiveProfile], "", cp_e.CpPrivilegeIcon[cp_e.CpPrivilegeActiveProfile]}, }, cp_e.CpGrade5: { {cp_e.CpPrivilegeSpace, cp_e.CpPrivilegeNameMsgId[cp_e.CpPrivilegeSpace], "", cp_e.CpPrivilegeIcon[cp_e.CpPrivilegeSpace]}, {cp_e.CpPrivilegeBanner, cp_e.CpPrivilegeNameMsgId[cp_e.CpPrivilegeBanner], "", cp_e.CpPrivilegeIcon[cp_e.CpPrivilegeBanner]}, {cp_e.CpPrivilegeMedal, cp_e.CpPrivilegeNameMsgId[cp_e.CpPrivilegeMedal], "", cp_e.CpPrivilegeIcon[cp_e.CpPrivilegeMedal]}, {cp_e.CpPrivilegeCert, cp_e.CpPrivilegeNameMsgId[cp_e.CpPrivilegeCert], "", cp_e.CpPrivilegeIcon[cp_e.CpPrivilegeCert]}, {cp_e.CpPrivilegeRoomEffect, cp_e.CpPrivilegeNameMsgId[cp_e.CpPrivilegeRoomEffect], "", cp_e.CpPrivilegeIcon[cp_e.CpPrivilegeRoomEffect]}, {cp_e.CpPrivilegeHeadwear, cp_e.CpPrivilegeNameMsgId[cp_e.CpPrivilegeHeadwear], "", cp_e.CpPrivilegeIcon[cp_e.CpPrivilegeHeadwear]}, {cp_e.CpPrivilegeActiveProfile, cp_e.CpPrivilegeNameMsgId[cp_e.CpPrivilegeActiveProfile], "", cp_e.CpPrivilegeIcon[cp_e.CpPrivilegeActiveProfile]}, {cp_e.CpPrivilegeMicEffect, cp_e.CpPrivilegeNameMsgId[cp_e.CpPrivilegeMicEffect], "", cp_e.CpPrivilegeIcon[cp_e.CpPrivilegeMicEffect]}, }, } func CopyCpGradePrivilegeList(grade cp_e.CpGrade, lang string) []CvPrivilege { privileges := make([]CvPrivilege, len(CpGradePrivilegeList[grade])) copy(privileges, CpGradePrivilegeList[grade]) for i, v := range privileges { privileges[i].Name = GetTranslate(v.NameMsgId, lang) } return privileges } var translateCache = gcache.New(1000).LRU().Build() func GetTranslate(msgId uint, lang string) string { key := fmt.Sprintf("%v-%v", msgId, lang) if data, err := translateCache.Get(key); err == nil { return data.(string) } if resMul, _ := res_m.GetResMultiTextBy(mysql.Db, msgId, lang); resMul != nil { _ = translateCache.SetWithExpire(key, resMul.Content, time.Hour) return resMul.Content } return "default" }