正在显示
1 个修改的文件
包含
126 行增加
和
3 行删除
1 | package domain | 1 | package domain |
2 | 2 | ||
3 | -import "time" | 3 | +import ( |
4 | + "fmt" | ||
5 | + "time" | ||
6 | +) | ||
4 | 7 | ||
5 | // 订单类型 | 8 | // 订单类型 |
6 | const ( | 9 | const ( |
@@ -11,7 +14,7 @@ const ( | @@ -11,7 +14,7 @@ const ( | ||
11 | // 订单状态 | 14 | // 订单状态 |
12 | const ( | 15 | const ( |
13 | ORDER_STATUS_UNSHIPPED = iota + 1 // 待发货 | 16 | ORDER_STATUS_UNSHIPPED = iota + 1 // 待发货 |
14 | - ORDER_STATUS_TRANSIT // 待收货 | 17 | + ORDER_STATUS_TRANSIT // 待收货(运输中) |
15 | ORDER_STATUS_RECEIVED // 已收货 | 18 | ORDER_STATUS_RECEIVED // 已收货 |
16 | ORDER_STATUS_RETURN // 退换货 | 19 | ORDER_STATUS_RETURN // 退换货 |
17 | ORDER_STATUS_CANCELED // 已取消(关闭) | 20 | ORDER_STATUS_CANCELED // 已取消(关闭) |
@@ -64,6 +67,7 @@ type Order struct { | @@ -64,6 +67,7 @@ type Order struct { | ||
64 | CurrentStatus OrderStatus `json:"-"` | 67 | CurrentStatus OrderStatus `json:"-"` |
65 | } | 68 | } |
66 | 69 | ||
70 | +// 订单状态机 | ||
67 | type OrderStatus interface { | 71 | type OrderStatus interface { |
68 | Update(order *Order, data map[string]interface{}) error // 更新订单 | 72 | Update(order *Order, data map[string]interface{}) error // 更新订单 |
69 | Checkout(order *Order) error // 下单 | 73 | Checkout(order *Order) error // 下单 |
@@ -72,8 +76,10 @@ type OrderStatus interface { | @@ -72,8 +76,10 @@ type OrderStatus interface { | ||
72 | Receive(order *Order) error // 收货 | 76 | Receive(order *Order) error // 收货 |
73 | } | 77 | } |
74 | 78 | ||
79 | +// 代发货状态 | ||
75 | type UnShippedStatus struct{} | 80 | type UnShippedStatus struct{} |
76 | 81 | ||
82 | +// 编辑待发货订单 | ||
77 | func (status *UnShippedStatus) Update(order *Order, data map[string]interface{}) error { | 83 | func (status *UnShippedStatus) Update(order *Order, data map[string]interface{}) error { |
78 | if orderId, ok := data["orderId"]; ok { | 84 | if orderId, ok := data["orderId"]; ok { |
79 | order.OrderId = orderId.(int64) | 85 | order.OrderId = orderId.(int64) |
@@ -194,7 +200,7 @@ func (status *UnShippedStatus) Checkout(order *Order) error { | @@ -194,7 +200,7 @@ func (status *UnShippedStatus) Checkout(order *Order) error { | ||
194 | } | 200 | } |
195 | 201 | ||
196 | func (status *UnShippedStatus) Return(order *Order) error { | 202 | func (status *UnShippedStatus) Return(order *Order) error { |
197 | - return nil | 203 | + return fmt.Errorf("待发货订单不能退货") |
198 | } | 204 | } |
199 | 205 | ||
200 | func (status *UnShippedStatus) Cancel(order *Order) error { | 206 | func (status *UnShippedStatus) Cancel(order *Order) error { |
@@ -202,9 +208,126 @@ func (status *UnShippedStatus) Cancel(order *Order) error { | @@ -202,9 +208,126 @@ func (status *UnShippedStatus) Cancel(order *Order) error { | ||
202 | } | 208 | } |
203 | 209 | ||
204 | func (status *UnShippedStatus) Receive(order *Order) error { | 210 | func (status *UnShippedStatus) Receive(order *Order) error { |
211 | + return fmt.Errorf("待发货订单不能收货") | ||
212 | +} | ||
213 | + | ||
214 | +// 待收货状态 | ||
215 | +type TransitStatus struct{} | ||
216 | + | ||
217 | +// 待收货订单不允许编辑 | ||
218 | +func (status *TransitStatus) Update(order *Order, data map[string]interface{}) error { | ||
219 | + return fmt.Errorf("已发货订单不允许编辑") | ||
220 | +} | ||
221 | + | ||
222 | +func (status *TransitStatus) Checkout(order *Order) error { | ||
223 | + return fmt.Errorf("待收货订单不能重复发货") | ||
224 | +} | ||
225 | + | ||
226 | +func (status *TransitStatus) Return(order *Order) error { | ||
227 | + return nil | ||
228 | +} | ||
229 | + | ||
230 | +func (status *TransitStatus) Cancel(order *Order) error { | ||
231 | + return fmt.Errorf("待收货订单不能取消") | ||
232 | +} | ||
233 | + | ||
234 | +func (status *TransitStatus) Receive(order *Order) error { | ||
235 | + return nil | ||
236 | +} | ||
237 | + | ||
238 | +// 收货状态 | ||
239 | +type ReceivedStatus struct{} | ||
240 | + | ||
241 | +func (status *ReceivedStatus) Update(order *Order, data map[string]interface{}) error { | ||
242 | + return fmt.Errorf("已收货订单不能编辑") | ||
243 | +} | ||
244 | + | ||
245 | +func (status *ReceivedStatus) Checkout(order *Order) error { | ||
246 | + return fmt.Errorf("已收货订单不能重复发货") | ||
247 | +} | ||
248 | + | ||
249 | +func (status *ReceivedStatus) Return(order *Order) error { | ||
250 | + return nil | ||
251 | +} | ||
252 | + | ||
253 | +func (status *ReceivedStatus) Cancel(order *Order) error { | ||
254 | + return fmt.Errorf("已收货订单不能取消") | ||
255 | +} | ||
256 | + | ||
257 | +func (status *ReceivedStatus) Receive(order *Order) error { | ||
258 | + return fmt.Errorf("已收货订单不能重复收货") | ||
259 | +} | ||
260 | + | ||
261 | +// 退货状态 | ||
262 | +type ReturnedStatus struct{} | ||
263 | + | ||
264 | +func (status *ReturnedStatus) Update(order *Order, data map[string]interface{}) error { | ||
265 | + return fmt.Errorf("已退货订单不允许编辑") | ||
266 | +} | ||
267 | + | ||
268 | +func (status *ReturnedStatus) Checkout(order *Order) error { | ||
269 | + return fmt.Errorf("已退货订单不允许发货") | ||
270 | +} | ||
271 | + | ||
272 | +func (status *ReturnedStatus) Return(order *Order) error { | ||
273 | + return fmt.Errorf("已退货订单不允许再次退货") | ||
274 | +} | ||
275 | + | ||
276 | +func (status *ReturnedStatus) Cancel(order *Order) error { | ||
277 | + return fmt.Errorf("已退货订单不能取消") | ||
278 | +} | ||
279 | + | ||
280 | +func (status *ReturnedStatus) Receive(order *Order) error { | ||
281 | + return fmt.Errorf("已退货订单不能收货") | ||
282 | +} | ||
283 | + | ||
284 | +// 取消状态 | ||
285 | +type CanceledStatus struct{} | ||
286 | + | ||
287 | +func (status *CanceledStatus) Update(order *Order, dat map[string]interface{}) error { | ||
288 | + return fmt.Errorf("已取消订单不能编辑") | ||
289 | +} | ||
290 | + | ||
291 | +func (status *CanceledStatus) Checkout(order *Order) error { | ||
292 | + return fmt.Errorf("已取消订单不能发货") | ||
293 | +} | ||
294 | + | ||
295 | +func (status *CanceledStatus) Return(order *Order) error { | ||
296 | + return fmt.Errorf("已取消订单不能退货") | ||
297 | +} | ||
298 | + | ||
299 | +func (status *CanceledStatus) Cancel(order *Order) error { | ||
300 | + return fmt.Errorf("已取消订单不能再次取消") | ||
301 | +} | ||
302 | + | ||
303 | +func (status *CanceledStatus) Receive(order *Order) error { | ||
304 | + return fmt.Errorf("已取消订单不能进行收货") | ||
305 | +} | ||
306 | + | ||
307 | +// 已完成状态 | ||
308 | +type CompletedStatus struct{} | ||
309 | + | ||
310 | +func (status *CompletedStatus) Update(order *Order, data map[string]interface{}) error { | ||
205 | return nil | 311 | return nil |
206 | } | 312 | } |
207 | 313 | ||
314 | +func (status *CompletedStatus) Checkout(order *Order) error { | ||
315 | + return fmt.Errorf("已完成订单不能发货") | ||
316 | +} | ||
317 | + | ||
318 | +func (status *CompletedStatus) Return(order *Order) error { | ||
319 | + return fmt.Errorf("已完成订单不能退货") | ||
320 | +} | ||
321 | + | ||
322 | +func (status *CompletedStatus) Cancel(order *Order) error { | ||
323 | + return fmt.Errorf("已完成订单不能取消") | ||
324 | +} | ||
325 | + | ||
326 | +func (status *CompletedStatus) Receive(order *Order) error { | ||
327 | + return fmt.Errorf("已完成订单不能收货") | ||
328 | +} | ||
329 | + | ||
330 | +// 订单仓储 | ||
208 | type OrderRepository interface { | 331 | type OrderRepository interface { |
209 | Save(order *Order) (*Order, error) | 332 | Save(order *Order) (*Order, error) |
210 | Remove(order *Order) (*Order, error) | 333 | Remove(order *Order) (*Order, error) |
-
请 注册 或 登录 后发表评论