feat: 宠物加性格/过敏/备注字段 + 身份卡照护信息 + 微信取手机号
- Pet 增 personality/allergy/notes;建档表单加「性格标签(多选)/过敏/备注」 - IDCard 增 color/personality/owner/phone(脱敏)/allergy/notes/疫苗驱虫状态/发证机构 - 微信取手机号:POST /api/user/phone 用 getPhoneNumber 的 code 换手机号存库 (BindPhoneByCode 走 getuserphonenumber,复用 access_token) Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -17,11 +17,23 @@ type IDCard struct {
|
||||
Zodiac string `json:"zodiac"` // 星座,按生日算
|
||||
Weight string `json:"weight"` // 体重,如 "13.5kg"
|
||||
Intro string `json:"intro"`
|
||||
Color string `json:"color"` // 毛色
|
||||
Personality string `json:"personality"` // 性格标签,逗号分隔
|
||||
AvatarURL string `json:"avatar_url"`
|
||||
IDNo string `json:"id_no"` // 玩具身份号,不入库
|
||||
Validity string `json:"validity"` // "2023.12.15 - 永远"
|
||||
QRURL string `json:"qr_url"` // 小程序码,未发布时为空
|
||||
QRReady bool `json:"qr_ready"` // 码有没有生成出来
|
||||
|
||||
// —— 背面:照护信息 ——
|
||||
Owner string `json:"owner"` // 主人昵称
|
||||
Phone string `json:"phone"` // 联系电话(脱敏)
|
||||
Allergy string `json:"allergy"` // 过敏情况
|
||||
Notes string `json:"notes"` // 备注
|
||||
VaccineState string `json:"vaccine_state"` // 疫苗情况
|
||||
DewormState string `json:"deworm_state"` // 驱虫情况
|
||||
Org string `json:"org"` // 发证机构
|
||||
|
||||
QRURL string `json:"qr_url"` // 小程序码,未发布时为空
|
||||
QRReady bool `json:"qr_ready"` // 码有没有生成出来
|
||||
}
|
||||
|
||||
// petIDNo 造一个稳定的「身份号」。纯装饰,不入库、不做校验。
|
||||
@@ -73,6 +85,14 @@ func zodiacOf(month, day int) string {
|
||||
return name
|
||||
}
|
||||
|
||||
// maskPhone 脱敏手机号:138****8888。空或非 11 位原样返回
|
||||
func maskPhone(p string) string {
|
||||
if len(p) != 11 {
|
||||
return p
|
||||
}
|
||||
return p[:3] + "****" + p[7:]
|
||||
}
|
||||
|
||||
// GetIDCard 组装身份卡。小程序码是 best-effort:拿不到(未发布/配额)也照出卡
|
||||
func (s *Service) GetIDCard(userID, petID string) (*IDCard, error) {
|
||||
pet, err := s.GetPet(userID, petID)
|
||||
@@ -99,10 +119,39 @@ func (s *Service) GetIDCard(userID, petID string) (*IDCard, error) {
|
||||
zodiac = zodiacOf(int(pet.Birthday.Month()), pet.Birthday.Day())
|
||||
}
|
||||
|
||||
// 主人昵称 + 脱敏电话
|
||||
var user model.User
|
||||
s.db.First(&user, userID)
|
||||
owner := user.Nickname
|
||||
if owner == "" {
|
||||
owner = "铲屎官"
|
||||
}
|
||||
|
||||
// 疫苗:有记录算已接种;驱虫:取下一次到期提醒的日期
|
||||
var vaccineCnt int64
|
||||
s.db.Model(&model.HealthRecord{}).Where("pet_id = ? AND type = ?", petID, model.RecordVaccine).Count(&vaccineCnt)
|
||||
vaccineState := "待接种"
|
||||
if vaccineCnt > 0 {
|
||||
vaccineState = "已接种"
|
||||
}
|
||||
dewormState := "—"
|
||||
var dw model.Reminder
|
||||
if err := s.db.Where("pet_id = ? AND type = ?", petID, model.ReminderDeworm).Order("next_due_date asc").First(&dw).Error; err == nil && dw.NextDueDate != nil {
|
||||
dewormState = dw.NextDueDate.Format("2006.01.02")
|
||||
}
|
||||
|
||||
allergy := pet.Allergy
|
||||
if allergy == "" {
|
||||
allergy = "无"
|
||||
}
|
||||
|
||||
card := &IDCard{
|
||||
Name: pet.Name, Species: pet.Type, Gender: pet.Gender, Breed: pet.Breed,
|
||||
Birthday: bd, Zodiac: zodiac, Weight: pet.Weight, Intro: intro,
|
||||
Color: pet.Color, Personality: pet.Personality,
|
||||
AvatarURL: pet.AvatarURL, IDNo: petIDNo(pet), Validity: validity,
|
||||
Owner: owner, Phone: maskPhone(user.Phone), Allergy: allergy, Notes: pet.Notes,
|
||||
VaccineState: vaccineState, DewormState: dewormState, Org: "肉垫计划",
|
||||
}
|
||||
|
||||
// 小程序码取不到不算错——未发布/配额用尽时卡照样出,只是没码
|
||||
|
||||
Reference in New Issue
Block a user