feat(fe+be): 身份卡头像不再压扁 + 内容丰富

- 头像用九参数 drawImage 居中裁剪(cover),竖图/横图都不变形,加白边圈
- 后端 IDCard 增 zodiac(按生日算星座) + weight,卡面加「星座/体重」行
- 加淡淡的肉垫水印 + 旋转的「肉垫计划·官方认证」印章
- 画布加高容纳新增内容

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
Blizzard
2026-07-31 11:50:04 +08:00
parent 96c92f2cfb
commit bb7db78763
2 changed files with 110 additions and 24 deletions
+29 -2
View File
@@ -14,6 +14,8 @@ type IDCard struct {
Gender string `json:"gender"`
Breed string `json:"breed"`
Birthday string `json:"birthday"` // "2023 年 12 月 15 日"
Zodiac string `json:"zodiac"` // 星座,按生日算
Weight string `json:"weight"` // 体重,如 "13.5kg"
Intro string `json:"intro"`
AvatarURL string `json:"avatar_url"`
IDNo string `json:"id_no"` // 玩具身份号,不入库
@@ -51,6 +53,26 @@ func petIDNo(pet *model.Pet) string {
return b.String()
}
// zodiacOf 按月日算西方星座。按各星座起始日(含)顺序判定,
// 落在 12/221/19 的默认摩羯座
func zodiacOf(month, day int) string {
starts := []struct {
m, d int
name string
}{
{1, 20, "水瓶座"}, {2, 19, "双鱼座"}, {3, 21, "白羊座"}, {4, 20, "金牛座"},
{5, 21, "双子座"}, {6, 22, "巨蟹座"}, {7, 23, "狮子座"}, {8, 23, "处女座"},
{9, 23, "天秤座"}, {10, 24, "天蝎座"}, {11, 22, "射手座"}, {12, 22, "摩羯座"},
}
name := "摩羯座"
for _, s := range starts {
if month > s.m || (month == s.m && day >= s.d) {
name = s.name
}
}
return name
}
// GetIDCard 组装身份卡。小程序码是 best-effort:拿不到(未发布/配额)也照出卡
func (s *Service) GetIDCard(userID, petID string) (*IDCard, error) {
pet, err := s.GetPet(userID, petID)
@@ -72,10 +94,15 @@ func (s *Service) GetIDCard(userID, petID string) (*IDCard, error) {
validity = pet.Birthday.Format("2006.01.02") + " - 永远"
}
zodiac := ""
if pet.Birthday != nil && !pet.Birthday.IsZero() {
zodiac = zodiacOf(int(pet.Birthday.Month()), pet.Birthday.Day())
}
card := &IDCard{
Name: pet.Name, Species: pet.Type, Gender: pet.Gender, Breed: pet.Breed,
Birthday: bd, Intro: intro, AvatarURL: pet.AvatarURL,
IDNo: petIDNo(pet), Validity: validity,
Birthday: bd, Zodiac: zodiac, Weight: pet.Weight, Intro: intro,
AvatarURL: pet.AvatarURL, IDNo: petIDNo(pet), Validity: validity,
}
// 小程序码取不到不算错——未发布/配额用尽时卡照样出,只是没码