2025-06-19 10:33:58 +08:00

71 lines
2.1 KiB
Go

package schema
import (
"github.guxuan/haibei/pkg/util"
)
// Defining the `Balance` struct.
type Balance struct {
util.BaseModel
CustomerID uint `json:"customerId" gorm:"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 uint `json:"operatorId" gorm:"index;comment:关联id"`
CreatorID string `json:"creatorId" gorm:"index;comment:操作人id"`
}
// Defining the query parameters for the `Balance` struct.
type BalanceQueryParam struct {
util.PaginationParam
CustomerID uint `form:"customerId" `
Typer string `form:"type" `
CreatorID string `form:"creatorId" `
}
// 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 uint `json:"customerId" `
Before int `json:"before" `
After int `json:"after" `
Change int `json:"change" `
Reason string `json:"reason" `
Typer string `json:"type" `
OperatorID uint `json:"operatorId" `
CreatorID string `json:"creatorId" `
}
// 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.Change = a.Change
balance.Reason = a.Reason
balance.Typer = a.Typer
balance.OperatorID = a.OperatorID
balance.CreatorID = a.CreatorID
return nil
}