init: 毛孩子计划 小程序 + Go 后端 + 内嵌后台
- pets-fe: 微信原生小程序(首页/计划/记录/报告/社区/引导), 服务端驱动、无假数据;弹层改用 scroll-view,打开时隐藏自定义 tabBar - pets-be: Gin + GORM(MySQL, sundynix_ 前缀) + MinIO,统一响应/分页, 微信 code2session 登录,provider-neutral AI(DeepSeek),go:embed React 后台 - 修复:分段选择类型不匹配(字符串 vs 数字)导致选不中 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
package model
|
||||
|
||||
// Admin 后台管理员
|
||||
type Admin struct {
|
||||
Base
|
||||
Username string `gorm:"size:64;uniqueIndex" json:"username"`
|
||||
PasswordHash string `gorm:"size:128" json:"-"`
|
||||
Role string `gorm:"size:32;default:admin" json:"role"`
|
||||
Disabled bool `json:"disabled"`
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package model
|
||||
|
||||
// AIMessage AI 聊天消息
|
||||
type AIMessage struct {
|
||||
Base
|
||||
UserID uint `gorm:"index" json:"user_id"`
|
||||
PetID *uint `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"`
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package model
|
||||
|
||||
// Article 新手知识文章
|
||||
type Article struct {
|
||||
Base
|
||||
Icon string `gorm:"size:16" json:"icon"`
|
||||
Title string `gorm:"size:128" json:"title"`
|
||||
Description string `gorm:"size:512" json:"description"`
|
||||
Content string `gorm:"type:text" json:"content"`
|
||||
Category string `gorm:"size:32" json:"category"`
|
||||
RelatedSheetType string `gorm:"size:32" json:"related_sheet_type"`
|
||||
Published bool `gorm:"default:true" json:"published"`
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package model
|
||||
|
||||
import "time"
|
||||
|
||||
// Base 所有模型的公共字段
|
||||
type Base struct {
|
||||
ID uint `gorm:"primarykey" json:"id"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
}
|
||||
|
||||
// AllModels 需要 AutoMigrate 的模型清单(按依赖顺序)
|
||||
func AllModels() []any {
|
||||
return []any{
|
||||
&User{},
|
||||
&Pet{},
|
||||
&HealthRecord{},
|
||||
&DailyTask{},
|
||||
&Plan{},
|
||||
&PlanTask{},
|
||||
&Reminder{},
|
||||
&Post{},
|
||||
&Comment{},
|
||||
&PostLike{},
|
||||
&Article{},
|
||||
&AIMessage{},
|
||||
&ProMembership{},
|
||||
&Admin{},
|
||||
&DailyAdvice{},
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package model
|
||||
|
||||
// Comment 帖子评论
|
||||
type Comment struct {
|
||||
Base
|
||||
PostID uint `gorm:"index" json:"post_id"`
|
||||
UserID uint `gorm:"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,9 @@
|
||||
package model
|
||||
|
||||
// DailyAdvice 首页「今日建议」每宠每天缓存一条,避免重复调用模型
|
||||
type DailyAdvice struct {
|
||||
Base
|
||||
PetID uint `gorm:"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"`
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package model
|
||||
|
||||
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"`
|
||||
Title string `gorm:"size:128" json:"title"`
|
||||
Description string `gorm:"size:512" json:"description"`
|
||||
Priority string `gorm:"size:16" json:"priority"` // "" / 重要
|
||||
SheetType string `gorm:"size:32" json:"sheet_type"` // 点击打开的弹层类型
|
||||
Done bool `json:"done"`
|
||||
CompletedAt *time.Time `json:"completed_at"`
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"gorm.io/datatypes"
|
||||
)
|
||||
|
||||
// 健康记录类型
|
||||
const (
|
||||
RecordWeight = "weight"
|
||||
RecordPoop = "poop"
|
||||
RecordFood = "food"
|
||||
RecordSymptom = "symptom"
|
||||
RecordMedicine = "medicine"
|
||||
RecordVaccine = "vaccine"
|
||||
RecordDeworm = "deworm"
|
||||
RecordCost = "cost"
|
||||
RecordPhoto = "photo"
|
||||
)
|
||||
|
||||
// HealthRecord 统一健康/时间轴记录表,type 区分 9 类。
|
||||
// NumValue 存体重/金额,Category 存消费类别/便便状态等,Extra 存各类型专有字段。
|
||||
type HealthRecord struct {
|
||||
Base
|
||||
PetID uint `gorm:"index" json:"pet_id"`
|
||||
UserID uint `gorm:"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"`
|
||||
Description string `gorm:"size:512" json:"description"`
|
||||
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"`
|
||||
Extra datatypes.JSON `json:"extra"`
|
||||
OccurredAt time.Time `gorm:"index" json:"occurred_at"`
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"gorm.io/datatypes"
|
||||
)
|
||||
|
||||
// Pet 宠物,属于 User,支持多宠
|
||||
type Pet struct {
|
||||
Base
|
||||
UserID uint `gorm:"index" json:"user_id"`
|
||||
Name string `gorm:"size:64" json:"name"`
|
||||
Emoji string `gorm:"size:16" json:"emoji"`
|
||||
Type string `gorm:"size:16" json:"type"` // 猫猫 / 狗狗
|
||||
Gender string `gorm:"size:16" json:"gender"` // 男孩 / 女孩 / 不确定
|
||||
Birthday *time.Time `json:"birthday"`
|
||||
Weight string `gorm:"size:16" json:"weight"` // 如 "2.8kg"
|
||||
Stage string `gorm:"size:32" json:"stage"` // 刚到家 0-30 天 / 幼年期 / 成年期 / 老年期
|
||||
Age string `gorm:"size:32" json:"age"`
|
||||
Color string `gorm:"size:32" json:"color"` // 毛色,如 橘白 / 奶牛
|
||||
Breed string `gorm:"size:64" json:"breed"` // 品种
|
||||
HealthStatus string `gorm:"size:16;default:正常" json:"health_status"`
|
||||
Goals datatypes.JSON `json:"goals"` // onboarding 目标多选
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"gorm.io/datatypes"
|
||||
)
|
||||
|
||||
// 计划类型
|
||||
const (
|
||||
PlanThirtyDay = "thirty_day"
|
||||
PlanAI = "ai"
|
||||
)
|
||||
|
||||
// Plan 养宠计划(30 天路线图 / AI 计划)
|
||||
type Plan struct {
|
||||
Base
|
||||
PetID uint `gorm:"index" json:"pet_id"`
|
||||
UserID uint `gorm:"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"`
|
||||
EndDate *time.Time `json:"end_date"`
|
||||
UserInput string `gorm:"size:512" json:"user_input"`
|
||||
Extracted datatypes.JSON `json:"extracted"` // AI 提取信息
|
||||
CompletionPct int `json:"completion_pct"`
|
||||
Status string `gorm:"size:16;default:active" json:"status"` // active / completed / archived
|
||||
Tasks []PlanTask `gorm:"foreignKey:PlanID" json:"tasks"`
|
||||
}
|
||||
|
||||
// PlanTask 计划明细项
|
||||
type PlanTask struct {
|
||||
Base
|
||||
PlanID uint `gorm:"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"`
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package model
|
||||
|
||||
import "gorm.io/datatypes"
|
||||
|
||||
// 帖子状态
|
||||
const (
|
||||
PostPublished = "published"
|
||||
PostHidden = "hidden"
|
||||
PostDeleted = "deleted"
|
||||
)
|
||||
|
||||
// Post 社区帖子
|
||||
type Post struct {
|
||||
Base
|
||||
UserID uint `gorm:"index" json:"user_id"`
|
||||
PetID *uint `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"`
|
||||
LikeCount int `json:"like_count"`
|
||||
CommentCount int `json:"comment_count"`
|
||||
Status string `gorm:"size:16;default:published;index" json:"status"`
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
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"`
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package model
|
||||
|
||||
import "time"
|
||||
|
||||
// Pro 会员状态
|
||||
const (
|
||||
ProActive = "active"
|
||||
ProExpired = "expired"
|
||||
ProNone = "none"
|
||||
)
|
||||
|
||||
// ProMembership 会员,1:1 于 User
|
||||
type ProMembership struct {
|
||||
Base
|
||||
UserID uint `gorm:"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"`
|
||||
StartDate *time.Time `json:"start_date"`
|
||||
EndDate *time.Time `json:"end_date"`
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package model
|
||||
|
||||
import "time"
|
||||
|
||||
// 提醒类型
|
||||
const (
|
||||
ReminderVaccine = "vaccine"
|
||||
ReminderDeworm = "deworm"
|
||||
ReminderWeight = "weight"
|
||||
ReminderMonthlyReport = "monthlyReport"
|
||||
)
|
||||
|
||||
// Reminder 提醒
|
||||
type Reminder struct {
|
||||
Base
|
||||
PetID uint `gorm:"index" json:"pet_id"`
|
||||
UserID uint `gorm:"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"`
|
||||
Frequency string `gorm:"size:64" json:"frequency"`
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package model
|
||||
|
||||
// User 小程序用户(铲屎官)
|
||||
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"`
|
||||
Phone string `gorm:"size:32" json:"phone"`
|
||||
Onboarded bool `json:"onboarded"`
|
||||
Disabled bool `json:"disabled"`
|
||||
}
|
||||
Reference in New Issue
Block a user