package model import ( "git.getensh.com/common/gopkgsv2/database" "gorm.io/gorm" ) type SySeriesModel interface { MakerList(db *gorm.DB) ([]Maker, error) Update(db *gorm.DB, values interface{}) error Count(db *gorm.DB, join bool) (int64, error) List(db *gorm.DB, pagination *Pagination, join bool) ([]SeriesAndBrandName, error) Get(db *gorm.DB) (*GdSySeries, error) SeriesList(db *gorm.DB) ([]GdSySeries, error) } type GdSySeries struct { ID int64 `gorm:"column:id" json:"id" form:"id"` SeriesId string `gorm:"column:series_id" json:"series_id" form:"series_id"` BrandId string `gorm:"column:brand_id" json:"brand_id" form:"brand_id"` SeriesName string `gorm:"column:series_name" json:"series_name" form:"series_name"` Maker string `gorm:"column:maker" json:"maker" form:"maker"` MakerId string `gorm:"column:maker_id" json:"maker_id" form:"maker_id"` LowestPrice string `gorm:"column:lowest_price" json:"lowest_price" form:"lowest_price"` HighestPrice string `gorm:"column:highest_price" json:"highest_price" form:"highest_price"` HasImg int64 `gorm:"column:has_img" json:"has_img" form:"has_img"` UpdateTime string `gorm:"column:update_time" json:"update_time" form:"update_time"` Status int64 `gorm:"column:status" json:"status"` } type SeriesAndBrandName struct { ID int64 `gorm:"column:id" json:"id" form:"id"` SeriesId string `gorm:"column:series_id" json:"series_id" form:"series_id"` SeriesName string `gorm:"column:series_name" json:"series_name" form:"series_name"` BrandId string `gorm:"column:brand_id" json:"brand_id" form:"brand_id"` BrandName string `gorm:"column:brand_name" json:"brand_name" form:"brand_name"` Maker string `gorm:"column:maker" json:"maker" form:"maker"` HasImg int64 `gorm:"column:has_img" json:"has_img" form:"has_img"` Status int64 `gorm:"column:status" json:"status"` } type Maker struct { BrandId string `gorm:"column:brand_id" json:"brand_id" form:"brand_id"` Maker string `gorm:"column:maker" json:"maker" form:"maker"` MakerId string `gorm:"column:maker_id" json:"maker_id" form:"maker_id"` } type defalutSySerieModel struct { tableName string fields string } func NewSySerieModel() SySeriesModel { return &defalutSySerieModel{ tableName: "db_adm_ads.t_adm_ads4", fields: "id, series_id,series_name, brand_id, maker, maker_id, lowest_price, highest_price, has_img, update_time", } } func (d *defalutSySerieModel) MakerList(db *gorm.DB) ([]Maker, error) { var res []Maker err := database.List(db, &res, database.Option{ TableName: d.tableName, Fields: "brand_id, maker, maker_id", Group: "maker", }) return res, err } func (d *defalutSySerieModel) Update(db *gorm.DB, values interface{}) error { return database.Update(db, values, database.Option{ TableName: d.tableName, }) } func (d *defalutSySerieModel) List(db *gorm.DB, pagination *Pagination, join bool) ([]SeriesAndBrandName, error) { var res []SeriesAndBrandName option := database.Option{ TableName: d.tableName + " AS t1", Joins: []string{"LEFT JOIN db_adm_ads.t_adm_ads2 AS t2 ON t1.brand_id = t2.brand_id"}, Fields: "t1.id, t1.series_id, t1.series_name, t1.maker, t1.status, t1.has_img, t2.brand_name, t1.brand_id", Limit: pagination.Limit, OffSet: pagination.Offset, } if join { option.Joins = []string{} } err := database.List(db, &res, option) return res, err } func (d *defalutSySerieModel) Count(db *gorm.DB, join bool) (int64, error) { option := database.Option{ TableName: d.tableName + " AS t1", } if join { option.Joins = []string{"LEFT JOIN db_adm_ads.t_adm_ads2 AS t2 ON t1.brand_id = t2.brand_id"} } return database.Count(db, option) } func (d *defalutSySerieModel) Get(db *gorm.DB) (*GdSySeries, error) { var res GdSySeries err := database.Get(db, &res, database.Option{ TableName: d.tableName, Fields: d.fields, }) return &res, err } func (d *defalutSySerieModel) SeriesList(db *gorm.DB) ([]GdSySeries, error) { var res []GdSySeries err := database.List(db, &res, database.Option{ TableName: d.tableName, Fields: d.fields, }) return res, err }