msg_code.go 852 B

123456789101112131415161718192021222324252627282930313233343536
  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. type MsgCodeResp struct {
  17. Mobile string `description:"手机号"`
  18. AreaNum string `description:"地区编码 国内默认为空"`
  19. }
  20. //添加用户session信息
  21. func AddMsgCode(item *MsgCode) (err error) {
  22. o := orm.NewOrmUsingDB("rddp")
  23. _, err = o.Insert(item)
  24. return
  25. }
  26. func GetMsgCode(mobile, code string) (item *MsgCode, err error) {
  27. o := orm.NewOrmUsingDB("rddp")
  28. sql := `SELECT * FROM msg_code WHERE mobile=? AND code=? AND FROM_UNIXTIME(expired_in)>=NOW() `
  29. err = o.Raw(sql, mobile, code).QueryRow(&item)
  30. return
  31. }