feat 添加keyword筛选
This commit is contained in:
parent
50b9ed22ad
commit
cd385c31e7
@ -38,6 +38,7 @@ type GetProviderArticleQuery struct {
|
|||||||
SkuId string `query:"skuId"`
|
SkuId string `query:"skuId"`
|
||||||
WatchNotNull bool `query:"watchNotNull"`
|
WatchNotNull bool `query:"watchNotNull"`
|
||||||
Watch *bool `query:"watch"`
|
Watch *bool `query:"watch"`
|
||||||
|
Keyword string `query:"keyword"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewGetProviderArticleQuery() *GetProviderArticleQuery {
|
func NewGetProviderArticleQuery() *GetProviderArticleQuery {
|
||||||
@ -77,6 +78,11 @@ func (g *GetProviderArticleQuery) SetWatchNotNull(watchNotNull bool) *GetProvide
|
|||||||
return g
|
return g
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (g *GetProviderArticleQuery) SetKeyword(keyword string) *GetProviderArticleQuery {
|
||||||
|
g.Keyword = keyword
|
||||||
|
return g
|
||||||
|
}
|
||||||
|
|
||||||
func (g *GetProviderArticleQuery) Scope(db *gorm.DB) *gorm.DB {
|
func (g *GetProviderArticleQuery) Scope(db *gorm.DB) *gorm.DB {
|
||||||
if g.ID > 0 {
|
if g.ID > 0 {
|
||||||
db = db.Where("id=?", g.ID)
|
db = db.Where("id=?", g.ID)
|
||||||
@ -99,6 +105,9 @@ func (g *GetProviderArticleQuery) Scope(db *gorm.DB) *gorm.DB {
|
|||||||
if g.Watch != nil {
|
if g.Watch != nil {
|
||||||
db = db.Where("watch=?", *g.Watch)
|
db = db.Where("watch=?", *g.Watch)
|
||||||
}
|
}
|
||||||
|
if g.Keyword != "" {
|
||||||
|
db = db.Where("(name ilike ? or sku_id ilike ?)", "%"+g.Keyword+"%", "%"+g.Keyword+"%")
|
||||||
|
}
|
||||||
return db
|
return db
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user