正在显示
1 个修改的文件
包含
86 行增加
和
20 行删除
@@ -13,13 +13,14 @@ const ( | @@ -13,13 +13,14 @@ const ( | ||
13 | 13 | ||
14 | // 订单状态 | 14 | // 订单状态 |
15 | const ( | 15 | const ( |
16 | - ORDER_STATUS_UNSHIPPED = iota + 1 // 待发货 | ||
17 | - ORDER_STATUS_TRANSIT // 待收货(运输中) | ||
18 | - ORDER_STATUS_RECEIVED // 已收货 | ||
19 | - ORDER_STATUS_RETURN // 退换货 | ||
20 | - ORDER_STATUS_CANCELED // 已取消(关闭) | ||
21 | - ORDER_STATUS_COMPLETED // 已完成 | ||
22 | - ORDER_STATUS_CLOSED // 已关闭 | 16 | + ORDER_STATUS_UNSHIPPED = iota + 1 // 待发货 |
17 | + ORDER_STATUS_SHIPPING // 已发货 | ||
18 | + ORDER_STATUS_PART_SHIPPING // 部分发货 | ||
19 | + ORDER_STATUS_RECEIVED // 已收货 | ||
20 | + ORDER_STATUS_RETURN // 退换货 | ||
21 | + ORDER_STATUS_CANCELED // 已取消 | ||
22 | + ORDER_STATUS_COMPLETED // 已完成 | ||
23 | + ORDER_STATUS_CLOSED // 已关闭 | ||
23 | ) | 24 | ) |
24 | 25 | ||
25 | // 订单实体 | 26 | // 订单实体 |
@@ -73,8 +74,8 @@ type Order struct { | @@ -73,8 +74,8 @@ type Order struct { | ||
73 | // 订单状态机 | 74 | // 订单状态机 |
74 | type OrderStatus interface { | 75 | type OrderStatus interface { |
75 | Update(order *Order, data map[string]interface{}) error // 更新订单 | 76 | Update(order *Order, data map[string]interface{}) error // 更新订单 |
76 | - Shipping(order *Order) error // 发货 | ||
77 | - Return(order *Order) error // 退换/货 | 77 | + Shipping(order *Order) error // 发货(全部发货,部分发货) |
78 | + Return(order *Order) error // 退换货 | ||
78 | Cancel(order *Order) error // 取消订单 | 79 | Cancel(order *Order) error // 取消订单 |
79 | Receive(order *Order) error // 收货 | 80 | Receive(order *Order) error // 收货 |
80 | Close(order *Order) error // 关闭订单 | 81 | Close(order *Order) error // 关闭订单 |
@@ -204,7 +205,7 @@ func (status *UnShippedStatus) Shipping(order *Order) error { | @@ -204,7 +205,7 @@ func (status *UnShippedStatus) Shipping(order *Order) error { | ||
204 | currentTime := time.Now() | 205 | currentTime := time.Now() |
205 | order.DeliveryTime = currentTime | 206 | order.DeliveryTime = currentTime |
206 | if order.OrderType == ORDER_TYPE_INTENTION { | 207 | if order.OrderType == ORDER_TYPE_INTENTION { |
207 | - order.OrderStatus = ORDER_STATUS_TRANSIT | 208 | + order.OrderStatus = ORDER_STATUS_SHIPPING |
208 | order.CurrentStatus = &TransitStatus{} | 209 | order.CurrentStatus = &TransitStatus{} |
209 | } | 210 | } |
210 | return nil | 211 | return nil |
@@ -234,11 +235,6 @@ func (status *TransitStatus) Shipping(order *Order) error { | @@ -234,11 +235,6 @@ func (status *TransitStatus) Shipping(order *Order) error { | ||
234 | return fmt.Errorf("待收货订单不能重复发货") | 235 | return fmt.Errorf("待收货订单不能重复发货") |
235 | } | 236 | } |
236 | 237 | ||
237 | -// 待收货订单不能关闭 | ||
238 | -func (status *TransitStatus) Close(order *Order) error { | ||
239 | - return fmt.Errorf("待收货订单不能关闭") | ||
240 | -} | ||
241 | - | ||
242 | // 待收货订单不允许编辑 | 238 | // 待收货订单不允许编辑 |
243 | func (status *TransitStatus) Update(order *Order, data map[string]interface{}) error { | 239 | func (status *TransitStatus) Update(order *Order, data map[string]interface{}) error { |
244 | return fmt.Errorf("已发货订单不允许编辑") | 240 | return fmt.Errorf("已发货订单不允许编辑") |
@@ -261,10 +257,15 @@ func (status *TransitStatus) Receive(order *Order) error { | @@ -261,10 +257,15 @@ func (status *TransitStatus) Receive(order *Order) error { | ||
261 | return nil | 257 | return nil |
262 | } | 258 | } |
263 | 259 | ||
260 | +// 待收货订单不能关闭 | ||
261 | +func (status *TransitStatus) Close(order *Order) error { | ||
262 | + return fmt.Errorf("待收货订单不能关闭") | ||
263 | +} | ||
264 | + | ||
264 | // 收货状态 | 265 | // 收货状态 |
265 | type ReceivedStatus struct{} | 266 | type ReceivedStatus struct{} |
266 | 267 | ||
267 | -// 编辑订单 | 268 | +// 已收货订单不能编辑 |
268 | func (status *ReceivedStatus) Update(order *Order, data map[string]interface{}) error { | 269 | func (status *ReceivedStatus) Update(order *Order, data map[string]interface{}) error { |
269 | return fmt.Errorf("已收货订单不能编辑") | 270 | return fmt.Errorf("已收货订单不能编辑") |
270 | } | 271 | } |
@@ -292,6 +293,7 @@ func (status *ReceivedStatus) Receive(order *Order) error { | @@ -292,6 +293,7 @@ func (status *ReceivedStatus) Receive(order *Order) error { | ||
292 | 293 | ||
293 | // 关闭订单 | 294 | // 关闭订单 |
294 | func (status *ReceivedStatus) Close(order *Order) error { | 295 | func (status *ReceivedStatus) Close(order *Order) error { |
296 | + order.CurrentStatus = &ClosedStatus{} | ||
295 | return nil | 297 | return nil |
296 | } | 298 | } |
297 | 299 | ||
@@ -323,9 +325,9 @@ func (status *ReturnedStatus) Receive(order *Order) error { | @@ -323,9 +325,9 @@ func (status *ReturnedStatus) Receive(order *Order) error { | ||
323 | return fmt.Errorf("已退货订单不能收货") | 325 | return fmt.Errorf("已退货订单不能收货") |
324 | } | 326 | } |
325 | 327 | ||
326 | -// 关闭订单 | 328 | +// 关闭已退货订单 |
327 | func (status *ReturnedStatus) Close(order *Order) error { | 329 | func (status *ReturnedStatus) Close(order *Order) error { |
328 | - | 330 | + order.CurrentStatus = &ClosedStatus{} |
329 | return nil | 331 | return nil |
330 | } | 332 | } |
331 | 333 | ||
@@ -359,6 +361,7 @@ func (status *CanceledStatus) Receive(order *Order) error { | @@ -359,6 +361,7 @@ func (status *CanceledStatus) Receive(order *Order) error { | ||
359 | 361 | ||
360 | // 关闭订单 | 362 | // 关闭订单 |
361 | func (status *CanceledStatus) Close(order *Order) error { | 363 | func (status *CanceledStatus) Close(order *Order) error { |
364 | + order.CurrentStatus = &ClosedStatus{} | ||
362 | return nil | 365 | return nil |
363 | } | 366 | } |
364 | 367 | ||
@@ -367,7 +370,36 @@ type CompletedStatus struct{} | @@ -367,7 +370,36 @@ type CompletedStatus struct{} | ||
367 | 370 | ||
368 | // 编辑已完成订单分红 | 371 | // 编辑已完成订单分红 |
369 | func (status *CompletedStatus) Update(order *Order, data map[string]interface{}) error { | 372 | func (status *CompletedStatus) Update(order *Order, data map[string]interface{}) error { |
370 | - | 373 | + if planBonus, ok := data["planBonus"]; ok { |
374 | + order.OrderDividend.PlanBonus = planBonus.(float64) | ||
375 | + } | ||
376 | + if useBonus, ok := data["useBonus"]; ok { | ||
377 | + order.OrderDividend.UseBonus = useBonus.(float64) | ||
378 | + } | ||
379 | + if bonusHas, ok := data["bonusHas"]; ok { | ||
380 | + order.OrderDividend.BonusHas = bonusHas.(float64) | ||
381 | + } | ||
382 | + if bonusNot, ok := data["bonusNot"]; ok { | ||
383 | + order.OrderDividend.BonusNot = bonusNot.(float64) | ||
384 | + } | ||
385 | + if bonusExpense, ok := data["bonusExpense"]; ok { | ||
386 | + order.OrderDividend.BonusExpense = bonusExpense.(float64) | ||
387 | + } | ||
388 | + if bonusStatus, ok := data["bonusStatus"]; ok { | ||
389 | + order.OrderDividend.BonusStatus = bonusStatus.(int) | ||
390 | + } | ||
391 | + if partnerBonusPercent, ok := data["partnerBonusPercent"]; ok { | ||
392 | + order.OrderDividend.PartnerBonusPercent = partnerBonusPercent.(float64) | ||
393 | + } | ||
394 | + if salesmanBonusPercent, ok := data["salesmanBonusPercent"]; ok { | ||
395 | + order.OrderDividend.SalesmanBonusPercent = salesmanBonusPercent.(float64) | ||
396 | + } | ||
397 | + if salesmanBonus, ok := data["salesmanBonus"]; ok { | ||
398 | + order.OrderDividend.SalesmanBonus = salesmanBonus.(float64) | ||
399 | + } | ||
400 | + if orderDividendStatus, ok := data["orderDividendStatus"]; ok { | ||
401 | + order.OrderDividendStatus = orderDividendStatus.(int) | ||
402 | + } | ||
371 | return nil | 403 | return nil |
372 | } | 404 | } |
373 | 405 | ||
@@ -393,12 +425,46 @@ func (status *CompletedStatus) Receive(order *Order) error { | @@ -393,12 +425,46 @@ func (status *CompletedStatus) Receive(order *Order) error { | ||
393 | 425 | ||
394 | // 关闭已完成订单 | 426 | // 关闭已完成订单 |
395 | func (status *CompletedStatus) Close(order *Order) error { | 427 | func (status *CompletedStatus) Close(order *Order) error { |
428 | + order.CurrentStatus = &ClosedStatus{} | ||
396 | return nil | 429 | return nil |
397 | } | 430 | } |
398 | 431 | ||
432 | +// 关闭状态 | ||
433 | +type ClosedStatus struct{} | ||
434 | + | ||
435 | +// 已关闭订单不能进行编辑 | ||
436 | +func (status *ClosedStatus) Update(order *Order, data map[string]interface{}) error { | ||
437 | + return fmt.Errorf("已关闭订单不能进行编辑") | ||
438 | +} | ||
439 | + | ||
440 | +// 已关闭订单不能发货 | ||
441 | +func (status *ClosedStatus) Shipping(order *Order) error { | ||
442 | + return fmt.Errorf("已关闭订单不能发货") | ||
443 | +} | ||
444 | + | ||
445 | +// 已关闭订单不能退货 | ||
446 | +func (status *ClosedStatus) Return(order *Order) error { | ||
447 | + return fmt.Errorf("已关闭订单不能退货") | ||
448 | +} | ||
449 | + | ||
450 | +// 已关闭订单不能取消 | ||
451 | +func (status *ClosedStatus) Cancel(order *Order) error { | ||
452 | + return fmt.Errorf("已关闭订单不能取消") | ||
453 | +} | ||
454 | + | ||
455 | +// 已关闭订单不能收货 | ||
456 | +func (status *ClosedStatus) Receive(order *Order) error { | ||
457 | + return fmt.Errorf("已关闭订单不能收货") | ||
458 | +} | ||
459 | + | ||
460 | +// 已关闭订单不能再次关闭 | ||
461 | +func (status *ClosedStatus) Close(order *Order) error { | ||
462 | + return fmt.Errorf("已关闭订单不能再次关闭") | ||
463 | +} | ||
464 | + | ||
399 | // 订单仓储 | 465 | // 订单仓储 |
400 | type OrderRepository interface { | 466 | type OrderRepository interface { |
401 | - Save(order *Order) (*Order, error) // 下单/编辑订单 | 467 | + Save(order *Order) (*Order, error) |
402 | Remove(order *Order) (*Order, error) | 468 | Remove(order *Order) (*Order, error) |
403 | FindOne(queryOptions map[string]interface{}) (*Order, error) | 469 | FindOne(queryOptions map[string]interface{}) (*Order, error) |
404 | Find(queryOptions map[string]interface{}) (int64, []*Order, error) | 470 | Find(queryOptions map[string]interface{}) (int64, []*Order, error) |
-
请 注册 或 登录 后发表评论