fix 修复查询时的`bug

This commit is contained in:
timerzz 2024-09-01 18:59:24 +08:00
parent e82ee959ed
commit 1290c1e1fd

View File

@ -68,19 +68,19 @@ func (f *FindArticleQuery) SetAvailable(available bool) *FindArticleQuery {
func (l *FindArticleQuery) Scope(db *gorm.DB) *gorm.DB {
if l.ID != 0 {
db = db.Where("`id`=?", l.ID)
db = db.Where("id=?", l.ID)
}
if l.Keyword != "" {
db = db.Where("(`name` ilike ? OR `english_name ilike ? OR `remark` ilike ? )", "%"+l.Keyword+"%", "%"+l.Keyword+"%", "%"+l.Keyword+"%")
db = db.Where("(name ilike ? OR english_name ilike ? OR remark ilike ? )", "%"+l.Keyword+"%", "%"+l.Keyword+"%", "%"+l.Keyword+"%")
}
if l.Brand != "" {
db = db.Where("`brand`=?", l.Brand)
db = db.Where("brand=?", l.Brand)
}
if l.Pid != "" {
db = db.Where("`pid`=?", l.Pid)
db = db.Where("pid=?", l.Pid)
}
if l.Available != nil {
db = db.Where("`available`=?", *l.Available)
db = db.Where("available=?", *l.Available)
}
return db
}
@ -133,13 +133,13 @@ func NewGetArticleQuery() *GetArticleQuery {
func (g *GetArticleQuery) Scope(db *gorm.DB) *gorm.DB {
db = db.Preload("Providers").Preload("Sellers")
if g.ID != 0 {
db = db.Where("`id`=?", g.ID)
db = db.Where("id=?", g.ID)
}
if g.Brand != "" {
db = db.Where("`brand`=?", g.Brand)
db = db.Where("brand=?", g.Brand)
}
if g.Pid != "" {
db = db.Where("`pid`=?", g.Pid)
db = db.Where("pid=?", g.Pid)
}
if g.History {
db = db.Preload("Providers.HistoryPrice").Preload("Sellers.HistoryPrice")