feat 添加keyword筛选

This commit is contained in:
timerzz 2024-11-30 14:43:01 +08:00
parent 50b9ed22ad
commit cd385c31e7

View File

@ -38,6 +38,7 @@ type GetProviderArticleQuery struct {
SkuId string `query:"skuId"`
WatchNotNull bool `query:"watchNotNull"`
Watch *bool `query:"watch"`
Keyword string `query:"keyword"`
}
func NewGetProviderArticleQuery() *GetProviderArticleQuery {
@ -77,6 +78,11 @@ func (g *GetProviderArticleQuery) SetWatchNotNull(watchNotNull bool) *GetProvide
return g
}
func (g *GetProviderArticleQuery) SetKeyword(keyword string) *GetProviderArticleQuery {
g.Keyword = keyword
return g
}
func (g *GetProviderArticleQuery) Scope(db *gorm.DB) *gorm.DB {
if g.ID > 0 {
db = db.Where("id=?", g.ID)
@ -99,6 +105,9 @@ func (g *GetProviderArticleQuery) Scope(db *gorm.DB) *gorm.DB {
if g.Watch != nil {
db = db.Where("watch=?", *g.Watch)
}
if g.Keyword != "" {
db = db.Where("(name ilike ? or sku_id ilike ?)", "%"+g.Keyword+"%", "%"+g.Keyword+"%")
}
return db
}