Enhance AI and Redis integration for smoke logging features
- Added AI configuration options to .env.example and config.go for OpenAI integration. - Implemented Redis caching for session management in main.go and auth middleware. - Updated smoke logging service to support real smoking time (`smoke_at`) and AI advice retrieval. - Enhanced API routes to include endpoints for AI advice and unlock functionality for non-members. - Improved database schema with new tables for AI advice and unlock records. - Expanded documentation to cover new AI features and Redis caching implementation.
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// MembershipRedeemCode 存储会员兑换码(只存 hash,不存明文 code)。
|
||||
type MembershipRedeemCode struct {
|
||||
ID uint `gorm:"primarykey" json:"id"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
|
||||
|
||||
// CodeHash 是 code 的 sha256(hex);避免 DB 泄漏导致所有兑换码被直接使用。
|
||||
CodeHash string `gorm:"size:64;uniqueIndex" json:"-"`
|
||||
// CodeSuffix 用于展示/审计(例如最后 6 位)
|
||||
CodeSuffix string `gorm:"size:16;index" json:"code_suffix"`
|
||||
|
||||
Plan string `gorm:"size:30" json:"plan"`
|
||||
DurationDays int `json:"duration_days"`
|
||||
ExpiresAt *time.Time `json:"expires_at,omitempty"`
|
||||
|
||||
MaxUses int `gorm:"default:1" json:"max_uses"`
|
||||
UsedUses int `gorm:"default:0" json:"used_uses"`
|
||||
|
||||
Status string `gorm:"size:20;default:active" json:"status"` // active/disabled
|
||||
}
|
||||
|
||||
func (MembershipRedeemCode) TableName() string {
|
||||
return "membership_redeem_codes"
|
||||
}
|
||||
|
||||
type MembershipRedemption struct {
|
||||
ID uint `gorm:"primarykey" json:"id"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
|
||||
|
||||
MiniProgramID uint `gorm:"index:idx_redeem_user_date,priority:1" json:"mini_program_id"`
|
||||
UserID uint `gorm:"index:idx_redeem_user_date,priority:2" json:"user_id"`
|
||||
|
||||
RedeemCodeID uint `gorm:"index" json:"redeem_code_id"`
|
||||
CodeSuffix string `gorm:"size:16" json:"code_suffix"`
|
||||
|
||||
MembershipID uint `gorm:"index" json:"membership_id"`
|
||||
|
||||
ClientIP string `gorm:"size:64" json:"client_ip,omitempty"`
|
||||
UserAgent string `gorm:"size:255" json:"user_agent,omitempty"`
|
||||
}
|
||||
|
||||
func (MembershipRedemption) TableName() string {
|
||||
return "membership_redemptions"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user