正在显示
1 个修改的文件
包含
66 行增加
和
18 行删除
@@ -10,12 +10,12 @@ const ( | @@ -10,12 +10,12 @@ const ( | ||
10 | 10 | ||
11 | // 订单状态 | 11 | // 订单状态 |
12 | const ( | 12 | const ( |
13 | - ORDER_STATUS_SHIPPED = iota + 1 // 已发货 | ||
14 | - ORDER_STATUS_TRANSIT // 待收货 | ||
15 | - ORDER_STATUS_RECEIVED // 已收货 | ||
16 | - ORDER_STATUS_RETURNED // 已退货 | ||
17 | - ORDER_STATUS_CANCELED // 已取消 | ||
18 | - ORDER_STATUS_CLOSED // 已关闭 | 13 | + ORDER_STATUS_UNSHIPPED = iota + 1 // 待发货 |
14 | + ORDER_STATUS_TRANSIT // 待收货 | ||
15 | + ORDER_STATUS_RECEIVED // 已收货 | ||
16 | + ORDER_STATUS_RETURN // 退换货 | ||
17 | + ORDER_STATUS_CANCELED // 已取消(关闭) | ||
18 | + ORDER_STATUS_COMPLETED // 已完成 | ||
19 | ) | 19 | ) |
20 | 20 | ||
21 | // 订单实体 | 21 | // 订单实体 |
@@ -60,23 +60,21 @@ type Order struct { | @@ -60,23 +60,21 @@ type Order struct { | ||
60 | UpdateAt time.Time `json:"updateAt"` | 60 | UpdateAt time.Time `json:"updateAt"` |
61 | // 软删 | 61 | // 软删 |
62 | DeleteAt time.Time `json:"deleteAt"` | 62 | DeleteAt time.Time `json:"deleteAt"` |
63 | + // 当前状态 | ||
64 | + CurrentStatus OrderStatus `json:"-"` | ||
63 | } | 65 | } |
64 | 66 | ||
65 | -type OrderRepository interface { | ||
66 | - Save(order *Order) (*Order, error) | ||
67 | - Remove(order *Order) (*Order, error) | ||
68 | - FindOne(queryOptions map[string]interface{}) (*Order, error) | ||
69 | - Find(queryOptions map[string]interface{}) (int64, []*Order, error) | 67 | +type OrderStatus interface { |
68 | + Update(order *Order, data map[string]interface{}) error // 更新订单 | ||
69 | + Checkout(order *Order) error // 下单 | ||
70 | + Return(order *Order) error // 退换货 | ||
71 | + Cancel(order *Order) error // 取消订单 | ||
72 | + Receive(order *Order) error // 收货 | ||
70 | } | 73 | } |
71 | 74 | ||
72 | -func (order *Order) Identify() interface{} { | ||
73 | - if order.OrderId == 0 { | ||
74 | - return nil | ||
75 | - } | ||
76 | - return order.OrderId | ||
77 | -} | 75 | +type UnShippedStatus struct{} |
78 | 76 | ||
79 | -func (order *Order) Update(data map[string]interface{}) error { | 77 | +func (status *UnShippedStatus) Update(order *Order, data map[string]interface{}) error { |
80 | if orderId, ok := data["orderId"]; ok { | 78 | if orderId, ok := data["orderId"]; ok { |
81 | order.OrderId = orderId.(int64) | 79 | order.OrderId = orderId.(int64) |
82 | } | 80 | } |
@@ -190,3 +188,53 @@ func (order *Order) Update(data map[string]interface{}) error { | @@ -190,3 +188,53 @@ func (order *Order) Update(data map[string]interface{}) error { | ||
190 | } | 188 | } |
191 | return nil | 189 | return nil |
192 | } | 190 | } |
191 | + | ||
192 | +func (status *UnShippedStatus) Checkout(order *Order) error { | ||
193 | + return nil | ||
194 | +} | ||
195 | + | ||
196 | +func (status *UnShippedStatus) Return(order *Order) error { | ||
197 | + return nil | ||
198 | +} | ||
199 | + | ||
200 | +func (status *UnShippedStatus) Cancel(order *Order) error { | ||
201 | + return nil | ||
202 | +} | ||
203 | + | ||
204 | +func (status *UnShippedStatus) Receive(order *Order) error { | ||
205 | + return nil | ||
206 | +} | ||
207 | + | ||
208 | +type OrderRepository interface { | ||
209 | + Save(order *Order) (*Order, error) | ||
210 | + Remove(order *Order) (*Order, error) | ||
211 | + FindOne(queryOptions map[string]interface{}) (*Order, error) | ||
212 | + Find(queryOptions map[string]interface{}) (int64, []*Order, error) | ||
213 | +} | ||
214 | + | ||
215 | +func (order *Order) Identify() interface{} { | ||
216 | + if order.OrderId == 0 { | ||
217 | + return nil | ||
218 | + } | ||
219 | + return order.OrderId | ||
220 | +} | ||
221 | + | ||
222 | +func (order *Order) Update(data map[string]interface{}) error { | ||
223 | + return order.CurrentStatus.Update(order, data) | ||
224 | +} | ||
225 | + | ||
226 | +func (order *Order) Checkout() error { | ||
227 | + return order.CurrentStatus.Checkout(order) | ||
228 | +} | ||
229 | + | ||
230 | +func (order *Order) Return() error { | ||
231 | + return order.CurrentStatus.Return(order) | ||
232 | +} | ||
233 | + | ||
234 | +func (order *Order) Receive() error { | ||
235 | + return order.CurrentStatus.Receive(order) | ||
236 | +} | ||
237 | + | ||
238 | +func (order *Order) Cancel() error { | ||
239 | + return order.CurrentStatus.Cancel(order) | ||
240 | +} |
-
请 注册 或 登录 后发表评论