msg_code.go 717 B

12345678910111213141516171819202122232425262728293031
  1. package models
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "time"
  5. )
  6. type MsgCode struct {
  7. MsgCodeId int `orm:"column(msg_code_id);pk"`
  8. OpenId string
  9. Mobile string
  10. Code string
  11. ExpiredIn int64
  12. Enabled int
  13. CreatedTime time.Time
  14. LastUpdatedTime time.Time
  15. }
  16. //添加用户session信息
  17. func AddMsgCode(item *MsgCode) (err error) {
  18. o := orm.NewOrmUsingDB("rddp")
  19. _, err = o.Insert(item)
  20. return
  21. }
  22. func GetMsgCode(mobile, code string) (item *MsgCode, err error) {
  23. o := orm.NewOrmUsingDB("rddp")
  24. sql := `SELECT * FROM msg_code WHERE mobile=? AND code=? AND FROM_UNIXTIME(expired_in)>=NOW() `
  25. err = o.Raw(sql, mobile, code).QueryRow(&item)
  26. return
  27. }