59 lines
1.7 KiB
Go
59 lines
1.7 KiB
Go
|
package models
|
||
|
|
||
|
import (
|
||
|
"kefu/types"
|
||
|
"time"
|
||
|
)
|
||
|
|
||
|
type Customer struct {
|
||
|
ID uint `gorm:"primary_key" json:"id"`
|
||
|
EntId string `json:"ent_id"`
|
||
|
KefuName string `json:"kefu_name"`
|
||
|
Tel string `json:"tel"`
|
||
|
Name string `json:"name"`
|
||
|
Openid string `json:"openid"`
|
||
|
AcountOpenid string `json:"acount_openid"`
|
||
|
Extra string `json:"extra"`
|
||
|
Score uint `json:"score"`
|
||
|
Avatar string `json:"avatar"`
|
||
|
CreatedAt types.Time `json:"created_at"`
|
||
|
UpdatedAt types.Time `json:"updated_at"`
|
||
|
}
|
||
|
|
||
|
func CreateCustomer(acountOpenid, entId, kefuName string) *Customer {
|
||
|
v := &Customer{
|
||
|
AcountOpenid: acountOpenid,
|
||
|
EntId: entId,
|
||
|
KefuName: kefuName,
|
||
|
CreatedAt: types.Time{Time: time.Now()},
|
||
|
}
|
||
|
|
||
|
DB.Create(v)
|
||
|
return v
|
||
|
}
|
||
|
func FindCustomerWhere(query interface{}, args ...interface{}) Customer {
|
||
|
var customer Customer
|
||
|
DB.Where(query, args...).First(&customer)
|
||
|
return customer
|
||
|
}
|
||
|
func CountCustomer(query interface{}, args ...interface{}) uint {
|
||
|
var v uint
|
||
|
DB.Table("customer").Where(query, args...).Count(&v)
|
||
|
return v
|
||
|
}
|
||
|
func FindCustomers(page, pagesize int, query interface{}, args ...interface{}) []Customer {
|
||
|
offset := (page - 1) * pagesize
|
||
|
var res []Customer
|
||
|
DB.Table("customer").Where(query, args...).Order("id desc").Offset(offset).Limit(pagesize).Find(&res)
|
||
|
return res
|
||
|
}
|
||
|
func DelCustomer(query interface{}, args ...interface{}) {
|
||
|
DB.Where(query, args...).Delete(&Customer{})
|
||
|
}
|
||
|
func (this *Customer) SaveCustomer(query interface{}, args ...interface{}) {
|
||
|
DB.Model(&Customer{}).Where(query, args...).Update(this)
|
||
|
}
|
||
|
func (this *Customer) AddCustomer() error {
|
||
|
return DB.Create(this).Error
|
||
|
}
|