diff --git a/_const/enum/cp_e/anniversary.go b/_const/enum/cp_e/anniversary.go index a2011004ec33431dc9607c26c8c6b15659f686a3..c280bcef7ff188f3fc2e5762ab38d65a4841be53 100644 --- a/_const/enum/cp_e/anniversary.go +++ b/_const/enum/cp_e/anniversary.go @@ -5,5 +5,7 @@ type AnniversaryItemType int const ( AnniversaryItemTypeNormal AnniversaryItemType = 0 // 普通类型 AnniversaryItemTypeAvatar AnniversaryItemType = 1 // 头像类型 - AnniversaryItemTypeAnniversary AnniversaryItemType = 2 // 纪念日类型(一年一度,如生日/结婚纪念日) + AnniversaryItemTypeBirthday1 AnniversaryItemType = 2 // user1的生日 + AnniversaryItemTypeBirthday2 AnniversaryItemType = 3 // user2的生日 + AnniversaryItemTypeAnniversary AnniversaryItemType = 4 // 纪念日 ) diff --git a/_const/enum/cp_e/level.go b/_const/enum/cp_e/level.go index c43f14c2671b0691ee8608456c0bc59d87ea2611..159095ec10cb5af9cdc66cbcecb57079554b011b 100644 --- a/_const/enum/cp_e/level.go +++ b/_const/enum/cp_e/level.go @@ -69,16 +69,16 @@ var ( CpPrivilegeActiveProfile: 270, CpPrivilegeMicEffect: 271, } - // cp特权icon // todo ui - CpPrivilegeIcon = map[CpPrivilege]string{ - CpPrivilegeSpace: "icon_p_1.png", - CpPrivilegeBanner: "icon_p_2.png", - CpPrivilegeMedal: "icon_p_3.png", - CpPrivilegeCert: "icon_p_4.png", - CpPrivilegeRoomEffect: "icon_p_5.png", - CpPrivilegeHeadwear: "icon_p_6.png", - CpPrivilegeActiveProfile: "icon_p_7.png", - CpPrivilegeMicEffect: "icon_p_8.png", + // cp特权icon + CpPrivilegeIcon = map[CpPrivilege]map[CpLevel]string{ + CpPrivilegeSpace: {CpLevel0: "https://image.whoisamy.shop/hilo/resource/cp/cp_p_space.png", CpLevel1: "https://image.whoisamy.shop/hilo/resource/cp/cp_p_space.png", CpLevel2: "https://image.whoisamy.shop/hilo/resource/cp/cp_p_space.png", CpLevel3: "https://image.whoisamy.shop/hilo/resource/cp/cp_p_space.png", CpLevel4: "https://image.whoisamy.shop/hilo/resource/cp/cp_p_space.png", CpLevel5: "https://image.whoisamy.shop/hilo/resource/cp/cp_p_space.png"}, + CpPrivilegeBanner: {CpLevel1: "https://image.whoisamy.shop/hilo/resource/cp/cp_p_banner1.png", CpLevel2: "https://image.whoisamy.shop/hilo/resource/cp/cp_p_banner2.png", CpLevel3: "https://image.whoisamy.shop/hilo/resource/cp/cp_p_banner3.png", CpLevel4: "https://image.whoisamy.shop/hilo/resource/cp/cp_p_banner4.png", CpLevel5: "https://image.whoisamy.shop/hilo/resource/cp/cp_p_banner5.png"}, + CpPrivilegeMedal: {CpLevel1: "https://image.whoisamy.shop/hilo/resource/cp/cp_p_medal1.png", CpLevel2: "https://image.whoisamy.shop/hilo/resource/cp/cp_p_medal2.png", CpLevel3: "https://image.whoisamy.shop/hilo/resource/cp/cp_p_medal3.png", CpLevel4: "https://image.whoisamy.shop/hilo/resource/cp/cp_p_medal4.png", CpLevel5: "https://image.whoisamy.shop/hilo/resource/cp/cp_p_medal5.png"}, + CpPrivilegeCert: {CpLevel0: "https://image.whoisamy.shop/hilo/resource/cp/cp_p_cert0.png", CpLevel1: "https://image.whoisamy.shop/hilo/resource/cp/cp_p_cert1.png", CpLevel2: "https://image.whoisamy.shop/hilo/resource/cp/cp_p_cert2.png", CpLevel3: "https://image.whoisamy.shop/hilo/resource/cp/cp_p_cert3.png", CpLevel4: "https://image.whoisamy.shop/hilo/resource/cp/cp_p_cert4.png", CpLevel5: "https://image.whoisamy.shop/hilo/resource/cp/cp_p_cert5.png"}, + CpPrivilegeRoomEffect: {CpLevel2: "https://image.whoisamy.shop/hilo/resource/cp/cp_p_enter2.png", CpLevel3: "https://image.whoisamy.shop/hilo/resource/cp/cp_p_enter3.png", CpLevel4: "https://image.whoisamy.shop/hilo/resource/cp/cp_p_enter4.png", CpLevel5: "https://image.whoisamy.shop/hilo/resource/cp/cp_p_enter5.png"}, + CpPrivilegeHeadwear: {CpLevel3: "https://image.whoisamy.shop/hilo/resource/cp/cp_p_headwear.png", CpLevel4: "https://image.whoisamy.shop/hilo/resource/cp/cp_p_headwear.png", CpLevel5: "https://image.whoisamy.shop/hilo/resource/cp/cp_p_headwear.png"}, + CpPrivilegeActiveProfile: {CpLevel4: "https://image.whoisamy.shop/hilo/resource/cp/cp_p_profile.png", CpLevel5: "https://image.whoisamy.shop/hilo/resource/cp/cp_p_profile.png"}, + CpPrivilegeMicEffect: {CpLevel5: "https://image.whoisamy.shop/hilo/resource/cp/cp_p_mic.png"}, } ) diff --git a/cv/cp_cv/space.go b/cv/cp_cv/space.go index dc2093dd78fa014c5bfeaf25ec754ad4268693c7..9d4261d3d284d51220cb3dde9fcb86db77cb7f8a 100644 --- a/cv/cp_cv/space.go +++ b/cv/cp_cv/space.go @@ -72,14 +72,14 @@ var CvResLevelList = []CvResLevel{ } var ( - 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, CpPrivilegeLevelList[cp_e.CpPrivilegeSpace]} - 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, CpPrivilegeLevelList[cp_e.CpPrivilegeBanner]} - 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, CpPrivilegeLevelList[cp_e.CpPrivilegeMedal]} - 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, CpPrivilegeLevelList[cp_e.CpPrivilegeCert]} - 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, CpPrivilegeLevelList[cp_e.CpPrivilegeRoomEffect]} - 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, CpPrivilegeLevelList[cp_e.CpPrivilegeHeadwear]} - 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, CpPrivilegeLevelList[cp_e.CpPrivilegeActiveProfile]} - 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, CpPrivilegeLevelList[cp_e.CpPrivilegeMicEffect]} + CvPrivilege1 = CvPrivilege{cp_e.CpPrivilegeSpace, cp_e.CpPrivilegeNameMsgId[cp_e.CpPrivilegeSpace], "", cp_e.CpPrivilegeDescMsgId[cp_e.CpPrivilegeSpace], "", "", false, false, CpPrivilegeLevelList[cp_e.CpPrivilegeSpace]} + CvPrivilege2 = CvPrivilege{cp_e.CpPrivilegeBanner, cp_e.CpPrivilegeNameMsgId[cp_e.CpPrivilegeBanner], "", cp_e.CpPrivilegeDescMsgId[cp_e.CpPrivilegeBanner], "", "", false, false, CpPrivilegeLevelList[cp_e.CpPrivilegeBanner]} + CvPrivilege3 = CvPrivilege{cp_e.CpPrivilegeMedal, cp_e.CpPrivilegeNameMsgId[cp_e.CpPrivilegeMedal], "", cp_e.CpPrivilegeDescMsgId[cp_e.CpPrivilegeMedal], "", "", false, false, CpPrivilegeLevelList[cp_e.CpPrivilegeMedal]} + CvPrivilege4 = CvPrivilege{cp_e.CpPrivilegeCert, cp_e.CpPrivilegeNameMsgId[cp_e.CpPrivilegeCert], "", cp_e.CpPrivilegeDescMsgId[cp_e.CpPrivilegeCert], "", "", false, false, CpPrivilegeLevelList[cp_e.CpPrivilegeCert]} + CvPrivilege5 = CvPrivilege{cp_e.CpPrivilegeRoomEffect, cp_e.CpPrivilegeNameMsgId[cp_e.CpPrivilegeRoomEffect], "", cp_e.CpPrivilegeDescMsgId[cp_e.CpPrivilegeRoomEffect], "", "", true, false, CpPrivilegeLevelList[cp_e.CpPrivilegeRoomEffect]} + CvPrivilege6 = CvPrivilege{cp_e.CpPrivilegeHeadwear, cp_e.CpPrivilegeNameMsgId[cp_e.CpPrivilegeHeadwear], "", cp_e.CpPrivilegeDescMsgId[cp_e.CpPrivilegeHeadwear], "", "", false, false, CpPrivilegeLevelList[cp_e.CpPrivilegeHeadwear]} + CvPrivilege7 = CvPrivilege{cp_e.CpPrivilegeActiveProfile, cp_e.CpPrivilegeNameMsgId[cp_e.CpPrivilegeActiveProfile], "", cp_e.CpPrivilegeDescMsgId[cp_e.CpPrivilegeActiveProfile], "", "", true, false, CpPrivilegeLevelList[cp_e.CpPrivilegeActiveProfile]} + CvPrivilege8 = CvPrivilege{cp_e.CpPrivilegeMicEffect, cp_e.CpPrivilegeNameMsgId[cp_e.CpPrivilegeMicEffect], "", cp_e.CpPrivilegeDescMsgId[cp_e.CpPrivilegeMicEffect], "", "", false, false, CpPrivilegeLevelList[cp_e.CpPrivilegeMicEffect]} ) var CpLevelPrivilegeList = map[cp_e.CpLevel][]CvPrivilege{ @@ -108,6 +108,7 @@ func CopyCpLevelPrivilegeList(Level cp_e.CpLevel, lang string) []CvPrivilege { for i, v := range privileges { privileges[i].Name = GetTranslate(v.NameMsgId, lang) privileges[i].Desc = GetTranslate(v.DescMsgId, lang) + privileges[i].Icon = cp_e.CpPrivilegeIcon[v.Type][Level] } return privileges } diff --git a/domain/model/cp_m/anniversary.go b/domain/model/cp_m/anniversary.go index a85da083416c1e4a9e846d051d945cb0907955d2..9f48924255968454af861bdf16c87aaf32fee808 100644 --- a/domain/model/cp_m/anniversary.go +++ b/domain/model/cp_m/anniversary.go @@ -36,10 +36,10 @@ func InitCpAnniversary(model *domain.Model, cp CpRelation, lang string) error { if err := AddCpAnniversary(model, cp_e.AnniversaryItemTypeNormal, cp, GetTranslate(259, lang), time.Now().Unix(), true, 100, 259); err != nil { return err } - if err := AddCpAnniversary(model, cp_e.AnniversaryItemTypeAnniversary, cp, fmt.Sprintf(GetTranslate(260, lang), users[cp.UserId1].Nick), 0, true, 0, 260); err != nil { + if err := AddCpAnniversary(model, cp_e.AnniversaryItemTypeBirthday1, cp, fmt.Sprintf(GetTranslate(260, lang), users[cp.UserId1].Nick), 0, true, 0, 260); err != nil { return err } - if err := AddCpAnniversary(model, cp_e.AnniversaryItemTypeAnniversary, cp, fmt.Sprintf(GetTranslate(260, lang), users[cp.UserId2].Nick), 0, true, 0, 260); err != nil { + if err := AddCpAnniversary(model, cp_e.AnniversaryItemTypeBirthday2, cp, fmt.Sprintf(GetTranslate(260, lang), users[cp.UserId2].Nick), 0, true, 0, 260); err != nil { return err } if err := AddCpAnniversary(model, cp_e.AnniversaryItemTypeNormal, cp, GetTranslate(261, lang), 0, true, 0, 261); err != nil { @@ -110,17 +110,14 @@ func GetAllCpAnniversary(model *domain.Model, userId mysql.ID, lang string) []Cp } var userIds = []mysql.ID{relation.UserId1, relation.UserId2} users, _ := user_m.GetUserMapByIds(model, userIds) - n := 0 for i, v := range res { if v.CreatedTime.Equal(v.UpdatedTime) && v.MsgId > 0 { - res[i].Content = GetTranslate(v.MsgId, lang) - if v.MsgId == 260 { - n++ - if n == 1 { - res[i].Content = fmt.Sprintf(GetTranslate(v.MsgId, lang), users[relation.UserId1].Nick) - } else { - res[i].Content = fmt.Sprintf(GetTranslate(v.MsgId, lang), users[relation.UserId2].Nick) - } + if v.Type == cp_e.AnniversaryItemTypeBirthday1 { + res[i].Content = fmt.Sprintf(GetTranslate(v.MsgId, lang), users[relation.UserId1].Nick) + } else if v.Type == cp_e.AnniversaryItemTypeBirthday2 { + res[i].Content = fmt.Sprintf(GetTranslate(v.MsgId, lang), users[relation.UserId2].Nick) + } else { + res[i].Content = GetTranslate(v.MsgId, lang) } } } @@ -140,7 +137,7 @@ func GetNeedRemindCpAnniversary(model *domain.Model) []CpAnniversary { } now := time.Now().Unix() for i, v := range rows { - ts := CalcNextAnniversary(v.Timestamp) + ts := CalcNextAnniversary(v.Timestamp, time.Local) if now > ts { res = append(res, rows[i]) } @@ -149,7 +146,7 @@ func GetNeedRemindCpAnniversary(model *domain.Model) []CpAnniversary { } // 获取cp当天需要提醒的纪念日 -func GetUserTodayCpAnniversary(model *domain.Model, cpId mysql.ID) []CpAnniversary { +func GetUserTodayCpAnniversary(model *domain.Model, cpId mysql.ID, tz *time.Location) []CpAnniversary { var rows, res []CpAnniversary if err := model.DB().Model(CpAnniversary{}). Where("`timestamp` > 0"). @@ -161,7 +158,7 @@ func GetUserTodayCpAnniversary(model *domain.Model, cpId mysql.ID) []CpAnniversa } now := time.Now().Unix() for i, v := range rows { - ts := CalcNextAnniversary(v.Timestamp) + ts := CalcNextAnniversary(v.Timestamp, tz) if now > ts { res = append(res, rows[i]) } @@ -174,11 +171,14 @@ func UpdateCpAnniversaryReminded(model *domain.Model, id mysql.ID) error { } // 计算下一个纪念日 -func CalcNextAnniversary(timestamp int64) int64 { +func CalcNextAnniversary(timestamp int64, tz *time.Location) int64 { + if tz == nil { + tz = time.Local + } now := time.Now() birthday := time.Unix(timestamp, 0) // 计算今年的生日日期 - thisYearBirthday := time.Date(now.Year(), birthday.Month(), birthday.Day(), 0, 0, 0, 0, time.Local) + thisYearBirthday := time.Date(now.Year(), birthday.Month(), birthday.Day(), 0, 0, 0, 0, tz) // 如果今年的生日还未到,则生日日期为今年的生日日期;否则为明年的生日日期 var next time.Time diff --git a/route/cp_r/anniversary.go b/route/cp_r/anniversary.go index f0c23c8e33f0ae5ad21a4cee216f1708bce91856..f59f839f019231901bc3e5ed4b6cae79a5e44aa3 100644 --- a/route/cp_r/anniversary.go +++ b/route/cp_r/anniversary.go @@ -1,6 +1,7 @@ package cp_r import ( + "git.hilo.cn/hilo-common/_const/enum/timezone_e" "git.hilo.cn/hilo-common/domain" "git.hilo.cn/hilo-common/mycontext" "github.com/gin-gonic/gin" @@ -92,8 +93,19 @@ func PageAnniversary(c *gin.Context) (*mycontext.MyContext, error) { if err != nil { return myCtx, err } - var response = make([]cp_cv.CvCpAnniversary, 0) model := domain.CreateModelContext(myCtx) + loc := timezone_e.GetFixedTimezone(c.GetHeader(mycontext.TIMEZONE)) + if loc == nil { + user, err := user_m.GetUser(model, userId) + if err != nil { + return myCtx, err + } + if user.Language == "ar" { + loc = timezone_e.KSATimezoneLoc + } + } + + var response = make([]cp_cv.CvCpAnniversary, 0) cpRelation, exits := cp_m.GetCpRelation(model, userId) if exits { userIds := []uint64{cpRelation.UserId1, cpRelation.UserId2} @@ -121,8 +133,8 @@ func PageAnniversary(c *gin.Context) (*mycontext.MyContext, error) { anniversary := cp_m.GetAllCpAnniversary(model, userId, lang) for _, v := range anniversary { timestamp := v.Timestamp - if v.Type == cp_e.AnniversaryItemTypeAnniversary && timestamp > 0 { - timestamp = cp_m.CalcNextAnniversary(timestamp) + if v.Type >= cp_e.AnniversaryItemTypeBirthday1 && timestamp > 0 { + timestamp = cp_m.CalcNextAnniversary(timestamp, loc) } // 客户端只认识0 1 Type := v.Type diff --git a/route/cp_r/space.go b/route/cp_r/space.go index ac0ed4a43778aaa21762ec581fadec0a666bfe01..656b2fd99b21b29592673da5a70773221642d073 100644 --- a/route/cp_r/space.go +++ b/route/cp_r/space.go @@ -1,6 +1,7 @@ package cp_r import ( + "git.hilo.cn/hilo-common/_const/enum/timezone_e" "git.hilo.cn/hilo-common/domain" "git.hilo.cn/hilo-common/mycontext" "git.hilo.cn/hilo-common/resource/mysql" @@ -30,15 +31,21 @@ func CpSpace(c *gin.Context) (*mycontext.MyContext, error) { if err != nil { return myContext, err } - externalId := c.Query("externalId") - if len(externalId) <= 0 { - return myContext, bizerr.InvalidParameter - } var model = domain.CreateModelContext(myContext) userInfo, err := user_m.GetUser(model, userId) if err != nil { return myContext, err } + loc := timezone_e.GetFixedTimezone(c.GetHeader(mycontext.TIMEZONE)) + if loc == nil { + if userInfo.Language == "ar" { + loc = timezone_e.KSATimezoneLoc + } + } + externalId := c.Query("externalId") + if len(externalId) <= 0 { + return myContext, bizerr.InvalidParameter + } targetUserInfo, err := user_m.GetUserByExtId(model, externalId) if err != nil { return myContext, err @@ -130,7 +137,7 @@ func CpSpace(c *gin.Context) (*mycontext.MyContext, error) { } // 需要提醒的纪念日 if exists && (userId == cpRelation.UserId1 || userId == cpRelation.UserId2) { - anniversary := cp_m.GetUserTodayCpAnniversary(model, cpRelation.Id) + anniversary := cp_m.GetUserTodayCpAnniversary(model, cpRelation.Id, loc) for _, a := range anniversary { response.CpAnniversary = append(response.CpAnniversary, cp_cv.CvCpAnniversary{ Id: a.ID, diff --git a/test/cp_test.go b/test/cp_test.go index 0974f13bafdbe0711c313fb7c1a6073418e423fa..fb41739721f5f97b0d987891842c89c7d2f519e1 100644 --- a/test/cp_test.go +++ b/test/cp_test.go @@ -1,9 +1,11 @@ package test import ( + "git.hilo.cn/hilo-common/_const/enum/timezone_e" "git.hilo.cn/hilo-common/domain" "hilo-user/domain/model/cp_m" "testing" + "time" ) func TestInitCpAnniversary(t *testing.T) { @@ -16,6 +18,15 @@ func TestInitCpAnniversary(t *testing.T) { } func TestCalcNextAnniversary(t *testing.T) { - t2 := cp_m.CalcNextAnniversary(1686211996) + t2 := cp_m.CalcNextAnniversary(1686211996, time.Local) println(t2) } + +func TestCalLoc(t *testing.T) { + loc := timezone_e.GetFixedTimezone("GMT+8") + println(time.Now().In(loc).Format("2006-01-02 15:04:05")) + loc = timezone_e.GetFixedTimezone("GMT+3") + println(time.Now().In(loc).Format("2006-01-02 15:04:05")) + loc = timezone_e.GetFixedTimezone("GMT+5") + println(time.Now().In(loc).Format("2006-01-02 15:04:05")) +}