mirror of
https://github.com/openimsdk/open-im-server.git
synced 2026-05-05 01:25:58 +08:00
merge cms into v2.3.0release
This commit is contained in:
@@ -3,6 +3,7 @@ package im_mysql_model
|
||||
import (
|
||||
"Open_IM/pkg/common/db"
|
||||
"errors"
|
||||
|
||||
_ "gorm.io/gorm"
|
||||
)
|
||||
|
||||
@@ -74,3 +75,10 @@ func DeleteAllRegisterAddFriendIDList() error {
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Where("1 = 1").Delete(&db.RegisterAddFriend{}).Error
|
||||
return err
|
||||
}
|
||||
|
||||
func GetUserIPLimit(userID string) (db.UserIpLimit, error) {
|
||||
var limit db.UserIpLimit
|
||||
limit.UserID = userID
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Model(&db.UserIpLimit{}).Take(&limit).Error
|
||||
return limit, err
|
||||
}
|
||||
|
||||
@@ -2,8 +2,10 @@ package im_mysql_model
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/db"
|
||||
_ "github.com/jinzhu/gorm/dialects/mysql"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
_ "github.com/jinzhu/gorm/dialects/mysql"
|
||||
)
|
||||
|
||||
func InsertToFriend(toInsertFollow *db.Friend) error {
|
||||
@@ -51,3 +53,34 @@ func UpdateFriendComment(OwnerUserID, FriendUserID, Remark string) error {
|
||||
func DeleteSingleFriendInfo(OwnerUserID, FriendUserID string) error {
|
||||
return db.DB.MysqlDB.DefaultGormDB().Table("friends").Where("owner_user_id=? and friend_user_id=?", OwnerUserID, FriendUserID).Delete(db.Friend{}).Error
|
||||
}
|
||||
|
||||
type FriendUser struct {
|
||||
db.Friend
|
||||
Nickname string `gorm:"column:name;size:255"`
|
||||
}
|
||||
|
||||
func GetUserFriendsCMS(ownerUserID, friendUserName string, pageNumber, showNumber int32) (friendUserList []*FriendUser, count int64, err error) {
|
||||
db := db.DB.MysqlDB.DefaultGormDB().Table("friends").
|
||||
Select("friends.*, users.name").
|
||||
Where("friends.owner_user_id=?", ownerUserID).Limit(int(showNumber)).
|
||||
Joins("left join users on friends.friend_user_id = users.user_id").
|
||||
Offset(int(showNumber * (pageNumber - 1)))
|
||||
if friendUserName != "" {
|
||||
db = db.Where("users.name like ?", fmt.Sprintf("%%%s%%", friendUserName))
|
||||
}
|
||||
if err = db.Count(&count).Error; err != nil {
|
||||
return
|
||||
}
|
||||
err = db.Find(&friendUserList).Error
|
||||
return
|
||||
}
|
||||
|
||||
func GetFriendByIDCMS(ownerUserID, friendUserID string) (friendUser *FriendUser, err error) {
|
||||
friendUser = &FriendUser{}
|
||||
err = db.DB.MysqlDB.DefaultGormDB().Table("friends").
|
||||
Select("friends.*, users.name").
|
||||
Where("friends.owner_user_id=? and friends.friend_user_id=?", ownerUserID, friendUserID).
|
||||
Joins("left join users on friends.friend_user_id = users.user_id").
|
||||
Take(friendUser).Error
|
||||
return friendUser, err
|
||||
}
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
package im_mysql_model
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/db"
|
||||
"Open_IM/pkg/utils"
|
||||
"fmt"
|
||||
|
||||
"time"
|
||||
)
|
||||
|
||||
@@ -54,7 +56,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 ? and status != ?", fmt.Sprintf("%%%s%%", groupName), constant.GroupStatusDismissed).Limit(int(showNumber)).Offset(int(showNumber * (pageNumber - 1))).Find(&groups).Error
|
||||
return groups, err
|
||||
}
|
||||
|
||||
@@ -80,7 +82,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(fmt.Sprintf(" 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
|
||||
|
||||
@@ -74,3 +74,15 @@ func GetRegisterUserNum(ip string) ([]string, error) {
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Model(&db.Register{}).Where("register_ip=?", ip).Pluck("user_id", &userIDList).Error
|
||||
return userIDList, err
|
||||
}
|
||||
|
||||
func InsertIpRecord(userID, createIp string) error {
|
||||
record := &db.UserIpRecord{UserID: userID, CreateIp: createIp, LastLoginTime: time.Now(), LoginTimes: 1}
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Model(&db.UserIpRecord{}).Create(record).Error
|
||||
return err
|
||||
}
|
||||
|
||||
func UpdateIpReocord(userID, ip string) error {
|
||||
record := &db.UserIpRecord{UserID: userID, LastLoginIp: ip, LastLoginTime: time.Now()}
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Model(&db.UserIpRecord{}).Updates(record).Updates("login_times = login_times + 1").Error
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package im_mysql_model
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/db"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/utils"
|
||||
@@ -10,10 +11,17 @@ import (
|
||||
func GetChatLog(chatLog db.ChatLog, pageNumber, showNumber int32) ([]db.ChatLog, error) {
|
||||
var chatLogs []db.ChatLog
|
||||
db := db.DB.MysqlDB.DefaultGormDB().Table("chat_logs").
|
||||
Where(fmt.Sprintf(" content like '%%%s%%'", chatLog.Content)).
|
||||
Limit(int(showNumber)).Offset(int(showNumber * (pageNumber - 1)))
|
||||
if chatLog.SessionType != 0 {
|
||||
if chatLog.SendTime.Unix() > 0 {
|
||||
db = db.Where("send_time > ? and send_time < ?", chatLog.SendTime, chatLog.SendTime.AddDate(0, 0, 1))
|
||||
}
|
||||
if chatLog.Content != "" {
|
||||
db = db.Where(" content like ? ", fmt.Sprintf("%%%s%%", chatLog.Content))
|
||||
}
|
||||
if chatLog.SessionType == 1 {
|
||||
db = db.Where("session_type = ?", chatLog.SessionType)
|
||||
} else if chatLog.SessionType == 2 {
|
||||
db = db.Where("content_type in (?)", []int{constant.GroupChatType, constant.SuperGroupChatType})
|
||||
}
|
||||
if chatLog.ContentType != 0 {
|
||||
db = db.Where("content_type = ?", chatLog.ContentType)
|
||||
@@ -24,23 +32,28 @@ func GetChatLog(chatLog db.ChatLog, pageNumber, showNumber int32) ([]db.ChatLog,
|
||||
if chatLog.RecvID != "" {
|
||||
db = db.Where("recv_id = ?", chatLog.RecvID)
|
||||
}
|
||||
if chatLog.SendTime.Unix() > 0 {
|
||||
db = db.Where("send_time > ? and send_time < ?", chatLog.SendTime, chatLog.SendTime.AddDate(0, 0, 1))
|
||||
}
|
||||
|
||||
err := db.Find(&chatLogs).Error
|
||||
return chatLogs, err
|
||||
}
|
||||
|
||||
func GetChatLogCount(chatLog db.ChatLog) (int64, error) {
|
||||
var chatLogs []db.ChatLog
|
||||
var count int64
|
||||
db := db.DB.MysqlDB.DefaultGormDB().Table("chat_logs").
|
||||
Where(fmt.Sprintf(" content like '%%%s%%'", chatLog.Content))
|
||||
db := db.DB.MysqlDB.DefaultGormDB().Table("chat_logs")
|
||||
if chatLog.SendTime.Unix() > 0 {
|
||||
log.NewDebug("", utils.GetSelfFuncName(), chatLog.SendTime, chatLog.SendTime.AddDate(0, 0, 1))
|
||||
db = db.Where("send_time > ? and send_time < ?", chatLog.SendTime, chatLog.SendTime.AddDate(0, 0, 1))
|
||||
}
|
||||
if chatLog.Content != "" {
|
||||
db = db.Where(" content like ? ", fmt.Sprintf("%%%s%%", chatLog.Content))
|
||||
}
|
||||
if chatLog.SessionType != 0 {
|
||||
db = db.Where("session_type = ?", chatLog.SessionType)
|
||||
}
|
||||
if chatLog.ContentType != 0 {
|
||||
if chatLog.ContentType == 1 {
|
||||
db = db.Where("content_type = ?", chatLog.ContentType)
|
||||
} else if chatLog.ContentType == 2 {
|
||||
db = db.Where("content_type in (?)", []int{constant.GroupChatType, constant.SuperGroupChatType})
|
||||
}
|
||||
if chatLog.SendID != "" {
|
||||
db = db.Where("send_id = ?", chatLog.SendID)
|
||||
@@ -48,11 +61,7 @@ func GetChatLogCount(chatLog db.ChatLog) (int64, error) {
|
||||
if chatLog.RecvID != "" {
|
||||
db = db.Where("recv_id = ?", chatLog.RecvID)
|
||||
}
|
||||
if chatLog.SendTime.Unix() > 0 {
|
||||
log.NewDebug("", utils.GetSelfFuncName(), chatLog.SendTime, chatLog.SendTime.AddDate(0, 0, 1))
|
||||
db = db.Where("send_time > ? and send_time < ?", chatLog.SendTime, chatLog.SendTime.AddDate(0, 0, 1))
|
||||
}
|
||||
|
||||
err := db.Find(&chatLogs).Count(&count).Error
|
||||
err := db.Count(&count).Error
|
||||
return count, err
|
||||
}
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
package im_mysql_model
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/db"
|
||||
"time"
|
||||
)
|
||||
|
||||
func GetActiveUserNum(from, to time.Time) (int32, error) {
|
||||
var num int64
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Table("chat_logs").Select("count(distinct(send_id))").Where("create_time >= ? and create_time <= ?", from, to).Count(&num).Error
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Table("chat_logs").Select("count(distinct(send_id))").Where("send_time >= ? and send_time <= ?", from, to).Count(&num).Error
|
||||
return int32(num), err
|
||||
}
|
||||
|
||||
@@ -31,13 +32,13 @@ func GetTotalUserNumByDate(to time.Time) (int32, error) {
|
||||
|
||||
func GetPrivateMessageNum(from, to time.Time) (int32, error) {
|
||||
var num int64
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Table("chat_logs").Where("create_time >= ? and create_time <= ? and session_type = ?", from, to, 1).Count(&num).Error
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Table("chat_logs").Where("send_time >= ? and send_time <= ? and session_type = ?", from, to, 1).Count(&num).Error
|
||||
return int32(num), err
|
||||
}
|
||||
|
||||
func GetGroupMessageNum(from, to time.Time) (int32, error) {
|
||||
var num int64
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Table("chat_logs").Where("create_time >= ? and create_time <= ? and session_type = ?", from, to, 2).Count(&num).Error
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Table("chat_logs").Where("send_time >= ? and send_time <= ? and session_type = ?", from, to, 2).Count(&num).Error
|
||||
return int32(num), err
|
||||
}
|
||||
|
||||
@@ -67,7 +68,7 @@ type activeGroup struct {
|
||||
|
||||
func GetActiveGroups(from, to time.Time, limit int) ([]*activeGroup, error) {
|
||||
var activeGroups []*activeGroup
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Table("chat_logs").Select("recv_id, count(*) as message_num").Where("create_time >= ? and create_time <= ? and session_type = ?", from, to, 2).Group("recv_id").Limit(limit).Order("message_num DESC").Find(&activeGroups).Error
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Table("chat_logs").Select("recv_id, count(*) as message_num").Where("send_time >= ? and send_time <= ? and session_type in (?)", from, to, []int{constant.GroupChatType, constant.SuperGroupChatType}).Group("recv_id").Limit(limit).Order("message_num DESC").Find(&activeGroups).Error
|
||||
for _, activeGroup := range activeGroups {
|
||||
group := db.Group{
|
||||
GroupID: activeGroup.Id,
|
||||
@@ -80,18 +81,21 @@ func GetActiveGroups(from, to time.Time, limit int) ([]*activeGroup, error) {
|
||||
|
||||
type activeUser struct {
|
||||
Name string
|
||||
Id string `gorm:"column:send_id"`
|
||||
ID string `gorm:"column:send_id"`
|
||||
MessageNum int `gorm:"column:message_num"`
|
||||
}
|
||||
|
||||
func GetActiveUsers(from, to time.Time, limit int) ([]*activeUser, error) {
|
||||
var activeUsers []*activeUser
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Table("chat_logs").Select("send_id, count(*) as message_num").Where("create_time >= ? and create_time <= ? and session_type = ?", from, to, 1).Group("send_id").Limit(limit).Order("message_num DESC").Find(&activeUsers).Error
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Table("chat_logs").Select("send_id, count(*) as message_num").Where("send_time >= ? and send_time <= ? and session_type = ?", from, to, constant.SingleChatType).Group("send_id").Limit(limit).Order("message_num DESC").Find(&activeUsers).Error
|
||||
for _, activeUser := range activeUsers {
|
||||
user := db.User{
|
||||
UserID: activeUser.Id,
|
||||
UserID: activeUser.ID,
|
||||
}
|
||||
err = db.DB.MysqlDB.DefaultGormDB().Table("users").Select("user_id, name").Find(&user).Error
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
db.DB.MysqlDB.DefaultGormDB().Table("users").Select("user_id, name").Find(&user)
|
||||
activeUser.Name = user.Nickname
|
||||
}
|
||||
return activeUsers, err
|
||||
|
||||
@@ -11,14 +11,14 @@ func InsertInToUserBlackList(black db.Black) error {
|
||||
return db.DB.MysqlDB.DefaultGormDB().Table("blacks").Create(black).Error
|
||||
}
|
||||
|
||||
//type Black struct {
|
||||
// OwnerUserID string `gorm:"column:owner_user_id;primaryKey;"`
|
||||
// BlockUserID string `gorm:"column:block_user_id;primaryKey;"`
|
||||
// CreateTime time.Time `gorm:"column:create_time"`
|
||||
// AddSource int32 `gorm:"column:add_source"`
|
||||
// OperatorUserID int32 `gorm:"column:operator_user_id"`
|
||||
// Ex string `gorm:"column:ex"`
|
||||
//}
|
||||
// type Black struct {
|
||||
// OwnerUserID string `gorm:"column:owner_user_id;primaryKey;"`
|
||||
// BlockUserID string `gorm:"column:block_user_id;primaryKey;"`
|
||||
// CreateTime time.Time `gorm:"column:create_time"`
|
||||
// AddSource int32 `gorm:"column:add_source"`
|
||||
// OperatorUserID int32 `gorm:"column:operator_user_id"`
|
||||
// Ex string `gorm:"column:ex"`
|
||||
// }
|
||||
|
||||
func CheckBlack(ownerUserID, blockUserID string) error {
|
||||
var black db.Black
|
||||
|
||||
@@ -43,9 +43,6 @@ func UserRegister(user db.User) error {
|
||||
if user.Birth.Unix() < 0 {
|
||||
user.Birth = utils.UnixSecondToTime(0)
|
||||
}
|
||||
user.LastLoginTime = time.Now()
|
||||
user.LoginTimes = 0
|
||||
user.LastLoginIp = user.CreateIp
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Table("users").Create(&user).Error
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -124,31 +121,21 @@ func GetUsers(showNumber, pageNumber int32) ([]db.User, error) {
|
||||
return users, err
|
||||
}
|
||||
|
||||
func AddUser(userId string, phoneNumber string, name string, email string, gender string, photo string, birth string) error {
|
||||
_gender, _err := strconv.Atoi(gender)
|
||||
if _err != nil {
|
||||
_gender = 0
|
||||
}
|
||||
_birth, _err := time.ParseInLocation("2006-01-02", birth, time.Local)
|
||||
func AddUser(userID string, phoneNumber string, name string, email string, gender int32, faceURL string, birth uint32) error {
|
||||
_birth, _err := time.ParseInLocation("2006-01-02", strconv.Itoa(int(birth)), time.Local)
|
||||
if _err != nil {
|
||||
_birth = time.Now()
|
||||
}
|
||||
user := db.User{
|
||||
UserID: userId,
|
||||
Nickname: name,
|
||||
FaceURL: photo,
|
||||
Gender: int32(_gender),
|
||||
PhoneNumber: phoneNumber,
|
||||
Birth: _birth,
|
||||
Email: email,
|
||||
Ex: "",
|
||||
CreateTime: time.Now(),
|
||||
CreateIp: "",
|
||||
LastLoginTime: time.Now(),
|
||||
LastLoginIp: "",
|
||||
LoginTimes: 0,
|
||||
LoginLimit: 0,
|
||||
InvitationCode: "",
|
||||
UserID: userID,
|
||||
Nickname: name,
|
||||
FaceURL: faceURL,
|
||||
Gender: gender,
|
||||
PhoneNumber: phoneNumber,
|
||||
Birth: _birth,
|
||||
Email: email,
|
||||
Ex: "",
|
||||
CreateTime: time.Now(),
|
||||
}
|
||||
result := db.DB.MysqlDB.DefaultGormDB().Table("users").Create(&user)
|
||||
return result.Error
|
||||
@@ -163,8 +150,13 @@ func UserIsBlock(userId string) (bool, error) {
|
||||
return false, nil
|
||||
}
|
||||
|
||||
func BlockUser(userId, endDisableTime string) error {
|
||||
user, err := GetUserByUserID(userId)
|
||||
func UsersIsBlock(userIDList []string) (inBlockUserIDList []string, err error) {
|
||||
err = db.DB.MysqlDB.DefaultGormDB().Table("black_lists").Where("uid in (?) and end_disable_time > now()", userIDList).Pluck("uid", &inBlockUserIDList).Error
|
||||
return inBlockUserIDList, err
|
||||
}
|
||||
|
||||
func BlockUser(userID, endDisableTime string) error {
|
||||
user, err := GetUserByUserID(userID)
|
||||
if err != nil || user.UserID == "" {
|
||||
return err
|
||||
}
|
||||
@@ -176,34 +168,34 @@ func BlockUser(userId, endDisableTime string) error {
|
||||
return constant.ErrDB
|
||||
}
|
||||
var blockUser db.BlackList
|
||||
db.DB.MysqlDB.DefaultGormDB().Table("black_lists").Where("uid=?", userId).First(&blockUser)
|
||||
db.DB.MysqlDB.DefaultGormDB().Table("black_lists").Where("uid=?", userID).First(&blockUser)
|
||||
if blockUser.UserId != "" {
|
||||
db.DB.MysqlDB.DefaultGormDB().Model(&blockUser).Where("uid=?", blockUser.UserId).Update("end_disable_time", end)
|
||||
if user.LoginLimit != 2 {
|
||||
db.DB.MysqlDB.DefaultGormDB().Table("users").Where("user_id=?", blockUser.UserId).Update("login_limit", 2)
|
||||
}
|
||||
// if user.LoginLimit != 2 {
|
||||
// db.DB.MysqlDB.DefaultGormDB().Table("users").Where("user_id=?", blockUser.UserId).Update("login_limit", 2)
|
||||
// }
|
||||
return nil
|
||||
}
|
||||
blockUser = db.BlackList{
|
||||
UserId: userId,
|
||||
UserId: userID,
|
||||
BeginDisableTime: time.Now(),
|
||||
EndDisableTime: end,
|
||||
}
|
||||
result := db.DB.MysqlDB.DefaultGormDB().Create(&blockUser)
|
||||
if result.Error == nil {
|
||||
if user.LoginLimit != 2 {
|
||||
db.DB.MysqlDB.DefaultGormDB().Table("users").Where("user_id=?", blockUser.UserId).Update("login_limit", 2)
|
||||
}
|
||||
// if user.LoginLimit != 2 {
|
||||
// db.DB.MysqlDB.DefaultGormDB().Table("users").Where("user_id=?", blockUser.UserId).Update("login_limit", 2)
|
||||
// }
|
||||
}
|
||||
return result.Error
|
||||
}
|
||||
|
||||
func UnBlockUser(userId string) error {
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Where("uid=?", userId).Delete(&db.BlackList{}).Error
|
||||
func UnBlockUser(userID string) error {
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Where("uid=?", userID).Delete(&db.BlackList{}).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return db.DB.MysqlDB.DefaultGormDB().Table("users").Where("user_id=?", userId).Update("login_limit", 0).Error
|
||||
return db.DB.MysqlDB.DefaultGormDB().Table("users").Where("user_id=?", userID).Update("login_limit", 0).Error
|
||||
}
|
||||
|
||||
type BlockUserInfo struct {
|
||||
@@ -212,7 +204,7 @@ type BlockUserInfo struct {
|
||||
EndDisableTime time.Time
|
||||
}
|
||||
|
||||
func GetBlockUserById(userId string) (BlockUserInfo, error) {
|
||||
func GetBlockUserByID(userId string) (BlockUserInfo, error) {
|
||||
var blockUserInfo BlockUserInfo
|
||||
blockUser := db.BlackList{
|
||||
UserId: userId,
|
||||
@@ -267,13 +259,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(fmt.Sprintf(" name like '%%%s%%' ", 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(user db.User) (int32, error) {
|
||||
func GetUsersCount(userName string) (int32, error) {
|
||||
var count int64
|
||||
if err := db.DB.MysqlDB.DefaultGormDB().Table("users").Where(fmt.Sprintf(" name like '%%%s%%' ", user.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
|
||||
|
||||
Reference in New Issue
Block a user