package models import "kefu/types" type Consumer struct { ID uint `gorm:"primary_key" json:"id"` EntId string `json:"ent_id"` KefuName string `json:"kefu_name"` Realname string `json:"realname"` Tel string `json:"tel"` Wechat string `json:"wechat"` Qq string `json:"qq"` Email string `json:"email"` Remark string `json:"remark"` Score string `json:"score"` ConsumerSn string `json:"consumer_sn"` Company string `json:"company"` CreatedAt types.Time `json:"created_at"` } //增加 func (this *Consumer) AddConsumer() error { return DB.Create(this).Error } //更新 func (this *Consumer) SaveConsumer(query interface{}, args ...interface{}) { DB.Model(&Consumer{}).Where(query, args...).Update(this) } //删除 func DelConsumer(query interface{}, args ...interface{}) { DB.Where(query, args...).Delete(&Consumer{}) } //计数 func CountConsumer(query interface{}, args ...interface{}) uint { var v uint DB.Table("consumer").Where(query, args...).Count(&v) return v } //列表 func FindConsumerList(page, pagesize int, query interface{}, args ...interface{}) []Consumer { offset := (page - 1) * pagesize var res []Consumer DB.Table("consumer").Where(query, args...).Order("id desc").Offset(offset).Limit(pagesize).Find(&res) return res } //单条 func FindConsumer(query interface{}, args ...interface{}) Consumer { var res Consumer DB.Where(query, args...).First(&res) return res }