31ea370cea
- 修复 JWTConfig 缺少 mapstructure tag 导致 access_expire_min 解析为 0, token 签发即过期,所有 API 请求返回 401 - 全部 config struct 补齐 mapstructure tag(secret/dsn/hmac_secret 等) - 模型层从 hotel/HotelID 统一重命名为 shop/ShopID - 删除旧 migrations(001-004),新增 001_init 综合迁移文件 - 更新 schema.sql、testutil、handler/service/model 相关引用 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
51 lines
968 B
Go
51 lines
968 B
Go
package model
|
|
|
|
import (
|
|
"database/sql/driver"
|
|
"encoding/json"
|
|
"fmt"
|
|
"time"
|
|
)
|
|
|
|
// JSON 类型,用于 custom_fields
|
|
type JSON map[string]interface{}
|
|
|
|
func (j JSON) Value() (driver.Value, error) {
|
|
if j == nil {
|
|
return nil, nil
|
|
}
|
|
b, err := json.Marshal(j)
|
|
return string(b), err
|
|
}
|
|
|
|
func (j *JSON) Scan(value interface{}) error {
|
|
if value == nil {
|
|
*j = nil
|
|
return nil
|
|
}
|
|
var bytes []byte
|
|
switch v := value.(type) {
|
|
case string:
|
|
bytes = []byte(v)
|
|
case []byte:
|
|
bytes = v
|
|
default:
|
|
return fmt.Errorf("cannot scan type %T into JSON", value)
|
|
}
|
|
return json.Unmarshal(bytes, j)
|
|
}
|
|
|
|
// Base 公共字段
|
|
type Base struct {
|
|
ID uint64 `gorm:"primaryKey;autoIncrement" json:"id"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
UpdatedAt time.Time `json:"updated_at"`
|
|
DeletedAt *time.Time `gorm:"index" json:"-"`
|
|
}
|
|
|
|
// TenantBase 含租户隔离的公共字段
|
|
type TenantBase struct {
|
|
Base
|
|
ShopID uint64 `gorm:"not null;index" json:"shop_id"`
|
|
}
|