Files
soul-yongping/soul-api/internal/model/user_rule.go
2026-03-24 01:22:50 +08:00

41 lines
1.5 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package model
import (
"database/sql/driver"
"time"
)
// RuleJSON 存储 JSON 数组/对象的列user_rules 的 trigger_conditions 等)
type RuleJSON []byte
func (r RuleJSON) Value() (driver.Value, error) { return []byte(r), nil }
func (r *RuleJSON) Scan(value interface{}) error {
if value == nil {
*r = nil
return nil
}
b, ok := value.([]byte)
if !ok {
return nil
}
*r = append((*r)[0:0], b...)
return nil
}
// UserRule 用户旅程触达规则(结构化触发条件 + 推送动作,由管理端配置)
type UserRule struct {
ID uint `gorm:"column:id;primaryKey;autoIncrement" json:"id"`
Title string `gorm:"column:title;size:200;not null" json:"title"`
Description string `gorm:"column:description;type:text" json:"description"`
Trigger string `gorm:"column:trigger;size:100" json:"trigger"`
TriggerConditions RuleJSON `gorm:"column:trigger_conditions;type:json" json:"triggerConditions,omitempty"`
ActionType string `gorm:"column:action_type;size:50;default:'popup'" json:"actionType,omitempty"`
ActionConfig RuleJSON `gorm:"column:action_config;type:json" json:"actionConfig,omitempty"`
Sort int `gorm:"column:sort;default:0" json:"sort"`
Enabled bool `gorm:"column:enabled;default:true" json:"enabled"`
CreatedAt time.Time `gorm:"column:created_at" json:"createdAt"`
UpdatedAt time.Time `gorm:"column:updated_at" json:"updatedAt"`
}
func (UserRule) TableName() string { return "user_rules" }