| 12345678910111213141516171819202122232425262728293031323334 |
- package user
- import "github.com/runningwater/gohub/pkg/database"
- func IsEmailExist(email string) bool {
- var count int64
- database.DB.Model(&User{}).Where("email = ?", email).Count(&count)
- return count > 0
- }
- func IsPhoneExist(phone string) bool {
- var count int64
- database.DB.Model(&User{}).Where("phone = ?", phone).Count(&count)
- return count > 0
- }
- // GetByMulti 多条件查询,支持手机号、邮箱和用户名
- // 按顺序检查并返回第一个匹配的用户
- func GetByMulti(loginID string) (userModel User) {
- database.DB.
- Where("phone = ?", loginID).
- Or("email =?", loginID).
- Or("name =?", loginID).
- First(&userModel)
- return
- }
- // GetByPhone 根据手机号查询用户
- func GetByPhone(phone string) (userModel User) {
- database.DB.Where("phone = ?", phone).First(&userModel)
- return
- }
|