This repository has been archived by the owner on Dec 13, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathorder.go
79 lines (70 loc) · 1.86 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
package shopy
const (
// OrderCanceled represents the order canceled status.
OrderCanceled = -1
// OrderPaymentWaiting represents an waiting payment status.
OrderPaymentWaiting = 0
// OrderPaymentDone represents the payment done status.
OrderPaymentDone = 1
// OrderPaymentFailed represents the failed payment status.
OrderPaymentFailed = 2
// OrderUnfulfilled represents a unfulfilled order.
OrderUnfulfilled = 0
// OrderFulfilled represents a fulfilled order.
OrderFulfilled = 1
)
// Order ...
type Order struct {
ID int
PayPal string
Value int
PaymentStatus int16
FulfillmentStatus int16
Credits int
User *User
Promocode *Promocode
Products []*OrderProduct
}
// PaymentStatusText returns the text corresponding to the status variable.
func (o *Order) PaymentStatusText() string {
switch o.PaymentStatus {
case OrderPaymentWaiting:
return "Waiting"
case OrderPaymentDone:
return "Done"
case OrderPaymentFailed:
return "Failed"
case OrderCanceled:
return "Canceled"
}
return "Unknown"
}
// FulfillmentStatusText returns the text corresponding to the status variable.
func (o *Order) FulfillmentStatusText() string {
switch o.FulfillmentStatus {
case OrderFulfilled:
return "Fulfilled"
case OrderUnfulfilled:
return "Unfulfilled"
case OrderCanceled:
return "Canceled"
}
return "Unknown"
}
// OrderProduct ...
type OrderProduct struct {
ID int
Name string
Quantity int `db:"quantity"`
}
// OrderService ...
type OrderService interface {
Get(id int) (*Order, error)
GetByPayPal(token string) (*Order, error)
Gets(first, limit int, order string) ([]*Order, error)
GetsWhere(first, limit int, order, where, sth string) ([]*Order, error)
Total() (int, error)
Create(o *Order) error
Update(o *Order, fields ...string) error
Delete(id int) error
}