56 lines
1.5 KiB
Go
56 lines
1.5 KiB
Go
package productsmodel
|
||
|
||
import (
|
||
"github.com/qit-team/snow-core/db"
|
||
"sync"
|
||
"time"
|
||
)
|
||
|
||
var (
|
||
once sync.Once
|
||
m *ProductsModel
|
||
)
|
||
|
||
// 实体
|
||
type Products struct {
|
||
Id string `xorm:"'id' UNSIGNED BIGINT pk autoincr"`
|
||
Name string `xorm:"'name' varchar(255)"`
|
||
MainImage string `xorm:"'main_image' varchar(255)"`
|
||
Brand string `xorm:"'brand' varchar(100)"`
|
||
BrandId int `xorm:"'brand_id' int(10)"`
|
||
Stock string `xorm:"'stock' UNSIGNED INT"`
|
||
ShowPrice string `xorm:"'show_price' decimal(10,2)"`
|
||
Price string `xorm:"'price' decimal(10,2)"`
|
||
Type string `xorm:"'type' UNSIGNED TINYINT"`
|
||
CreateTime time.Time `xorm:"'create_time' datetime"`
|
||
UpdateTime time.Time `xorm:"'update_time' datetime"`
|
||
Deleted time.Time `xorm:"'Deleted' datetime"`
|
||
Status string `xorm:"'status' UNSIGNED TINYINT"`
|
||
Description string `xorm:"'description' varchar(500)"`
|
||
ThirdProductId int `xorm:"'third_product_Id' int(0)"`
|
||
}
|
||
|
||
type MilkProductsList struct {
|
||
Products `xorm:"extends"`
|
||
Flag string `xorm:"'flag' varchar(50)"`
|
||
}
|
||
|
||
// 表名
|
||
func (m *Products) TableName() string {
|
||
return "Products"
|
||
}
|
||
|
||
// 私有化,防止被外部new
|
||
type ProductsModel struct {
|
||
db.Model //组合基础Model,集成基础Model的属性和方法
|
||
}
|
||
|
||
// 单例模式
|
||
func GetInstance() *ProductsModel {
|
||
once.Do(func() {
|
||
m = new(ProductsModel)
|
||
//m.DiName = "" //设置数据库实例连接,默认db.SingletonMain
|
||
})
|
||
return m
|
||
}
|