kefu/models/user_douyin.go

53 lines
1.8 KiB
Go
Raw Permalink Normal View History

2024-12-10 02:50:12 +00:00
package models
import "kefu/types"
type User_douyin struct {
ID uint `gorm:"primary_key" json:"id"`
EntId string `json:"ent_id"`
KefuName string `json:"kefu_name"`
Nickname string `json:"nickname"`
Avatar string `json:"avatar"`
OpenId string `json:"open_id"`
UnionId string `json:"union_id"`
AccessToken string `json:"access_token"`
ClientToken string `json:"client_token"`
RefreshToken string `json:"refresh_token"`
ExpiresIn types.Time `json:"expires_in"`
RefreshExpiresIn types.Time `json:"refresh_expires_in"`
ClientTokenExpires string `json:"client_token_expires"`
CreatedAt types.Time `json:"created_at"`
}
func (this *User_douyin) UpdateOrInsert() error {
douyin := FindUserDouyinRow("open_id = ?", this.OpenId)
if douyin.ID != 0 {
return this.SaveUserDouyin("open_id = ?", this.OpenId)
} else {
return this.AddUserDouyin()
}
}
func (this *User_douyin) AddUserDouyin() error {
db := DB.Create(this)
return db.Error
}
func (this *User_douyin) SaveUserDouyin(query interface{}, args ...interface{}) error {
db := DB.Table("user_douyin").Where(query, args...).Update(this)
return db.Error
}
func FindUserDouyinRow(query interface{}, args ...interface{}) *User_douyin {
res := &User_douyin{}
DB.Table("user_douyin").Where(query, args...).Order("id desc").Find(res)
return res
}
func FindUserDouyinRows(query interface{}, args ...interface{}) []User_douyin {
var res []User_douyin
DB.Table("user_douyin").Where(query, args...).Order("id desc").Find(&res)
return res
}
func DeleteUserDouyinRows(query interface{}, args ...interface{}) []User_douyin {
var res []User_douyin
DB.Where(query, args...).Delete(User_douyin{})
return res
}