2025-06-19 10:35:26 +08:00

75 lines
2.1 KiB
Go

package schema
import (
"github.com/google/uuid"
"gitlab.guxuan.icu/jinshan_community/pkg/util"
"gorm.io/gorm"
)
// Defining the `Balance` struct.
type Balance struct {
util.BaseModel
CustomerID string `json:"customerId" gorm:"type:char(36);index;comment:客户id"`
Before int `json:"before" gorm:"not null;comment:改变钱余额" `
After int `json:"after" gorm:"not null;comment:改变后余额" `
Change int `json:"change" gorm:"not null;comment:变化量" `
Reason string `json:"reason" gorm:"size:1024;comment:原因说明" `
Typer string `json:"type" gorm:"not null;comment:类型" `
OperatorID string `json:"operatorId" gorm:"type:char(36);index;comment:关联id"`
}
func (c *Balance) BeforeCreate(tx *gorm.DB) (err error) {
if c.ID == "" {
c.ID = uuid.New().String()
}
return
}
// Defining the query parameters for the `Balance` struct.
type BalanceQueryParam struct {
util.PaginationParam
}
// Defining the query options for the `Balance` struct.
type BalanceQueryOptions struct {
util.QueryOptions
}
// Defining the query result for the `Balance` struct.
type BalanceQueryResult struct {
Data Balances
PageResult *util.PaginationResult
}
// Defining the slice of `Balance` struct.
type Balances []*Balance
// Defining the data structure for creating a `Balance` struct.
type BalanceForm struct {
CustomerID string `json:"customerId" `
Before int `json:"before" `
After int `json:"after"`
Change int `json:"change"`
Reason string `json:"reason" `
Typer string `json:"type" `
OperatorID string `json:"operatorId" `
CreatedID string `json:"CreatedID" `
}
// A validation function for the `BalanceForm` struct.
func (a *BalanceForm) Validate() error {
return nil
}
// Convert `BalanceForm` to `Balance` object.
func (a *BalanceForm) FillTo(balance *Balance) error {
balance.CustomerID = a.CustomerID
balance.Before = a.Before
balance.After = a.After
balance.Reason = a.Reason
balance.Typer = a.Typer
balance.OperatorID = a.OperatorID
balance.CreatedID = a.CreatedID
return nil
}