model

package
v0.3.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 29, 2025 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CNYFen  Price = 1
	CNYJiao       = 10 * CNYFen
	CNYYuan       = 10 * CNYJiao
)
View Source
const (
	TimeCompactLayout = "20060102150405"
	TimeDotLayout     = "2006.01.02 15:04:05"
	DateDotLayout     = "2006.01.02"
	DateCompactLayout = "20060102"
	ChineseDateLayout = "2006年01月02日"
	MonthLayout       = "2006-01"
)
View Source
const CstHour int64 = 8 * 3600

CstHour 东八区

View Source
const PriceColor = `#08AF5D`

PriceColor 价格颜色

Variables

This section is empty.

Functions

func Pagination

func Pagination(pagination form.Pagination, order ...string) func(tx *gorm.DB) *gorm.DB

Pagination 分页排序

Types

type Array

type Array[T comparable] []T

func (*Array[T]) Scan

func (a *Array[T]) Scan(v interface{}) error

func (*Array[T]) String

func (a *Array[T]) String() string

func (Array[T]) Value

func (a Array[T]) Value() (driver.Value, error)

type BinaryStatus

type BinaryStatus uint8

BinaryStatus 二元状态 0-否 1-是

const (
	BinaryStatusYes BinaryStatus = 1
	BinaryStatusNo  BinaryStatus = 0
)

func BinaryStatusByBool

func BinaryStatusByBool(status bool) BinaryStatus

func BinaryStatusByUint

func BinaryStatusByUint(status uint8) BinaryStatus

func (BinaryStatus) Bool

func (s BinaryStatus) Bool() bool

func (BinaryStatus) Uint

func (s BinaryStatus) Uint() uint8

type Crypto

type Crypto string

Crypto 加密字段

func (*Crypto) Scan

func (c *Crypto) Scan(v interface{}) error

func (Crypto) String

func (c Crypto) String() string

func (Crypto) Value

func (c Crypto) Value() (driver.Value, error)

type JSON

type JSON json.RawMessage

JSON json数据字段

func (*JSON) Scan

func (j *JSON) Scan(value interface{}) error

func (JSON) Value

func (j JSON) Value() (driver.Value, error)

type JSONDate

type JSONDate struct {
	time.Time
}

JSONDate format json date field by myself

func (JSONDate) MarshalJSON

func (t JSONDate) MarshalJSON() ([]byte, error)

func (*JSONDate) Scan

func (t *JSONDate) Scan(v interface{}) error

Scan valueOf time.Time

func (*JSONDate) UnmarshalJSON

func (t *JSONDate) UnmarshalJSON(data []byte) (err error)

func (JSONDate) Value

func (t JSONDate) Value() (driver.Value, error)

Value insert timestamp into mysql need this function.

type JSONTime

type JSONTime struct {
	time.Time
}

JSONTime format json time field by myself

func (JSONTime) MarshalJSON

func (t JSONTime) MarshalJSON() ([]byte, error)

MarshalJSON on JSONTime format Time field with %Y-%m-%d %H:%M:%S

func (*JSONTime) Scan

func (t *JSONTime) Scan(v interface{}) error

Scan valueOf time.Time

func (*JSONTime) UnmarshalJSON

func (t *JSONTime) UnmarshalJSON(data []byte) (err error)

func (JSONTime) Value

func (t JSONTime) Value() (driver.Value, error)

Value insert timestamp into mysql need this function.

type Percent

type Percent uint

Percent 百分比字段

func DecimalPercent

func DecimalPercent(per float64) Percent

DecimalPercent 根据百分比小数形式创建Percent

func NumericPercent

func NumericPercent(per float64) Percent

NumericPercent 根据百分比形式创建Percent

func (Percent) Decimal

func (p Percent) Decimal() float64

Decimal 换算为小数形式 例如 10%==>0.1

func (Percent) FormatDecimal

func (p Percent) FormatDecimal() string

FormatDecimal 格式化百分比小数 例如 10%==>0.1

func (Percent) FormatInt

func (p Percent) FormatInt() string

FormatInt 格式化整数 例如 10%==>1

func (Percent) FormatNumeric

func (p Percent) FormatNumeric() string

FormatNumeric 格式化百分比 例如 10%==>10

func (Percent) Numeric

func (p Percent) Numeric() float64

Numeric 换算为百分比形式 eg. 10%==>10

func (Percent) Valid

func (p Percent) Valid() bool

type Price

type Price int64

Price 金额字段

func CalculatePricePercent

func CalculatePricePercent(price Price, percent Percent) Price

CalculatePricePercent 计算金额的%

func PriceYuan

func PriceYuan(yuan float64) Price

func (Price) Fen

func (p Price) Fen() int64

func (Price) Format

func (p Price) Format(format string, isThousand bool) string

Format 金额格式化 @param format string 格式 @param isThousand bool 按千分位格式化

func (Price) FormatColor

func (p Price) FormatColor(format, color string, isThousand bool) string

FormatColor 带颜色标签的格式化 @param format string 格式 @param color string 颜色值 @param isThousand bool 按千分位格式化

func (Price) Jiao

func (p Price) Jiao() float64

func (Price) Yuan

func (p Price) Yuan() float64

type PrimaryKeyID

type PrimaryKeyID struct {
	ID uint64 `gorm:"primary_key;autoIncrement" json:"id"`
}

PrimaryKeyID 自增主键ID

type Score

type Score uint8

Score 评分字段

func NewScore

func NewScore(score float32) Score

NewScore 新建评分

func (Score) Format

func (s Score) Format() string

func (Score) FormatFloat

func (s Score) FormatFloat() float32

func (Score) Score

func (s Score) Score() float32

func (Score) Valid

func (s Score) Valid() bool

type SoftDelete

type SoftDelete struct {
	IsDelete   uint8    `gorm:"not null;default:0;comment:删除标识 0-未删除 1-已删除" json:"is_delete"`
	DeleteTime JSONTime `gorm:"type:datetime(0);index;not null" json:"delete_time"`
}

SoftDelete 软删除

type Time

type Time struct {
	CreatedAt JSONTime `gorm:"type:datetime(0);index;not null" json:"created_at,omitempty"`
	UpdatedAt JSONTime `gorm:"type:datetime(0);not null" json:"updated_at,omitempty"`
}

Time 添加时间,修改时间

type Weight

type Weight uint64

Weight 重量(克)

func WeightByKg

func WeightByKg(weight float64) Weight

WeightByKg 以千克创建重量

func WeightByTon

func WeightByTon(weight float64) Weight

WeightByTon 以吨创建重量

func (Weight) FormatKg

func (w Weight) FormatKg(format string) string

func (Weight) FormatTon

func (w Weight) FormatTon(format string) string

func (Weight) Gram

func (w Weight) Gram() uint64

func (Weight) Kg

func (w Weight) Kg() float64

func (Weight) Ton

func (w Weight) Ton() float64

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL