package model
|
|
import (
|
"aps_crm/pkg/mysqlx"
|
"gorm.io/gorm"
|
)
|
|
type (
|
// RegularCustomers 老客户
|
RegularCustomers struct {
|
Id int `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"`
|
Name string `json:"name" gorm:"column:name;type:varchar(255);comment:客户名称"`
|
}
|
|
// RegularCustomersSearch 老客户搜索条件
|
RegularCustomersSearch struct {
|
RegularCustomers
|
Orm *gorm.DB
|
}
|
)
|
|
func (RegularCustomers) TableName() string {
|
return "regular_customers"
|
}
|
|
func NewRegularCustomersSearch() *RegularCustomersSearch {
|
return &RegularCustomersSearch{
|
Orm: mysqlx.GetDB(),
|
}
|
}
|
|
func (slf *RegularCustomersSearch) build() *gorm.DB {
|
var db = slf.Orm.Model(&RegularCustomers{})
|
if slf.Id != 0 {
|
db = db.Where("id = ?", slf.Id)
|
}
|
if slf.Name != "" {
|
db = db.Where("name = ?", slf.Name)
|
}
|
|
return db
|
}
|
|
func (slf *RegularCustomersSearch) Create(record *RegularCustomers) error {
|
var db = slf.build()
|
return db.Create(record).Error
|
}
|
|
func (slf *RegularCustomersSearch) Delete() error {
|
var db = slf.build()
|
return db.Delete(&RegularCustomers{}).Error
|
}
|
|
func (slf *RegularCustomersSearch) Update(record *RegularCustomers) error {
|
var db = slf.build()
|
return db.Updates(record).Error
|
}
|
|
func (slf *RegularCustomersSearch) Find() (*RegularCustomers, error) {
|
var db = slf.build()
|
var record = &RegularCustomers{}
|
err := db.First(record).Error
|
return record, err
|
}
|
|
func (slf *RegularCustomersSearch) FindAll() ([]*RegularCustomers, error) {
|
var db = slf.build()
|
var records = make([]*RegularCustomers, 0)
|
err := db.Find(&records).Error
|
return records, err
|
}
|
|
func (slf *RegularCustomersSearch) SetId(id int) *RegularCustomersSearch {
|
slf.Id = id
|
return slf
|
}
|
|
func (slf *RegularCustomersSearch) SetName(name string) *RegularCustomersSearch {
|
slf.Name = name
|
return slf
|
}
|
|
func (slf *RegularCustomersSearch) Updates(data map[string]interface{}) error {
|
var db = slf.build()
|
return db.Updates(data).Error
|
}
|