/
order.go
98 lines (84 loc) · 2.16 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
//Package po generated by 'freedom new-po'
package po
import (
"gorm.io/gorm"
"time"
)
// Order .
type Order struct {
changes map[string]interface{}
ID int `gorm:"primaryKey;column:id"`
OrderNo string `gorm:"column:order_no"`
UserID int `gorm:"column:user_id"` // 用户id
TotalPrice int `gorm:"column:total_price"` // 总价
Status string `gorm:"column:status"` // 支付,未支付,发货,完成
Created time.Time `gorm:"column:created"`
Updated time.Time `gorm:"column:updated"`
}
// TableName .
func (obj *Order) TableName() string {
return "order"
}
// Location .
func (obj *Order) Location() map[string]interface{} {
return map[string]interface{}{"id": obj.ID}
}
// GetChanges .
func (obj *Order) GetChanges() map[string]interface{} {
if obj.changes == nil {
return nil
}
result := make(map[string]interface{})
for k, v := range obj.changes {
result[k] = v
}
obj.changes = nil
return result
}
// Update .
func (obj *Order) Update(name string, value interface{}) {
if obj.changes == nil {
obj.changes = make(map[string]interface{})
}
obj.changes[name] = value
}
// SetOrderNo .
func (obj *Order) SetOrderNo(orderNo string) {
obj.OrderNo = orderNo
obj.Update("order_no", orderNo)
}
// SetUserID .
func (obj *Order) SetUserID(userID int) {
obj.UserID = userID
obj.Update("user_id", userID)
}
// SetTotalPrice .
func (obj *Order) SetTotalPrice(totalPrice int) {
obj.TotalPrice = totalPrice
obj.Update("total_price", totalPrice)
}
// SetStatus .
func (obj *Order) SetStatus(status string) {
obj.Status = status
obj.Update("status", status)
}
// SetCreated .
func (obj *Order) SetCreated(created time.Time) {
obj.Created = created
obj.Update("created", created)
}
// SetUpdated .
func (obj *Order) SetUpdated(updated time.Time) {
obj.Updated = updated
obj.Update("updated", updated)
}
// AddUserID .
func (obj *Order) AddUserID(userID int) {
obj.UserID += userID
obj.Update("user_id", gorm.Expr("user_id + ?", userID))
}
// AddTotalPrice .
func (obj *Order) AddTotalPrice(totalPrice int) {
obj.TotalPrice += totalPrice
obj.Update("total_price", gorm.Expr("total_price + ?", totalPrice))
}