feat: client 增删改查
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
package system
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"sundynix-go/global"
|
||||
"sundynix-go/model/system"
|
||||
systemReq "sundynix-go/model/system/request"
|
||||
"sundynix-go/utils"
|
||||
)
|
||||
|
||||
type UserService struct{}
|
||||
|
||||
var UserServiceApp = new(UserService)
|
||||
|
||||
func (userService *UserService) Login(u *system.User) (userInfo *system.User, err error) {
|
||||
var user system.User
|
||||
err = global.DB.Where("account = ?", u.Account).First(&user).Error
|
||||
if err == nil {
|
||||
if ok := utils.BcryptCheck(u.Password, user.Password); !ok {
|
||||
return nil, errors.New("密码错误")
|
||||
}
|
||||
}
|
||||
return &user, err
|
||||
}
|
||||
|
||||
func (userService *UserService) GetUserList(info systemReq.GetUserList) (list interface{}, total int64, err error) {
|
||||
limit := info.PageSize
|
||||
offset := info.PageSize * (info.Current - 1)
|
||||
db := global.DB.Model(&system.User{})
|
||||
var userList []system.User
|
||||
|
||||
if info.Account != "" {
|
||||
db = db.Where("account LIKE ?", "%"+info.Account+"%")
|
||||
}
|
||||
if info.Phone != "" {
|
||||
db = db.Where("phone LIKE ?", "%"+info.Phone+"%")
|
||||
}
|
||||
err = db.Count(&total).Error
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
err = db.Limit(limit).Offset(offset).Find(&userList).Error
|
||||
return userList, total, err
|
||||
}
|
||||
Reference in New Issue
Block a user