space.go 6.63 KB
Newer Older
hujiebin's avatar
hujiebin committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14
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 {
hujiebin's avatar
hujiebin committed
15 16 17 18 19
	UserInfo      *user_cv.UserTiny `json:"userInfo"`             // 用户信息
	CpUserInfo    *user_cv.UserTiny `json:"cpUserInfo,omitempty"` // cp用户信息
	CpDays        int               `json:"cpDays"`               // cp天数
	VisitTimes    int64             `json:"visitTimes"`           // 空间访问量
	ApplyToUnbind bool              `json:"applyToUnbind"`        // 是否申请撤销cp
hujiebin's avatar
hujiebin committed
20 21 22
}

// cp等级
23
type CvCpLevel struct {
hujiebin's avatar
hujiebin committed
24 25 26 27 28 29
	Level          cp_e.CpLevel `json:"level"`                  // 等级 0:无称号 1:恋爱CP 2:甜蜜CP 3:忠诚CP 4:炽热CP 5:荣耀CP
	Points         uint32       `json:"points"`                 // CP值
	StartPoints    uint32       `json:"startPoints,omitempty"`  // 上个等级所需CP值
	EndPoints      uint32       `json:"endPoints,omitempty"`    // 下个等级所需CP值
	ExpireAtUnix   int64        `json:"expireAtUnix,omitempty"` // 有效期,时间戳
	SettlementDate string       `json:"settlementDate"`         // 等级过期时间
hujiebin's avatar
1  
hujiebin committed
30
	MaxLevel       cp_e.CpLevel `json:"maxLevel"`               // cp最大的等级
hujiebin's avatar
hujiebin committed
31
	Title          string       `json:"title,omitempty"`        // 称号翻译
hujiebin's avatar
hujiebin committed
32 33 34
}

// 资源等级
35
type CvResLevel struct {
hujiebin's avatar
hujiebin committed
36 37 38 39
	Level       cp_e.CpLevel `json:"level"`               // 等级
	Icon        string       `json:"icon"`                // 等级icon图
	StartPoints uint32       `json:"startPoints"`         // 上个等级所需CP值
	EndPoints   uint32       `json:"endPoints,omitempty"` // 下个等级所需CP值
hujiebin's avatar
hujiebin committed
40 41 42 43
}

// 特权信息
type CvPrivilege struct {
hujiebin's avatar
hujiebin committed
44 45 46 47 48
	Type       cp_e.CpPrivilege `json:"type"` // 特权id 1:空间 2:横幅 3:等级勋章 4:证书 5:进场特效 6:头像头饰 7:动态资料卡 8:麦位特效
	NameMsgId  uint             `json:"-"`    // 名称-翻译id
	Name       string           `json:"name"` // 名称
	DescMsgId  uint             `json:"-"`    // 描述-翻译id
	Desc       string           `json:"desc"`
hujiebin's avatar
hujiebin committed
49 50 51
	Icon       string           `json:"icon"`       // 图标
	CanSwitch  bool             `json:"canSwitch"`  // 能否开关
	UserSwitch bool             `json:"userSwitch"` // 用户开关
hujiebin's avatar
hujiebin committed
52 53 54 55
}

// cp空间页
type CvSpace struct {
56 57 58 59 60
	CpInfo        CvCpInfo          `json:"cpInfo"`        // cp信息
	CpLevel       CvCpLevel         `json:"cpLevel"`       // cp等级
	ResLevelList  []CvResLevel      `json:"resLevelList"`  // 资源等级列表,无称号/恋爱CP/甜蜜CP/忠诚CP/炽热CP/荣耀CP
	PrivilegeList [][]CvPrivilege   `json:"privilegeList"` // 等级特权
	CpAnniversary []CvCpAnniversary `json:"cpAnniversary"` // 提醒的纪念日
hujiebin's avatar
hujiebin committed
61 62
}

63
var CvResLevelList = []CvResLevel{
hujiebin's avatar
hujiebin committed
64 65 66 67 68 69
	{cp_e.CpLevel0, cp_e.CpLevelIcon[cp_e.CpLevel0], cp_e.CpLevelPoints[cp_e.CpLevel0], cp_e.CpLevelPoints[cp_e.CpLevel1]},
	{cp_e.CpLevel1, cp_e.CpLevelIcon[cp_e.CpLevel1], cp_e.CpLevelPoints[cp_e.CpLevel1], cp_e.CpLevelPoints[cp_e.CpLevel2]},
	{cp_e.CpLevel2, cp_e.CpLevelIcon[cp_e.CpLevel2], cp_e.CpLevelPoints[cp_e.CpLevel2], cp_e.CpLevelPoints[cp_e.CpLevel3]},
	{cp_e.CpLevel3, cp_e.CpLevelIcon[cp_e.CpLevel3], cp_e.CpLevelPoints[cp_e.CpLevel3], cp_e.CpLevelPoints[cp_e.CpLevel4]},
	{cp_e.CpLevel4, cp_e.CpLevelIcon[cp_e.CpLevel4], cp_e.CpLevelPoints[cp_e.CpLevel4], cp_e.CpLevelPoints[cp_e.CpLevel5]},
	{cp_e.CpLevel5, cp_e.CpLevelIcon[cp_e.CpLevel5], cp_e.CpLevelPoints[cp_e.CpLevel5], cp_e.CpLevelPoints[cp_e.CpLevelMax]},
hujiebin's avatar
hujiebin committed
70 71
}

hujiebin's avatar
hujiebin committed
72
var (
hujiebin's avatar
hujiebin committed
73 74 75 76 77 78 79 80
	CvPrivilege1 = CvPrivilege{cp_e.CpPrivilegeSpace, cp_e.CpPrivilegeNameMsgId[cp_e.CpPrivilegeSpace], "", cp_e.CpPrivilegeDescMsgId[cp_e.CpPrivilegeSpace], "", cp_e.CpPrivilegeIcon[cp_e.CpPrivilegeSpace], false, false}
	CvPrivilege2 = CvPrivilege{cp_e.CpPrivilegeBanner, cp_e.CpPrivilegeNameMsgId[cp_e.CpPrivilegeBanner], "", cp_e.CpPrivilegeDescMsgId[cp_e.CpPrivilegeBanner], "", cp_e.CpPrivilegeIcon[cp_e.CpPrivilegeBanner], false, false}
	CvPrivilege3 = CvPrivilege{cp_e.CpPrivilegeMedal, cp_e.CpPrivilegeNameMsgId[cp_e.CpPrivilegeMedal], "", cp_e.CpPrivilegeDescMsgId[cp_e.CpPrivilegeMedal], "", cp_e.CpPrivilegeIcon[cp_e.CpPrivilegeMedal], false, false}
	CvPrivilege4 = CvPrivilege{cp_e.CpPrivilegeCert, cp_e.CpPrivilegeNameMsgId[cp_e.CpPrivilegeCert], "", cp_e.CpPrivilegeDescMsgId[cp_e.CpPrivilegeCert], "", cp_e.CpPrivilegeIcon[cp_e.CpPrivilegeCert], false, false}
	CvPrivilege5 = CvPrivilege{cp_e.CpPrivilegeRoomEffect, cp_e.CpPrivilegeNameMsgId[cp_e.CpPrivilegeRoomEffect], "", cp_e.CpPrivilegeDescMsgId[cp_e.CpPrivilegeRoomEffect], "", cp_e.CpPrivilegeIcon[cp_e.CpPrivilegeRoomEffect], true, false}
	CvPrivilege6 = CvPrivilege{cp_e.CpPrivilegeHeadwear, cp_e.CpPrivilegeNameMsgId[cp_e.CpPrivilegeHeadwear], "", cp_e.CpPrivilegeDescMsgId[cp_e.CpPrivilegeHeadwear], "", cp_e.CpPrivilegeIcon[cp_e.CpPrivilegeHeadwear], false, false}
	CvPrivilege7 = CvPrivilege{cp_e.CpPrivilegeActiveProfile, cp_e.CpPrivilegeNameMsgId[cp_e.CpPrivilegeActiveProfile], "", cp_e.CpPrivilegeDescMsgId[cp_e.CpPrivilegeActiveProfile], "", cp_e.CpPrivilegeIcon[cp_e.CpPrivilegeActiveProfile], true, false}
	CvPrivilege8 = CvPrivilege{cp_e.CpPrivilegeMicEffect, cp_e.CpPrivilegeNameMsgId[cp_e.CpPrivilegeMicEffect], "", cp_e.CpPrivilegeDescMsgId[cp_e.CpPrivilegeMicEffect], "", cp_e.CpPrivilegeIcon[cp_e.CpPrivilegeMicEffect], false, false}
hujiebin's avatar
hujiebin committed
81 82
)

83
var CpLevelPrivilegeList = map[cp_e.CpLevel][]CvPrivilege{
hujiebin's avatar
hujiebin committed
84
	cp_e.CpLevel0: {CvPrivilege1},
hujiebin's avatar
hujiebin committed
85 86 87 88 89
	cp_e.CpLevel1: {CvPrivilege1, CvPrivilege2, CvPrivilege3, CvPrivilege4},
	cp_e.CpLevel2: {CvPrivilege1, CvPrivilege2, CvPrivilege3, CvPrivilege4, CvPrivilege5},
	cp_e.CpLevel3: {CvPrivilege1, CvPrivilege2, CvPrivilege3, CvPrivilege4, CvPrivilege5, CvPrivilege6},
	cp_e.CpLevel4: {CvPrivilege1, CvPrivilege2, CvPrivilege3, CvPrivilege4, CvPrivilege5, CvPrivilege6, CvPrivilege7},
	cp_e.CpLevel5: {CvPrivilege1, CvPrivilege2, CvPrivilege3, CvPrivilege4, CvPrivilege5, CvPrivilege6, CvPrivilege7, CvPrivilege8},
hujiebin's avatar
hujiebin committed
90 91
}

92 93 94
func CopyCpLevelPrivilegeList(Level cp_e.CpLevel, lang string) []CvPrivilege {
	privileges := make([]CvPrivilege, len(CpLevelPrivilegeList[Level]))
	copy(privileges, CpLevelPrivilegeList[Level])
hujiebin's avatar
hujiebin committed
95 96
	for i, v := range privileges {
		privileges[i].Name = GetTranslate(v.NameMsgId, lang)
hujiebin's avatar
hujiebin committed
97
		privileges[i].Desc = GetTranslate(v.DescMsgId, lang)
hujiebin's avatar
hujiebin committed
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
	}
	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"
}