Merge pull request #428 from XZFFF/develop

Develop:支持用户名和姓名的多条件模糊搜索,优化搜索结果的展示效果
This commit is contained in:
Minho 2019-01-16 11:28:15 +08:00 committed by GitHub
commit 11634d8c5b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 2 deletions

View File

@ -98,7 +98,8 @@ func (c *SearchController) User() {
c.JsonResult(500, "项目不存在")
}
members, err := models.NewMemberRelationshipResult().FindNotJoinUsersByAccount(book.BookId, 10, "%"+keyword+"%")
//members, err := models.NewMemberRelationshipResult().FindNotJoinUsersByAccount(book.BookId, 10, "%"+keyword+"%")
members, err := models.NewMemberRelationshipResult().FindNotJoinUsersByAccountOrRealName(book.BookId, 10, "%"+keyword+"%")
if err != nil {
beego.Error("查询用户列表出错:" + err.Error())
c.JsonResult(500, err.Error())
@ -109,7 +110,7 @@ func (c *SearchController) User() {
for _, member := range members {
item := models.KeyValueItem{}
item.Id = member.MemberId
item.Text = member.Account
item.Text = member.Account + "[" + member.RealName + "]"
items = append(items, item)
}

View File

@ -108,3 +108,17 @@ func (m *MemberRelationshipResult) FindNotJoinUsersByAccount(bookId, limit int,
return members, err
}
// 根据姓名以及用户名模糊查询指定文档中不存在的用户列表
func (m *MemberRelationshipResult) FindNotJoinUsersByAccountOrRealName(bookId, limit int, keyWord string) ([]*Member, error) {
o := orm.NewOrm()
sql := "SELECT m.* FROM md_members as m LEFT JOIN md_relationship as rel ON rel.member_id = m.member_id AND rel.book_id = ? WHERE rel.relationship_id IS NULL AND (m.real_name LIKE ?) OR (m.account LIKE ?) LIMIT 0,?;"
var members []*Member
_, err := o.Raw(sql, bookId, keyWord,keyWord, limit).QueryRows(&members)
return members, err
}