kefu/models/user_attrs.go

57 lines
1.5 KiB
Go
Raw Permalink Normal View History

2024-12-10 02:50:12 +00:00
package models
import (
"kefu/types"
"time"
)
type User_attr struct {
ID uint `gorm:"primary_key" json:"id"`
EntId string `json:"ent_id"`
KefuName string `json:"kefu_name"`
GoodNum uint `json:"good_num"`
NormalNum uint `json:"normal_num"`
BadNum uint `json:"bad_num"`
Money int64 `json:"money"`
CreatedAt types.Time `json:"created_at"`
AuthKey string `json:"auth_key"`
IdCard string `json:"id_card"`
}
func CreateUserAttr(entTd, kefuName string, goodNum, normalNum, badNum uint) *User_attr {
v := &User_attr{
EntId: entTd,
KefuName: kefuName,
GoodNum: goodNum,
NormalNum: normalNum,
BadNum: badNum,
CreatedAt: types.Time{time.Now()},
}
DB.Create(v)
return v
}
func (this *User_attr) AddUserAttr() error {
db := DB.Create(this)
return db.Error
}
func (this *User_attr) SaveUserAttr(query interface{}, args ...interface{}) error {
db := DB.Table("user_attr").Where(query, args...).Update(this)
return db.Error
}
func (this *User_attr) AddOrSaveUserAttr(query interface{}, args ...interface{}) {
attr := FindUserAttrRow(query, args...)
if attr.ID != 0 {
this.SaveUserAttr(query, args...)
} else {
this.AddUserAttr()
}
}
func FindUserAttrRow(query interface{}, args ...interface{}) *User_attr {
res := &User_attr{}
DB.Table("user_attr").Where(query, args...).Order("id desc").Find(res)
return res
}
func DelUserAttr(query interface{}, args ...interface{}) {
DB.Model(&User_attr{}).Where(query, args...).Delete(&User_attr{})
}