✨ scan the QR code to log in on the WeChat public account
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"schisandra-cloud-album/service/role_service"
|
||||
"schisandra-cloud-album/service/user_role_service"
|
||||
"schisandra-cloud-album/service/user_service"
|
||||
"schisandra-cloud-album/service/user_social_service"
|
||||
)
|
||||
|
||||
// Services 统一导出的service
|
||||
@@ -15,6 +16,7 @@ type Services struct {
|
||||
UserRoleService user_role_service.UserRoleService
|
||||
RolePermissionService role_permission_service.RolePermissionService
|
||||
PermissionService permission_service.PermissionService
|
||||
UserSocialService user_social_service.UserSocialService
|
||||
}
|
||||
|
||||
// Service new函数实例化,实例化完成后会返回结构体地指针类型
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package user_service
|
||||
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
"schisandra-cloud-album/common/enum"
|
||||
"schisandra-cloud-album/global"
|
||||
"schisandra-cloud-album/model"
|
||||
@@ -22,10 +21,21 @@ func (UserService) QueryUserByUsername(username string) model.ScaAuthUser {
|
||||
}
|
||||
|
||||
// QueryUserByUuid 根据用户uuid查询用户
|
||||
func (UserService) QueryUserByUuid(uuid string) model.ScaAuthUser {
|
||||
func (UserService) QueryUserByUuid(uuid *string) (model.ScaAuthUser, error) {
|
||||
authUser := model.ScaAuthUser{}
|
||||
global.DB.Where("uuid = ? and deleted = 0", uuid).First(&authUser)
|
||||
return authUser
|
||||
if err := global.DB.Where("uid = ? and deleted = 0", uuid).First(&authUser).Error; err != nil {
|
||||
return model.ScaAuthUser{}, err
|
||||
}
|
||||
return authUser, nil
|
||||
}
|
||||
|
||||
// QueryUserById 根据用户id查询用户
|
||||
func (UserService) QueryUserById(id *int64) (model.ScaAuthUser, error) {
|
||||
authUser := model.ScaAuthUser{}
|
||||
if err := global.DB.Where("id = ? and deleted = 0", id).First(&authUser).Error; err != nil {
|
||||
return model.ScaAuthUser{}, err
|
||||
}
|
||||
return authUser, nil
|
||||
}
|
||||
|
||||
// AddUser 添加用户
|
||||
@@ -42,15 +52,14 @@ func (UserService) AddUser(user model.ScaAuthUser) (model.ScaAuthUser, error) {
|
||||
}
|
||||
|
||||
// UpdateUser 更新用户
|
||||
func (UserService) UpdateUser(user model.ScaAuthUser) *gorm.DB {
|
||||
authUser := model.ScaAuthUser{}
|
||||
return global.DB.Model(&authUser).Where("uuid = ?", user.UID).Updates(user)
|
||||
func (UserService) UpdateUser(phone string, password string) error {
|
||||
return global.DB.Model(&model.ScaAuthUser{}).Where("phone = ? and deleted = 0", phone).Updates(&model.ScaAuthUser{Password: &password}).Error
|
||||
}
|
||||
|
||||
// DeleteUser 删除用户
|
||||
func (UserService) DeleteUser(uuid string) error {
|
||||
authUser := model.ScaAuthUser{}
|
||||
return global.DB.Model(&authUser).Where("uuid = ?", uuid).Updates(&model.ScaAuthUser{Deleted: &enum.DELETED}).Error
|
||||
return global.DB.Model(&authUser).Where("uid = ?", uuid).Updates(&model.ScaAuthUser{Deleted: &enum.DELETED}).Error
|
||||
}
|
||||
|
||||
// QueryUserByPhone 根据手机号查询用户
|
||||
|
||||
3
service/user_social_service/user_social.go
Normal file
3
service/user_social_service/user_social.go
Normal file
@@ -0,0 +1,3 @@
|
||||
package user_social_service
|
||||
|
||||
type UserSocialService struct{}
|
||||
31
service/user_social_service/user_social_service.go
Normal file
31
service/user_social_service/user_social_service.go
Normal file
@@ -0,0 +1,31 @@
|
||||
package user_social_service
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"gorm.io/gorm"
|
||||
"schisandra-cloud-album/global"
|
||||
"schisandra-cloud-album/model"
|
||||
)
|
||||
|
||||
// AddUserSocial 添加社会化登录用户信息
|
||||
|
||||
func (UserSocialService) AddUserSocial(user model.ScaAuthUserSocial) error {
|
||||
result := global.DB.Create(&user)
|
||||
if result.Error != nil {
|
||||
return result.Error
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// QueryUserSocialByOpenID 根据openID查询用户信息
|
||||
func (UserSocialService) QueryUserSocialByOpenID(openID string) (model.ScaAuthUserSocial, error) {
|
||||
var user model.ScaAuthUserSocial
|
||||
result := global.DB.Where("open_id = ? and deleted = 0", openID).First(&user)
|
||||
if result.Error != nil {
|
||||
if errors.Is(result.Error, gorm.ErrRecordNotFound) {
|
||||
return model.ScaAuthUserSocial{}, result.Error
|
||||
}
|
||||
return model.ScaAuthUserSocial{}, result.Error
|
||||
}
|
||||
return user, nil
|
||||
}
|
||||
Reference in New Issue
Block a user