123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126 |
- 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) (*DipSySeries, error)
- SeriesList(db *gorm.DB) ([]DipSySeries, error)
- }
- type DipSySeries 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) (*DipSySeries, error) {
- var res DipSySeries
- err := database.Get(db, &res, database.Option{
- TableName: d.tableName,
- Fields: d.fields,
- })
- return &res, err
- }
- func (d *defalutSySerieModel) SeriesList(db *gorm.DB) ([]DipSySeries, error) {
- var res []DipSySeries
- err := database.List(db, &res, database.Option{
- TableName: d.tableName,
- Fields: d.fields,
- })
- return res, err
- }
|