77 lines
2.1 KiB
Go
77 lines
2.1 KiB
Go
package schema
|
|
|
|
import (
|
|
"github.com/google/uuid"
|
|
"gitlab.guxuan.icu/jinshan_community/pkg/util"
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
// Defining the `Customer` struct.
|
|
type Customer struct {
|
|
util.BaseModel
|
|
Name string `json:"name" gorm:"size:128;index;comment:姓名"`
|
|
Phone string `json:"phone" gorm:"size:128;index;comment:手机号"`
|
|
Birthday string `json:"birthday" gorm:"size:128;index;comment:生日"`
|
|
WxSign string `json:"wxSign" gorm:"size:1024;comment:微信签名token"`
|
|
Introduce string `json:"introduce" gorm:"size:1024;comment:个性签名"`
|
|
Avatar string `json:"avatar" gorm:"size:1024;comment:头像"`
|
|
Status string `json:"status" gorm:"size:20;index;comment:状态"`
|
|
}
|
|
|
|
func (c *Customer) BeforeCreate(tx *gorm.DB) (err error) {
|
|
if c.ID == "" {
|
|
c.ID = uuid.New().String()
|
|
}
|
|
return
|
|
}
|
|
|
|
// Defining the query parameters for the `Customer` struct.
|
|
type CustomerQueryParam struct {
|
|
util.PaginationParam
|
|
}
|
|
|
|
// Defining the query options for the `Customer` struct.
|
|
type CustomerQueryOptions struct {
|
|
util.QueryOptions
|
|
LikeName string `json:"name"`
|
|
LikePhone string `json:"phone"`
|
|
Status string `json:"status"`
|
|
}
|
|
|
|
// Defining the query result for the `Customer` struct.
|
|
type CustomerQueryResult struct {
|
|
Data Customers
|
|
PageResult *util.PaginationResult
|
|
}
|
|
|
|
// Defining the slice of `Customer` struct.
|
|
type Customers []*Customer
|
|
|
|
// Defining the data structure for creating a `Customer` struct.
|
|
type CustomerForm struct {
|
|
Name string `json:"name"`
|
|
Phone string `json:"phone" `
|
|
Birthday string `json:"birthday"`
|
|
WxSign string `json:"wxSign" `
|
|
Avatar string `json:"avatar" `
|
|
Status string `json:"status"`
|
|
Introduce string `json:"introduce" `
|
|
}
|
|
|
|
// A validation function for the `CustomerForm` struct.
|
|
func (a *CustomerForm) Validate() error {
|
|
return nil
|
|
}
|
|
|
|
// Convert `CustomerForm` to `Customer` object.
|
|
func (a *CustomerForm) FillTo(customer *Customer) error {
|
|
customer.Name = a.Name
|
|
customer.Phone = a.Phone
|
|
customer.Birthday = a.Birthday
|
|
customer.WxSign = a.WxSign
|
|
customer.Avatar = a.Avatar
|
|
customer.Status = a.Status
|
|
customer.Introduce = a.Introduce
|
|
return nil
|
|
}
|