Browse Source

手机号判断是否存在

fuwencai 4 years ago
parent
commit
bf6bb94ae9
1 changed files with 8 additions and 0 deletions
  1. 8 0
      src/github.com/baiy/Cadmin-server-go/models/user/user.go

+ 8 - 0
src/github.com/baiy/Cadmin-server-go/models/user/user.go

@@ -66,6 +66,10 @@ func Add(username, password string, status int, description string, phone string
 	if exist.Id > 0 {
 		return errors.New(fmt.Sprintf("[%s] 用户已经存在", username))
 	}
+	phoneExist, _ := GetByPhone(phone)
+	if phoneExist.Id > 0 {
+		return errors.New(fmt.Sprintf("[%s] 手机号已经存在", phone))
+	}
 	_, err := models.Db.Insert("admin_user").Rows(
 		goqu.Record{"username": username, "password": password, "status": status, "description": description, "phone": phone},
 	).Executor().Exec()
@@ -77,6 +81,10 @@ func Updata(id int, username, password string, status int, description string, p
 	if exist.Id > 0 && exist.Id != id {
 		return errors.New(fmt.Sprintf("[%s] 用户已经存在", username))
 	}
+	phoneExist, _ := GetByPhone(phone)
+	if phoneExist.Id > 0 && phoneExist.Id != id {
+		return errors.New(fmt.Sprintf("[%s] 手机号已经存在", phone))
+	}
 	record := goqu.Record{"username": username, "status": status, "description": description, "phone": phone}
 
 	if password != "" {