health-go/services/sms/preValidate.go

28 lines
564 B
Go
Raw Normal View History

2024-10-28 14:41:27 +08:00
package sms
import (
"fmt"
"health-go/config"
"health-go/models"
)
// PreValidate 判断用户是否存在
// @param userTel 用户手机号
// @return string notExist, reachLimit, ok, error
func PreValidate(userTel string) string {
var result models.User
// 计数查询是否存在对应的手机号
query := config.DB.Table("user").Where("tel = ?", userTel).First(&result)
if query.Error != nil {
return fmt.Sprint(query.Error)
}
if query.RowsAffected == 0 {
return "notExist"
}
if result.SMSTry > 10 {
return "reachLimit"
}
return "ok"
}