pull/351/head
wangchuxiao 2 years ago
parent 5134faeefd
commit a4b95cb7cf

@ -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

@ -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

Loading…
Cancel
Save