You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
paopao-ce/internal/model/captcha.go

39 lines
781 B

package model
import "gorm.io/gorm"
type Captcha struct {
*Model
Phone string `json:"phone"`
Captcha string `json:"captcha"`
UseTimes int `json:"use_times"`
ExpiredOn int64 `json:"expired_on"`
}
func (c *Captcha) Create(db *gorm.DB) (*Captcha, error) {
err := db.Create(&c).Error
return c, err
}
func (c *Captcha) Update(db *gorm.DB) error {
return db.Model(&Captcha{}).Where("id = ? AND is_del = ?", c.Model.ID, 0).Save(c).Error
}
func (c *Captcha) Get(db *gorm.DB) (*Captcha, error) {
var captcha Captcha
if c.Model != nil && c.ID > 0 {
db = db.Where("id = ? AND is_del = ?", c.ID, 0)
}
if c.Phone != "" {
db = db.Where("phone = ?", c.Phone)
}
err := db.Last(&captcha).Error
if err != nil {
return &captcha, err
}
return &captcha, nil
}