package models import ( "time" "github.com/beego/beego/v2/client/orm" ) type WxSession struct { WxSessionId int `orm:"pk" description:"id"` OpenId string `description:"openId"` UnionId string `description:"unionId"` AccessToken string `description:"微信token"` CreateTime time.Time `description:"创建时间"` LastUpdateTime time.Time `description:"最后更新时间"` } func (w *WxSession) Insert() (insertId int64, err error) { o := orm.NewOrm() insertId, err = o.Insert(w) return } func (w *WxSession) Update(cols []string) (err error) { o := orm.NewOrm() _, err = o.Update(w, cols...) return } func GetWxSessionByAccessToken(accessToken string) (item *WxSession, err error) { o := orm.NewOrm() sql := `SELECT * FROM wx_session WHERE access_token = ?` err = o.Raw(sql, accessToken).QueryRow(&item) return } func GetWxSessionByOpenId(openId string) (item *WxSession, err error) { o := orm.NewOrm() sql := `SELECT * FROM wx_session WHERE open_id = ?` err = o.Raw(sql, openId).QueryRow(&item) return }