From a4b95cb7cf3ead39de6f5c03e284f3a6360da1c8 Mon Sep 17 00:00:00 2001 From: wangchuxiao Date: Tue, 30 Aug 2022 23:23:53 +0800 Subject: [PATCH] cms --- pkg/common/db/mysql_model/im_mysql_model/group_model.go | 4 ++-- pkg/common/db/mysql_model/im_mysql_model/user_model.go | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/pkg/common/db/mysql_model/im_mysql_model/group_model.go b/pkg/common/db/mysql_model/im_mysql_model/group_model.go index 2def46596..ccf317ff4 100644 --- a/pkg/common/db/mysql_model/im_mysql_model/group_model.go +++ b/pkg/common/db/mysql_model/im_mysql_model/group_model.go @@ -54,7 +54,7 @@ type GroupWithNum struct { func GetGroupsByName(groupName string, pageNumber, showNumber int32) ([]GroupWithNum, error) { var groups []GroupWithNum err := db.DB.MysqlDB.DefaultGormDB().Table("groups").Select("groups.*, (select count(*) from group_members where group_members.group_id=groups.group_id) as num"). - Where(fmt.Sprintf(" name like '%%%s%%' ", groupName)).Limit(int(showNumber)).Offset(int(showNumber * (pageNumber - 1))).Find(&groups).Error + Where(" name like ? ", fmt.Sprintf("%%%s%%", groupName)).Limit(int(showNumber)).Offset(int(showNumber * (pageNumber - 1))).Find(&groups).Error return groups, err } @@ -80,7 +80,7 @@ func OperateGroupStatus(groupId string, groupStatus int32) error { func GetGroupsCountNum(group db.Group) (int32, error) { var count int64 - if err := db.DB.MysqlDB.DefaultGormDB().Table("groups").Where(" name like '%%%s%%' ", group.GroupName).Count(&count).Error; err != nil { + if err := db.DB.MysqlDB.DefaultGormDB().Table("groups").Where(" name like ? ", fmt.Sprintf("%%%s%%", group.GroupName)).Count(&count).Error; err != nil { return 0, err } return int32(count), nil diff --git a/pkg/common/db/mysql_model/im_mysql_model/user_model.go b/pkg/common/db/mysql_model/im_mysql_model/user_model.go index 1a53e8eac..cb9322ea0 100644 --- a/pkg/common/db/mysql_model/im_mysql_model/user_model.go +++ b/pkg/common/db/mysql_model/im_mysql_model/user_model.go @@ -254,13 +254,13 @@ func GetBlockUsers(showNumber, pageNumber int32) ([]BlockUserInfo, error) { func GetUserByName(userName string, showNumber, pageNumber int32) ([]db.User, error) { var users []db.User - err := db.DB.MysqlDB.DefaultGormDB().Table("users").Where(" name like %?%", userName).Limit(int(showNumber)).Offset(int(showNumber * (pageNumber - 1))).Find(&users).Error + err := db.DB.MysqlDB.DefaultGormDB().Table("users").Where(" name like ?", fmt.Sprintf("%%%s%%", userName)).Limit(int(showNumber)).Offset(int(showNumber * (pageNumber - 1))).Find(&users).Error return users, err } -func GetUsersCount(nickname string) (int32, error) { +func GetUsersCount(userName string) (int32, error) { var count int64 - if err := db.DB.MysqlDB.DefaultGormDB().Table("users").Where(" name like '%%%s%%' ", nickname).Count(&count).Error; err != nil { + if err := db.DB.MysqlDB.DefaultGormDB().Table("users").Where(" name like ? ", fmt.Sprintf("%%%s%%", userName)).Count(&count).Error; err != nil { return 0, err } return int32(count), nil