46 lines
1.1 KiB
Go
46 lines
1.1 KiB
Go
|
package models
|
||
|
|
||
|
import "kefu/types"
|
||
|
|
||
|
type Learn struct {
|
||
|
ID uint `gorm:"primary_key" json:"id"`
|
||
|
EntId string `json:"ent_id"`
|
||
|
KefuName string `json:"kefu_name"`
|
||
|
Content string `json:"content"`
|
||
|
Score uint `json:"score"`
|
||
|
Finshed uint `json:"finshed"`
|
||
|
CreatedAt types.Time `json:"created_at"`
|
||
|
}
|
||
|
|
||
|
//增加
|
||
|
func (this *Learn) AddLearn() error {
|
||
|
return DB.Create(this).Error
|
||
|
}
|
||
|
|
||
|
//更新
|
||
|
func (this *Learn) SaveLearn(query interface{}, args ...interface{}) {
|
||
|
DB.Model(&Learn{}).Where(query, args...).Update(this)
|
||
|
}
|
||
|
|
||
|
//计数
|
||
|
func CountLearn(query interface{}, args ...interface{}) uint {
|
||
|
var v uint
|
||
|
DB.Table("learn").Where(query, args...).Count(&v)
|
||
|
return v
|
||
|
}
|
||
|
|
||
|
//列表
|
||
|
func FindLearnList(page, pagesize int, query interface{}, args ...interface{}) []Learn {
|
||
|
offset := (page - 1) * pagesize
|
||
|
var res []Learn
|
||
|
DB.Table("learn").Where(query, args...).Order("finshed asc,score desc,id desc").Offset(offset).Limit(pagesize).Find(&res)
|
||
|
return res
|
||
|
}
|
||
|
|
||
|
//单条
|
||
|
func FindLearn(query interface{}, args ...interface{}) Learn {
|
||
|
var res Learn
|
||
|
DB.Where(query, args...).First(&res)
|
||
|
return res
|
||
|
}
|