51 lines
1.4 KiB
Go
51 lines
1.4 KiB
Go
package productmodel
|
||
|
||
import (
|
||
"github.com/qit-team/snow-core/db"
|
||
"sync"
|
||
"time"
|
||
)
|
||
|
||
var (
|
||
once sync.Once
|
||
m *ProductModel
|
||
)
|
||
|
||
// 实体
|
||
type Product struct {
|
||
Id int `xorm:"'id' UNSIGNED BIGINT pk autoincr"`
|
||
Name string `xorm:"'name' varchar(255)"`
|
||
Brand string `xorm:"'brand' varchar(50)"`
|
||
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"`
|
||
ManagerId string `xorm:"'manager_id' UNSIGNED INT"`
|
||
Status string `xorm:"'status' UNSIGNED TINYINT"`
|
||
MainImage string `xorm:"'main_image' varchar(255)"`
|
||
Description string `xorm:"'description' varchar(500)"`
|
||
ThirdProductId int `xorm:"'third_product_Id' int(0)"`
|
||
}
|
||
|
||
// 表名
|
||
func (m *Product) TableName() string {
|
||
return "product"
|
||
}
|
||
|
||
// 私有化,防止被外部new
|
||
type ProductModel struct {
|
||
db.Model //组合基础Model,集成基础Model的属性和方法
|
||
}
|
||
|
||
// 单例模式
|
||
func GetInstance() *ProductModel {
|
||
once.Do(func() {
|
||
m = new(ProductModel)
|
||
//m.DiName = "" //设置数据库实例连接,默认db.SingletonMain
|
||
})
|
||
return m
|
||
}
|