Skip to content

Commit

Permalink
表达式+相等过滤操作
Browse files Browse the repository at this point in the history
  • Loading branch information
hulutech-web committed Oct 11, 2024
1 parent 594ad86 commit 71ec348
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions paginator.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"github.com/goravel/framework/contracts/http"
"github.com/goravel/framework/facades"
"github.com/spf13/cast"
"gorm.io/gorm"
"math"
"strconv"
)
Expand Down Expand Up @@ -37,17 +38,18 @@ func (h *HttpResult) SearchByParams(params map[string]string, conditionMap map[s
delete(params, except)
}
query := facades.Orm().Query()
for key, val := range conditionMap {
query = query.Raw(key+" = ?", val).(orm.Query)
}

// 再处理url查询
h.Query = func(q orm.Query) orm.Query {
// 先处理过滤条件
for key, val := range conditionMap {
q = q.Where(key+" = ?", val).(orm.Query)
}
for key, value := range params {
if value == "" || key == "pageSize" || key == "total" || key == "currentPage" || key == "sort" || key == "order" {
continue
} else {
//q:=gorm.Expr(key+" like ?", "%"+value+"%")
//q = q.Where(key+" like ?", "%"+value+"%")
q = q.Raw(key+" like ?", "%"+value+"%").(orm.Query)
q = q.Where(key, gorm.Expr(" like ? %"+value+"%"))
}
}
return q
Expand Down

0 comments on commit 71ec348

Please sign in to comment.