Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
phsl
/
new-api
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
9e6d0b2a
authored
Dec 22, 2024
by
Calcium-Ion
Committed by
GitHub
Dec 22, 2024
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #648 from palboss/main
解决 #534 用户管理-管理用户-查询报错 (SQLSTATE 42601)-postgresql
parents
7d0f26c9
ad15c0cb
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
5 deletions
+10
-5
model/user.go
+10
-5
No files found.
model/user.go
View file @
9e6d0b2a
...
...
@@ -89,26 +89,31 @@ func SearchUsers(keyword string, group string) ([]*User, error) {
var
users
[]
*
User
var
err
error
groupCol
:=
"`group`"
if
common
.
UsingPostgreSQL
{
groupCol
=
`"group"`
}
// 尝试将关键字转换为整数ID
keywordInt
,
err
:=
strconv
.
Atoi
(
keyword
)
if
err
==
nil
{
// 如果转换成功,按照ID和可选的组别搜索用户
query
:=
DB
.
Unscoped
()
.
Omit
(
"password"
)
.
Where
(
"
`id`
= ?"
,
keywordInt
)
query
:=
DB
.
Unscoped
()
.
Omit
(
"password"
)
.
Where
(
"
id
= ?"
,
keywordInt
)
if
group
!=
""
{
query
=
query
.
Where
(
"`group`
= ?"
,
group
)
// 使用反引号包围group
query
=
query
.
Where
(
groupCol
+
"
= ?"
,
group
)
// 使用反引号包围group
}
err
=
query
.
Find
(
&
users
)
.
Error
if
err
!=
nil
||
len
(
users
)
>
0
{
return
users
,
err
}
}
err
=
nil
query
:=
DB
.
Unscoped
()
.
Omit
(
"password"
)
likeCondition
:=
"
`username` LIKE ? OR `email` LIKE ? OR `display_name`
LIKE ?"
likeCondition
:=
"
username LIKE ? OR email LIKE ? OR display_name
LIKE ?"
if
group
!=
""
{
query
=
query
.
Where
(
"("
+
likeCondition
+
") AND
`group`
= ?"
,
"%"
+
keyword
+
"%"
,
"%"
+
keyword
+
"%"
,
"%"
+
keyword
+
"%"
,
group
)
query
=
query
.
Where
(
"("
+
likeCondition
+
") AND
"
+
groupCol
+
"
= ?"
,
"%"
+
keyword
+
"%"
,
"%"
+
keyword
+
"%"
,
"%"
+
keyword
+
"%"
,
group
)
}
else
{
query
=
query
.
Where
(
likeCondition
,
"%"
+
keyword
+
"%"
,
"%"
+
keyword
+
"%"
,
"%"
+
keyword
+
"%"
)
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment