-
Notifications
You must be signed in to change notification settings - Fork 2
/
order.go
47 lines (37 loc) · 1.79 KB
/
order.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package orders
import (
"fmt"
"github.com/keepchen/go-sail/v3/examples/pkg/common/db/models"
modelsEnum "github.com/keepchen/go-sail/v3/examples/pkg/common/enum/models"
"github.com/keepchen/go-sail/v3/utils"
"gorm.io/gorm"
)
type Order struct {
models.BaseModel
UserID int64 `gorm:"column:user_id;type:bigint;not null;index:user_id;comment:用户编号"`
OrderNo string `gorm:"column:order_no;type:varchar(40);not null;index:order_no,unique;comment:订单号"`
ProductName string `gorm:"column:product_name;type:varchar(255);not null;comment:商品名称"`
ProductNum int `gorm:"column:product_num;type:int;not null;comment:商品数量"`
Status modelsEnum.OrderStatusCode `gorm:"column:status;type:tinyint;not null;default:0;comment:订单状态"`
Amount float64 `gorm:"column:amount;type:decimal(14,4);not null;comment:订单金额"`
TransactionID string `gorm:"column:transaction_id;type:varchar(40);index:bet_transaction_id;comment:交易流水号"`
Platform int `gorm:"column:platform;type:tinyint;not null;default:0;comment:下单的客户端平台(0:web,1:app)"`
}
func (*Order) TableName() string {
return "tb_orders"
}
func (*Order) Class() string {
return "Order"
}
func (o *Order) BeforeCreate(_ *gorm.DB) (err error) {
o.BaseModel.CreatedAt = utils.NewTimeWithTimeZone().Now()
o.BaseModel.UpdatedAt = o.BaseModel.CreatedAt
return nil
}
func (o *Order) BeforeUpdate(_ *gorm.DB) (err error) {
o.BaseModel.UpdatedAt = utils.NewTimeWithTimeZone().Now()
return nil
}
func (*Order) GenOrderNo() string {
return fmt.Sprintf("%d%s", utils.NewTimeWithTimeZone().Now().UnixNano(), utils.RandomDigitalChars(5))
}