28 lines
564 B
Go
28 lines
564 B
Go
|
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"
|
||
|
}
|