model

package
v0.0.0-...-9ff475a Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Banner struct {
	Id         int32     `gorm:"primarykey; type:int" json:"id"`
	AddTime    time.Time `gorm:"add_time" json:"add_time"`
	IsDeleted  bool      `gorm:"default:false;not null;comment:'是否删除'" json:"is_deleted"`
	UpdateTime time.Time `gorm:"update_time" json:"update_time"`
	Image      string    `gorm:"type:varchar(200);not null;comment:'图片路径'"`
	Url        string    `gorm:"type:varchar(200);not null;comment:'跳转地址'"`
	Index      int32     `gorm:"type:int;not null;default:1;comment:'排序'"`
}

func (Banner) TableName

func (Banner) TableName() string

type BaseModel

type BaseModel struct {
	// 在数据库中,一个表中的外键如果与另一个表中的主键类型不一致(如int和bigint),那么创建表会出错
	// 两种解决方案,第一种方式是加tag(如type:int/bigint);第二种方式是在struct中设置相同的类型
	Id        int32 `gorm:"primarykey; type:int"` // int32对应mysql中int,int64对应mysql中bigint
	CreatedAt time.Time
	UpdatedAt time.Time
	DeletedAt gorm.DeletedAt `gorm:"index"`
}

type Brand

type Brand struct {
	Id         int32     `gorm:"primarykey; type:int" json:"id"` // int32对应mysql中int,int64对应mysql中bigint
	Name       string    `gorm:"type:varchar(50);not null;comment:'品牌名'"`
	AddTime    time.Time `gorm:"add_time" json:"add_time"`
	IsDeleted  bool      `gorm:"default:false;not null;comment:'是否删除'" json:"is_deleted"`
	UpdateTime time.Time `gorm:"update_time" json:"update_time"`
}

func (Brand) TableName

func (Brand) TableName() string

type Category

type Category struct {
	Id               int32       `gorm:"primarykey; type:int" json:"id"`                      // int32对应mysql中int,int64对应mysql中bigint
	Name             string      `gorm:"type:varchar(20);not null;comment:'分类名'" json:"name"` // 尽量设置为not null
	ParentCategoryId int32       `gorm:"type:int;default:null;comment:'默认级别为1'" json:"parent_category_id"`
	Level            int32       `gorm:"type:int;not null;default:1;comment:'默认级别为1'" json:"level"` // 由于proto中没有int类型,只有int32、int64,为了减少类型转换,所以这里设置为int32
	IsTab            bool        `gorm:"default:false;not null;comment:'是否是tab'" json:"is_tab"`
	Url              string      `gorm:"type:varchar(500);default:url;not null;comment:'url'" json:"url"`
	AddTime          time.Time   `gorm:"add_time" json:"add_time"`
	IsDeleted        bool        `gorm:"default:false;not null;comment:'是否删除'" json:"is_deleted"`
	UpdateTime       time.Time   `gorm:"update_time" json:"update_time"`
	SubCategory      []*Category `gorm:"foreignKey:ParentCategoryId;references:Id" json:"sub_categorys"` // foreignKey: 表示另一个表的外键,references: 表示关联本表的列
}

func (Category) TableName

func (Category) TableName() string

type CategoryBrand

type CategoryBrand struct {
	Id         int32     `gorm:"primarykey; type:int"` // int32对应mysql中int,int64对应mysql中bigint
	CategoryId int32     `gorm:"type:int;index:idx_category_brand,unique;comment:'分类id'"`
	BrandId    int32     `gorm:"type:int;index:idx_category_brand,unique;comment:'品牌id'"`
	AddTime    time.Time `gorm:"add_time" json:"add_time"`
	IsDeleted  bool      `gorm:"default:false;not null;comment:'是否删除'" json:"is_deleted"`
	UpdateTime time.Time `gorm:"update_time" json:"update_time"`

	Category *Category
	Brand    *Brand
}

func (CategoryBrand) TableName

func (CategoryBrand) TableName() string

type EsGoods

type EsGoods struct {
	// json和go文件名都推荐用蛇形命名法
	Id          int32   `json:"id"`
	CategoryId  int32   `json:"category_id"`
	BrandId     int32   `json:"brand_id"`
	OnSale      bool    `json:"on_sale"`
	ShipFree    bool    `json:"ship_free"`
	IsNew       bool    `json:"is_new"`
	IsHot       bool    `json:"is_hot"`
	Name        string  `json:"name"`
	ClickNum    int32   `json:"click_num"`
	SoldNum     int32   `json:"sold_num"`
	FavNum      int32   `json:"fav_num"`
	MarketPrice float32 `json:"market_price"`
	GoodsBrief  string  `json:"goods_brief"`
	ShopPrice   float32 `json:"shop_price"`
}

func (EsGoods) GetIndexName

func (EsGoods) GetIndexName() string

func (EsGoods) GetMapping

func (EsGoods) GetMapping() string

type Goods

type Goods struct {
	Id         int32     `gorm:"primarykey; type:int" json:"id"` // int32对应mysql中int,int64对应mysql中bigint
	AddTime    time.Time `gorm:"add_time" json:"add_time"`
	IsDeleted  bool      `gorm:"default:false;not null;comment:'是否删除'" json:"is_deleted"`
	UpdateTime time.Time `gorm:"update_time" json:"update_time"`
	Category   Category
	CategoryId int32 `gorm:"type:int;not null;comment:'分类id'"`
	Brand      Brand
	BrandId    int32 `gorm:"type:int;not null;comment:'品牌id'"`

	// bool类型数据
	OnSale   bool `gorm:"default:false;not null;comment:'是否上架'"`
	ShipFree bool `gorm:"default:false;not null;comment:'是否包邮'"`
	IsNew    bool `gorm:"default:false;not null;comment:'是否新品'"`
	IsHot    bool `gorm:"default:false;not null;comment:'是否热销'"`

	// string类型数据
	Name       string `gorm:"type:varchar(500);not null;comment:'商品名'"`
	GoodsSn    string `gorm:"type:varchar(50);not null;default:'';comment:'商品编号'"`
	GoodsBrief string `gorm:"type:varchar(100);not null;comment:'商品简介'"`

	// 数值类型数据
	Stocks      int32   `gorm:"type:int;not null;default:0;comment:'库存量'"`
	ClickNum    int32   `gorm:"type:int;not null;default:0;comment:'点击量'"`
	FavNum      int32   `gorm:"type:int;not null;default:0;comment:'收藏量'"`
	SoldNum     int32   `gorm:"type:int;not null;default:0;comment:'销量'"`
	ShopPrice   float32 `gorm:"type:int;not null;default:0;comment:'商品价格'"`
	MarketPrice float32 `gorm:"type:float;not null;default:0;comment:'市场价'"` // float32会自动转换为数据库中的float类型,int类型会转换为bigint

	// 切片类型数据
	Images           commonDB.GormList `gorm:"type:varchar(2000);not null;comment:'商品图片'"`
	DescImages       commonDB.GormList `gorm:"type:varchar(2000);not null;comment:'商品详情图片'"`
	GoodsFrontImages string            `gorm:"type:varchar(200);not null;comment:'商品首页图片'"`
}

func (*Goods) AfterCreate

func (g *Goods) AfterCreate(tx *gorm.DB) error

func (*Goods) AfterDelete

func (g *Goods) AfterDelete(tx *gorm.DB) (err error)

func (*Goods) AfterUpdate

func (g *Goods) AfterUpdate(tx *gorm.DB) (err error)

func (Goods) TableName

func (Goods) TableName() string

type GoodsCategoryBrand

type GoodsCategoryBrand struct {
	BaseModel
	CategoryId int32 `gorm:"type:int;index:idx_category_brand,unique;comment:'分类id'"`
	Category   Category
	BrandId    int32 `gorm:"type:int;index:idx_category_brand,unique;comment:'品牌id'"`
	Brand      Brand
}

func (GoodsCategoryBrand) TableName

func (GoodsCategoryBrand) TableName() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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