feat: 养护模板/社区运营/体重趋势/计划日历 + 雪花ID重构 + 文件表与图片上传
后端
- 主键改雪花字符串 ID(pkg/idgen + Base.BeforeCreate),全表外键/JWT/中间件随之调整
- 新增 files 表:/api/upload 按 MD5 去重,返回 {id,url,md5},服务端只收图片
- 头像/记录附图/帖子图改 file_id 关联,读取解析为 URL
- 养护模板(物种×阶段)后台可配 + AI 生成草稿;建档按模板生成任务/计划/提醒
- 社区 AI 运营:虚拟账号池 + 每日定时/手动生成,帖子带 AI 标
- 计划路线图节点带真实日期;首页周历与计划日历同源;新增 day-plan 当日安排
- 体重趋势接口带备注;记录列表分页
小程序
- 公共图片上传 utils/upload.js(仅图片);记录拍照/我的头像/社区发图三处接入
- 首页日历点选查当日任务;记录页体重趋势可点看备注 + 时间轴分页折叠
- 计划页日历点选查当日计划;自定义 tabBar 高度调整
后台(React)
- 新增「养护模板」「社区运营」页;用户管理加机器人筛选
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -3,8 +3,8 @@ package model
|
||||
// AIMessage AI 聊天消息
|
||||
type AIMessage struct {
|
||||
Base
|
||||
UserID uint `gorm:"index" json:"user_id"`
|
||||
PetID *uint `json:"pet_id"`
|
||||
UserID string `gorm:"size:24;index" json:"user_id"`
|
||||
PetID *string `gorm:"size:24" json:"pet_id"`
|
||||
Session string `gorm:"size:64;index" json:"session"`
|
||||
Role string `gorm:"size:8" json:"role"` // user / ai
|
||||
Text string `gorm:"type:text" json:"text"`
|
||||
|
||||
@@ -1,14 +1,28 @@
|
||||
package model
|
||||
|
||||
import "time"
|
||||
import (
|
||||
"time"
|
||||
|
||||
// Base 所有模型的公共字段
|
||||
"gorm.io/gorm"
|
||||
|
||||
"github.com/sundynix/pets-be/pkg/idgen"
|
||||
)
|
||||
|
||||
// Base 所有模型的公共字段。主键为雪花算法字符串 ID(非自增)。
|
||||
type Base struct {
|
||||
ID uint `gorm:"primarykey" json:"id"`
|
||||
ID string `gorm:"primaryKey;size:24" json:"id"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
}
|
||||
|
||||
// BeforeCreate 未显式赋值时自动生成雪花 ID(通过嵌入对所有模型生效)。
|
||||
func (b *Base) BeforeCreate(tx *gorm.DB) error {
|
||||
if b.ID == "" {
|
||||
b.ID = idgen.Next()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// AllModels 需要 AutoMigrate 的模型清单(按依赖顺序)
|
||||
func AllModels() []any {
|
||||
return []any{
|
||||
@@ -27,5 +41,9 @@ func AllModels() []any {
|
||||
&ProMembership{},
|
||||
&Admin{},
|
||||
&DailyAdvice{},
|
||||
&CareTemplate{},
|
||||
&CareTemplateItem{},
|
||||
&CommunityBotConfig{},
|
||||
&File{},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
package model
|
||||
|
||||
// 养护模板:按「物种 × 阶段」配置建档时生成的今日任务 / 30天计划 / 提醒。
|
||||
// 管理员可 AI 生成草稿后修改保存;建档时按宠物物种阶段套用,查不到回退内置默认。
|
||||
|
||||
// 物种取值
|
||||
const (
|
||||
SpeciesCat = "cat"
|
||||
SpeciesDog = "dog"
|
||||
)
|
||||
|
||||
// 模板明细的类别
|
||||
const (
|
||||
CareKindTask = "task" // 今日任务
|
||||
CareKindPlan = "plan" // 30天计划节点
|
||||
CareKindReminder = "reminder" // 提醒
|
||||
)
|
||||
|
||||
// CareTemplate 一套模板 = 一个 (species, stage) 组合
|
||||
type CareTemplate struct {
|
||||
Base
|
||||
Species string `gorm:"size:16;uniqueIndex:idx_species_stage" json:"species"` // cat | dog
|
||||
Stage string `gorm:"size:48;uniqueIndex:idx_species_stage" json:"stage"` // 与 onboarding 阶段一致
|
||||
Items []CareTemplateItem `gorm:"foreignKey:TemplateID" json:"items"`
|
||||
}
|
||||
|
||||
// CareTemplateItem 模板明细,kind 区分三类;不同类只用到部分字段
|
||||
type CareTemplateItem struct {
|
||||
Base
|
||||
TemplateID string `gorm:"size:24;index" json:"template_id"`
|
||||
Kind string `gorm:"size:16;index" json:"kind"` // task | plan | reminder
|
||||
Sort int `json:"sort"`
|
||||
Title string `gorm:"size:128" json:"title"`
|
||||
Description string `gorm:"size:512" json:"description"`
|
||||
|
||||
// task 专用
|
||||
Priority string `gorm:"size:16" json:"priority"` // 重要 / 普通(空)
|
||||
SheetType string `gorm:"size:32" json:"sheet_type"` // 关联记录弹层:weight/poop/food/vaccine...
|
||||
|
||||
// plan 专用
|
||||
Day int `json:"day"` // 第 N 天(0=今天)
|
||||
DayLabel string `gorm:"size:32" json:"day_label"` // 展示标签
|
||||
|
||||
// reminder 专用
|
||||
ReminderType string `gorm:"size:32" json:"reminder_type"` // vaccine/deworm/weight/monthlyReport
|
||||
OffsetDays int `json:"offset_days"` // 到期 = 今天 + N 天;<=0 表示无固定到期,用频率
|
||||
Frequency string `gorm:"size:64" json:"frequency"` // 频率描述,如「每周二、周五」
|
||||
}
|
||||
@@ -3,8 +3,8 @@ package model
|
||||
// Comment 帖子评论
|
||||
type Comment struct {
|
||||
Base
|
||||
PostID uint `gorm:"index" json:"post_id"`
|
||||
UserID uint `gorm:"index" json:"user_id"`
|
||||
PostID string `gorm:"size:24;index" json:"post_id"`
|
||||
UserID string `gorm:"size:24;index" json:"user_id"`
|
||||
AuthorName string `gorm:"size:64" json:"author_name"`
|
||||
Content string `gorm:"size:512" json:"content"`
|
||||
Status string `gorm:"size:16;default:published" json:"status"`
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
package model
|
||||
|
||||
// CommunityBotConfig 社区 AI 运营配置(单例,固定 id=1)
|
||||
type CommunityBotConfig struct {
|
||||
Base
|
||||
Enabled bool `json:"enabled"` // 是否开启每日自动生成
|
||||
DailyCount int `json:"daily_count"` // 每天生成条数
|
||||
StartHour int `json:"start_hour"` // 白天投放窗口起(含)
|
||||
EndHour int `json:"end_hour"` // 白天投放窗口止(不含)
|
||||
}
|
||||
@@ -3,7 +3,7 @@ package model
|
||||
// DailyAdvice 首页「今日建议」每宠每天缓存一条,避免重复调用模型
|
||||
type DailyAdvice struct {
|
||||
Base
|
||||
PetID uint `gorm:"uniqueIndex:idx_pet_day" json:"pet_id"`
|
||||
PetID string `gorm:"size:24;uniqueIndex:idx_pet_day" json:"pet_id"`
|
||||
Day string `gorm:"size:10;uniqueIndex:idx_pet_day" json:"day"` // YYYY-MM-DD
|
||||
Text string `gorm:"type:text" json:"text"`
|
||||
}
|
||||
|
||||
@@ -5,9 +5,9 @@ import "time"
|
||||
// DailyTask 今日任务
|
||||
type DailyTask struct {
|
||||
Base
|
||||
PetID uint `gorm:"index" json:"pet_id"`
|
||||
UserID uint `gorm:"index" json:"user_id"`
|
||||
TaskDate time.Time `gorm:"index" json:"task_date"`
|
||||
PetID string `gorm:"size:24;index" json:"pet_id"`
|
||||
UserID string `gorm:"size:24;index" json:"user_id"`
|
||||
TaskDate time.Time `gorm:"size:24;index" json:"task_date"`
|
||||
Title string `gorm:"size:128" json:"title"`
|
||||
Description string `gorm:"size:512" json:"description"`
|
||||
Priority string `gorm:"size:16" json:"priority"` // "" / 重要
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
package model
|
||||
|
||||
// File 上传文件表:图片/头像等统一入库,按 MD5 去重,使用处以 file_id 关联。
|
||||
type File struct {
|
||||
Base
|
||||
MD5 string `gorm:"size:32;uniqueIndex" json:"md5"` // 内容 MD5,唯一,用于去重
|
||||
ObjectName string `gorm:"size:255" json:"object_name"` // MinIO 对象名
|
||||
URL string `gorm:"size:512" json:"url"` // 可访问 URL
|
||||
Size int64 `json:"size"`
|
||||
ContentType string `gorm:"size:128" json:"content_type"`
|
||||
Ext string `gorm:"size:16" json:"ext"`
|
||||
}
|
||||
@@ -23,8 +23,8 @@ const (
|
||||
// NumValue 存体重/金额,Category 存消费类别/便便状态等,Extra 存各类型专有字段。
|
||||
type HealthRecord struct {
|
||||
Base
|
||||
PetID uint `gorm:"index" json:"pet_id"`
|
||||
UserID uint `gorm:"index" json:"user_id"`
|
||||
PetID string `gorm:"size:24;index" json:"pet_id"`
|
||||
UserID string `gorm:"size:24;index" json:"user_id"`
|
||||
Type string `gorm:"size:16;index" json:"type"`
|
||||
Icon string `gorm:"size:16" json:"icon"`
|
||||
Title string `gorm:"size:128" json:"title"`
|
||||
@@ -32,6 +32,7 @@ type HealthRecord struct {
|
||||
NumValue float64 `gorm:"type:decimal(10,2)" json:"num_value"`
|
||||
Category string `gorm:"size:32" json:"category"`
|
||||
ImageURL string `gorm:"size:512" json:"image_url"`
|
||||
ImageFileID string `gorm:"size:24" json:"image_file_id"` // 关联 files 表:记录附图
|
||||
Extra datatypes.JSON `json:"extra"`
|
||||
OccurredAt time.Time `gorm:"index" json:"occurred_at"`
|
||||
OccurredAt time.Time `gorm:"size:24;index" json:"occurred_at"`
|
||||
}
|
||||
|
||||
@@ -9,9 +9,11 @@ import (
|
||||
// Pet 宠物,属于 User,支持多宠
|
||||
type Pet struct {
|
||||
Base
|
||||
UserID uint `gorm:"index" json:"user_id"`
|
||||
UserID string `gorm:"size:24;index" json:"user_id"`
|
||||
Name string `gorm:"size:64" json:"name"`
|
||||
Emoji string `gorm:"size:16" json:"emoji"`
|
||||
AvatarFileID string `gorm:"size:24" json:"avatar_file_id"` // 关联 files 表:宠物照片
|
||||
AvatarURL string `gorm:"-" json:"avatar_url"` // 计算字段:由 AvatarFileID 解析
|
||||
Type string `gorm:"size:16" json:"type"` // 猫猫 / 狗狗
|
||||
Gender string `gorm:"size:16" json:"gender"` // 男孩 / 女孩 / 不确定
|
||||
Birthday *time.Time `json:"birthday"`
|
||||
|
||||
@@ -15,8 +15,8 @@ const (
|
||||
// Plan 养宠计划(30 天路线图 / AI 计划)
|
||||
type Plan struct {
|
||||
Base
|
||||
PetID uint `gorm:"index" json:"pet_id"`
|
||||
UserID uint `gorm:"index" json:"user_id"`
|
||||
PetID string `gorm:"size:24;index" json:"pet_id"`
|
||||
UserID string `gorm:"size:24;index" json:"user_id"`
|
||||
Kind string `gorm:"size:16;index" json:"kind"` // thirty_day / ai
|
||||
Stage string `gorm:"size:32" json:"stage"`
|
||||
StartDate *time.Time `json:"start_date"`
|
||||
@@ -31,11 +31,12 @@ type Plan struct {
|
||||
// PlanTask 计划明细项
|
||||
type PlanTask struct {
|
||||
Base
|
||||
PlanID uint `gorm:"index" json:"plan_id"`
|
||||
PlanID string `gorm:"size:24;index" json:"plan_id"`
|
||||
Day int `json:"day"`
|
||||
DayLabel string `gorm:"size:32" json:"day_label"`
|
||||
Title string `gorm:"size:128" json:"title"`
|
||||
Description string `gorm:"size:512" json:"description"`
|
||||
SheetType string `gorm:"size:32" json:"sheet_type"`
|
||||
Done bool `json:"done"`
|
||||
Date string `gorm:"-" json:"date"` // 计算字段:计划开始日 + Day
|
||||
}
|
||||
|
||||
@@ -12,15 +12,17 @@ const (
|
||||
// Post 社区帖子
|
||||
type Post struct {
|
||||
Base
|
||||
UserID uint `gorm:"index" json:"user_id"`
|
||||
PetID *uint `json:"pet_id"`
|
||||
UserID string `gorm:"size:24;index" json:"user_id"`
|
||||
PetID *string `gorm:"size:24" json:"pet_id"`
|
||||
AuthorName string `gorm:"size:64" json:"author_name"`
|
||||
AuthorEmoji string `gorm:"size:16" json:"author_emoji"`
|
||||
Identity string `gorm:"size:16" json:"identity"` // petName / anonymous / official
|
||||
Content string `gorm:"type:text" json:"content"`
|
||||
Tags datatypes.JSON `json:"tags"`
|
||||
Images datatypes.JSON `json:"images"`
|
||||
Images datatypes.JSON `json:"images"` // 展示用:URL 数组(真实图)或 emoji 数组(机器人)
|
||||
ImageFileIDs datatypes.JSON `json:"image_file_ids"` // 关联 files 表的 id 数组,读取时解析为 Images
|
||||
LikeCount int `json:"like_count"`
|
||||
CommentCount int `json:"comment_count"`
|
||||
Status string `gorm:"size:16;default:published;index" json:"status"`
|
||||
IsAI bool `gorm:"size:24;index" json:"is_ai"` // AI 运营生成的帖子,前端打「AI」标
|
||||
}
|
||||
|
||||
@@ -3,6 +3,6 @@ package model
|
||||
// PostLike 帖子点赞,(post_id, user_id) 唯一
|
||||
type PostLike struct {
|
||||
Base
|
||||
PostID uint `gorm:"uniqueIndex:idx_post_user" json:"post_id"`
|
||||
UserID uint `gorm:"uniqueIndex:idx_post_user" json:"user_id"`
|
||||
PostID string `gorm:"size:24;uniqueIndex:idx_post_user" json:"post_id"`
|
||||
UserID string `gorm:"size:24;uniqueIndex:idx_post_user" json:"user_id"`
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ const (
|
||||
// ProMembership 会员,1:1 于 User
|
||||
type ProMembership struct {
|
||||
Base
|
||||
UserID uint `gorm:"uniqueIndex" json:"user_id"`
|
||||
UserID string `gorm:"size:24;uniqueIndex" json:"user_id"`
|
||||
Status string `gorm:"size:16;default:none" json:"status"`
|
||||
PlanType string `gorm:"size:16" json:"plan_type"` // yearly / monthly
|
||||
Price float64 `gorm:"type:decimal(10,2)" json:"price"`
|
||||
|
||||
@@ -13,8 +13,8 @@ const (
|
||||
// Reminder 提醒
|
||||
type Reminder struct {
|
||||
Base
|
||||
PetID uint `gorm:"index" json:"pet_id"`
|
||||
UserID uint `gorm:"index" json:"user_id"`
|
||||
PetID string `gorm:"size:24;index" json:"pet_id"`
|
||||
UserID string `gorm:"size:24;index" json:"user_id"`
|
||||
Type string `gorm:"size:24;index" json:"type"`
|
||||
Title string `gorm:"size:128" json:"title"`
|
||||
NextDueDate *time.Time `json:"next_due_date"`
|
||||
|
||||
@@ -4,9 +4,12 @@ package model
|
||||
type User struct {
|
||||
Base
|
||||
OpenID string `gorm:"size:64;index" json:"openid"`
|
||||
Nickname string `gorm:"size:64" json:"nickname"`
|
||||
Avatar string `gorm:"size:512" json:"avatar"`
|
||||
Nickname string `gorm:"size:64" json:"nickname"`
|
||||
Avatar string `gorm:"size:512" json:"avatar"`
|
||||
AvatarFileID string `gorm:"size:24" json:"avatar_file_id"` // 关联 files 表;优先于 Avatar
|
||||
AvatarURL string `gorm:"-" json:"avatar_url"` // 计算字段:由 AvatarFileID 解析
|
||||
Phone string `gorm:"size:32" json:"phone"`
|
||||
Onboarded bool `json:"onboarded"`
|
||||
Disabled bool `json:"disabled"`
|
||||
IsBot bool `gorm:"size:24;index" json:"is_bot"` // 虚拟宠友账号(AI 社区运营用)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user