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
57a24bed
authored
Dec 22, 2024
by
borland
Committed by
GitHub
Dec 22, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update user.go
parent
191131b2
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
4 deletions
+9
-4
model/user.go
+9
-4
No files found.
model/user.go
View file @
57a24bed
...
...
@@ -89,13 +89,18 @@ 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
{
...
...
@@ -106,9 +111,9 @@ func SearchUsers(keyword string, group string) ([]*User, error) {
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