diff --git a/structs/storage/article.go b/structs/storage/article.go index a80742d..b2eeaee 100644 --- a/structs/storage/article.go +++ b/structs/storage/article.go @@ -67,7 +67,8 @@ type FindArticleQuery struct { Keyword string `query:"keyword"` Brand v2.Brand `query:"brand"` Pid string `query:"pid"` - Available *bool `query:"available"` + Available *bool `query:"available"` //可购买 + RateSort string `query:"rate_sort,omitempty"` // 收益率排序 } func NewFindArticleQuery() *FindArticleQuery { @@ -94,21 +95,24 @@ func (f *FindArticleQuery) SetAvailable(available bool) *FindArticleQuery { return f } -func (l *FindArticleQuery) Scope(db *gorm.DB) *gorm.DB { - if l.ID != 0 { - db = db.Where("id=?", l.ID) +func (f *FindArticleQuery) Scope(db *gorm.DB) *gorm.DB { + if f.ID != 0 { + db = db.Where("id=?", f.ID) } - if l.Keyword != "" { - db = db.Where("(name ilike ? OR english_name ilike ? OR remark ilike ? )", "%"+l.Keyword+"%", "%"+l.Keyword+"%", "%"+l.Keyword+"%") + if f.Keyword != "" { + db = db.Where("(name ilike ? OR english_name ilike ? OR remark ilike ? OR pid ilike ?)", "%"+f.Keyword+"%", "%"+f.Keyword+"%", "%"+f.Keyword+"%", "%"+f.Keyword+"%") } - if l.Brand != "" { - db = db.Where("brand=?", l.Brand) + if f.Brand != "" { + db = db.Where("brand=?", f.Brand) } - if l.Pid != "" { - db = db.Where("pid=?", l.Pid) + if f.Pid != "" { + db = db.Where("pid=?", f.Pid) } - if l.Available != nil { - db = db.Where("available=?", *l.Available) + if f.Available != nil { + db = db.Where("available=?", *f.Available) + } + if f.RateSort != "" { + db = db.Order("rate " + f.RateSort) } return db } diff --git a/structs/storage/provider-article.go b/structs/storage/provider-article.go index 3896408..b0d3a95 100644 --- a/structs/storage/provider-article.go +++ b/structs/storage/provider-article.go @@ -89,7 +89,7 @@ func (p *providerArticleApi) Get(query *GetProviderArticleQuery) (article v2.Pro func (p *providerArticleApi) Upsert(article v2.ProviderArticle) error { if err := p.db.Clauses(clause.OnConflict{ Columns: []clause.Column{{Name: "provider_id"}, {Name: "sku_id"}}, - DoUpdates: clause.AssignmentColumns([]string{"cost", "available"}), + DoUpdates: clause.AssignmentColumns([]string{"cost", "available", "updated_at"}), }).Create(&article).Error; err != nil { return err } diff --git a/structs/storage/seller-article.go b/structs/storage/seller-article.go index 63a4395..fd38020 100644 --- a/structs/storage/seller-article.go +++ b/structs/storage/seller-article.go @@ -85,7 +85,7 @@ func (p *sellerArticleApi) Get(query *GetSellerArticleQuery) (article v2.SellerA func (p *sellerArticleApi) Upsert(article v2.SellerArticle) error { if err := p.db.Clauses(clause.OnConflict{ Columns: []clause.Column{{Name: "id"}}, - DoUpdates: clause.AssignmentColumns([]string{"sell", "exclude"}), + DoUpdates: clause.AssignmentColumns([]string{"sell", "exclude", "updated_at"}), }).Create(&article).Error; err != nil { return err }