You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

68 lines
1.7 KiB
Go

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package handle
import (
"Lee-WineList/common/constant"
"Lee-WineList/model/entity"
"Lee-WineList/repository"
"errors"
"git.echol.cn/loser/logger/log"
"strconv"
)
// 获取普通用户信息
func getUser(account string, loginType constant.LoginType, nikeName string, avatarUrl string) (userId string, err error) {
// 根据登录类型获取用户信息
// 定义微信小程序信息
//var unionId, openId, sessionKey string
//var mobile string
// 定义用户信息
var user entity.User
switch loginType {
case constant.LoginTypeWeChatMiniApp:
//mobile, err = utils.WeChatUtils().GetPhoneNumber(account)
//if err != nil {
// return
//}
//if mobile == "" {
// err = errors.New("获取手机号失败")
// return
//}
//user.Phone = mobile
user.Nickname = nikeName
user.Avatar = avatarUrl
default:
//user.Phone = account
user.Nickname = nikeName
user.Avatar = avatarUrl
}
// 查询用户信息
if err = repository.User().GetOrCreate(&user); err != nil {
log.Errorf("获取用户信息或创建用户失败,错误信息:%s", err.Error())
err = errors.New("登录失败,请联系管理员")
return
}
// 校验用户状态
if user.Status == constant.UserStatusDisabled {
err = errors.New("账户已被禁用")
return
}
// 异步缓存小程序SessionKey
//go func() {
// if loginType == constant.LoginTypeWeChatMiniApp {
// // 缓存SessionKey
// if client.Redis.Set(context.Background(), constant.WeChatSessionKey+user.Id, sessionKey, 3*24*time.Hour).Err() != nil {
// log.Errorf("缓存SessionKey失败用户Id%s", user.Id)
// }
// }
//}()
// 返回用户Id
userId = strconv.Itoa(user.Id)
return
}