feat: add quit-checkin v2 backend APIs

This commit is contained in:
你çšnepiedg
2026-03-17 00:47:33 +08:00
parent 12619aa4ab
commit 9278260681
11 changed files with 2212 additions and 0 deletions
@@ -0,0 +1,43 @@
package model
import (
"time"
"gorm.io/gorm"
)
// 每日状态枚举值。
const (
DailyStatusPending = "pending"
DailyStatusCheckedIn = "checked_in"
DailyStatusRelapsed = "relapsed"
DailyStatusMissed = "missed"
)
// DailyStatus 表示用户在某一自然日的打卡或复吸状态。
type DailyStatus struct {
ID uint `gorm:"primaryKey;comment:主键" json:"id"`
CreatedAt time.Time `gorm:"comment:创建时间" json:"created_at"`
UpdatedAt time.Time `gorm:"comment:更新时间" json:"updated_at"`
DeletedAt gorm.DeletedAt `gorm:"index;comment:删除时间" json:"-"`
UID int `gorm:"uniqueIndex:idx_quit_checkin_uid_date;comment:用户ID" json:"-"`
Date time.Time `gorm:"uniqueIndex:idx_quit_checkin_uid_date;type:date;comment:自然日" json:"date"`
Status string `gorm:"size:32;index;comment:状态" json:"status"`
CheckInAt *time.Time `gorm:"column:check_in_at;comment:打卡时间" json:"check_in_at,omitempty"`
RelapsedAt *time.Time `gorm:"column:relapsed_at;comment:复吸时间" json:"relapsed_at,omitempty"`
RelapseNum int `gorm:"column:relapse_num;comment:复吸支数" json:"relapse_num"`
Reason string `gorm:"column:reason;size:64;comment:复吸原因" json:"reason,omitempty"`
Note string `gorm:"column:note;size:200;comment:备注" json:"note,omitempty"`
}
// TableName 返回每日状态表名。
func (DailyStatus) TableName() string {
return "fa_quit_checkin_daily_status"
}
// TableComment 返回每日状态表注释。
func (DailyStatus) TableComment() string {
return "V2-无烟打卡-每日状态"
}
+34
View File
@@ -0,0 +1,34 @@
package model
import (
"time"
"gorm.io/gorm"
)
// Profile 表示无烟打卡的基础资料配置。
type Profile struct {
ID uint `gorm:"primaryKey;comment:主键" json:"id"`
CreatedAt time.Time `gorm:"comment:创建时间" json:"created_at"`
UpdatedAt time.Time `gorm:"comment:更新时间" json:"updated_at"`
DeletedAt gorm.DeletedAt `gorm:"index;comment:删除时间" json:"-"`
UID int `gorm:"uniqueIndex;comment:用户ID" json:"-"`
QuitStartDate time.Time `gorm:"column:quit_start_date;type:date;comment:戒烟开始日期" json:"quit_start_date"`
PackPriceCent int `gorm:"column:pack_price_cent;comment:每包价格(分)" json:"pack_price_cent"`
BaselineCigsPerDay int `gorm:"column:baseline_cigs_per_day;comment:戒烟前日均支数" json:"baseline_cigs_per_day"`
Motivation string `gorm:"column:motivation;size:200;comment:戒烟初心" json:"motivation"`
NotifyTime string `gorm:"column:notify_time;size:5;comment:提醒时间(HH:MM)" json:"notify_time"`
ResetRule string `gorm:"column:reset_rule;size:64;comment:连续天数重置规则" json:"reset_rule"`
}
// TableName 返回用户资料表名。
func (Profile) TableName() string {
return "fa_quit_checkin_profile"
}
// TableComment 返回用户资料表注释。
func (Profile) TableComment() string {
return "V2-无烟打卡-用户资料"
}
@@ -0,0 +1,34 @@
package model
import (
"time"
"gorm.io/gorm"
)
// RelapseEvent 表示一次复吸事件明细。
type RelapseEvent struct {
ID uint `gorm:"primaryKey;comment:主键" json:"id"`
CreatedAt time.Time `gorm:"comment:创建时间" json:"created_at"`
UpdatedAt time.Time `gorm:"comment:更新时间" json:"updated_at"`
DeletedAt gorm.DeletedAt `gorm:"index;comment:删除时间" json:"-"`
UID int `gorm:"index;comment:用户ID" json:"-"`
Date time.Time `gorm:"type:date;index;comment:所属自然日" json:"date"`
RelapseAt time.Time `gorm:"column:relapse_at;comment:复吸时间" json:"relapse_at"`
RelapseNum int `gorm:"column:relapse_num;comment:复吸支数" json:"relapse_num"`
Reason string `gorm:"column:reason;size:64;comment:复吸原因" json:"reason,omitempty"`
Note string `gorm:"column:note;size:200;comment:备注" json:"note,omitempty"`
AffectStreak bool `gorm:"column:affect_streak;comment:是否影响连续天数" json:"affect_streak"`
}
// TableName 返回复吸事件表名。
func (RelapseEvent) TableName() string {
return "fa_quit_checkin_relapse_event"
}
// TableComment 返回复吸事件表注释。
func (RelapseEvent) TableComment() string {
return "V2-无烟打卡-复吸事件"
}
+40
View File
@@ -0,0 +1,40 @@
package model
import (
"time"
"gorm.io/gorm"
)
// 梦想目标状态枚举值。
const (
RewardGoalStatusActive = "active"
RewardGoalStatusCompleted = "completed"
RewardGoalStatusArchived = "archived"
)
// RewardGoal 表示用户的梦想奖励目标。
type RewardGoal struct {
ID uint `gorm:"primaryKey;comment:主键" json:"id"`
CreatedAt time.Time `gorm:"comment:创建时间" json:"created_at"`
UpdatedAt time.Time `gorm:"comment:更新时间" json:"updated_at"`
DeletedAt gorm.DeletedAt `gorm:"index;comment:删除时间" json:"-"`
UID int `gorm:"index;comment:用户ID" json:"-"`
Title string `gorm:"column:title;size:64;comment:目标名称" json:"title"`
TargetAmountCent int `gorm:"column:target_amount_cent;comment:目标金额(分)" json:"target_amount_cent"`
CoverImage string `gorm:"column:cover_image;size:500;comment:封面图" json:"cover_image,omitempty"`
Status string `gorm:"column:status;size:32;index;comment:状态" json:"status"`
CompletedAt *time.Time `gorm:"column:completed_at;comment:完成时间" json:"completed_at,omitempty"`
}
// TableName 返回梦想目标表名。
func (RewardGoal) TableName() string {
return "fa_quit_checkin_reward_goal"
}
// TableComment 返回梦想目标表注释。
func (RewardGoal) TableComment() string {
return "V2-无烟打卡-梦想目标"
}