|
|
package domain
|
|
|
|
|
|
import "time"
|
|
|
import (
|
|
|
"fmt"
|
|
|
"time"
|
|
|
)
|
|
|
|
|
|
// 订单类型
|
|
|
const (
|
...
|
...
|
@@ -11,7 +14,7 @@ const ( |
|
|
// 订单状态
|
|
|
const (
|
|
|
ORDER_STATUS_UNSHIPPED = iota + 1 // 待发货
|
|
|
ORDER_STATUS_TRANSIT // 待收货
|
|
|
ORDER_STATUS_TRANSIT // 待收货(运输中)
|
|
|
ORDER_STATUS_RECEIVED // 已收货
|
|
|
ORDER_STATUS_RETURN // 退换货
|
|
|
ORDER_STATUS_CANCELED // 已取消(关闭)
|
...
|
...
|
@@ -64,6 +67,7 @@ type Order struct { |
|
|
CurrentStatus OrderStatus `json:"-"`
|
|
|
}
|
|
|
|
|
|
// 订单状态机
|
|
|
type OrderStatus interface {
|
|
|
Update(order *Order, data map[string]interface{}) error // 更新订单
|
|
|
Checkout(order *Order) error // 下单
|
...
|
...
|
@@ -72,8 +76,10 @@ type OrderStatus interface { |
|
|
Receive(order *Order) error // 收货
|
|
|
}
|
|
|
|
|
|
// 代发货状态
|
|
|
type UnShippedStatus struct{}
|
|
|
|
|
|
// 编辑待发货订单
|
|
|
func (status *UnShippedStatus) Update(order *Order, data map[string]interface{}) error {
|
|
|
if orderId, ok := data["orderId"]; ok {
|
|
|
order.OrderId = orderId.(int64)
|
...
|
...
|
@@ -194,7 +200,7 @@ func (status *UnShippedStatus) Checkout(order *Order) error { |
|
|
}
|
|
|
|
|
|
func (status *UnShippedStatus) Return(order *Order) error {
|
|
|
return nil
|
|
|
return fmt.Errorf("待发货订单不能退货")
|
|
|
}
|
|
|
|
|
|
func (status *UnShippedStatus) Cancel(order *Order) error {
|
...
|
...
|
@@ -202,9 +208,126 @@ func (status *UnShippedStatus) Cancel(order *Order) error { |
|
|
}
|
|
|
|
|
|
func (status *UnShippedStatus) Receive(order *Order) error {
|
|
|
return fmt.Errorf("待发货订单不能收货")
|
|
|
}
|
|
|
|
|
|
// 待收货状态
|
|
|
type TransitStatus struct{}
|
|
|
|
|
|
// 待收货订单不允许编辑
|
|
|
func (status *TransitStatus) Update(order *Order, data map[string]interface{}) error {
|
|
|
return fmt.Errorf("已发货订单不允许编辑")
|
|
|
}
|
|
|
|
|
|
func (status *TransitStatus) Checkout(order *Order) error {
|
|
|
return fmt.Errorf("待收货订单不能重复发货")
|
|
|
}
|
|
|
|
|
|
func (status *TransitStatus) Return(order *Order) error {
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
func (status *TransitStatus) Cancel(order *Order) error {
|
|
|
return fmt.Errorf("待收货订单不能取消")
|
|
|
}
|
|
|
|
|
|
func (status *TransitStatus) Receive(order *Order) error {
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
// 收货状态
|
|
|
type ReceivedStatus struct{}
|
|
|
|
|
|
func (status *ReceivedStatus) Update(order *Order, data map[string]interface{}) error {
|
|
|
return fmt.Errorf("已收货订单不能编辑")
|
|
|
}
|
|
|
|
|
|
func (status *ReceivedStatus) Checkout(order *Order) error {
|
|
|
return fmt.Errorf("已收货订单不能重复发货")
|
|
|
}
|
|
|
|
|
|
func (status *ReceivedStatus) Return(order *Order) error {
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
func (status *ReceivedStatus) Cancel(order *Order) error {
|
|
|
return fmt.Errorf("已收货订单不能取消")
|
|
|
}
|
|
|
|
|
|
func (status *ReceivedStatus) Receive(order *Order) error {
|
|
|
return fmt.Errorf("已收货订单不能重复收货")
|
|
|
}
|
|
|
|
|
|
// 退货状态
|
|
|
type ReturnedStatus struct{}
|
|
|
|
|
|
func (status *ReturnedStatus) Update(order *Order, data map[string]interface{}) error {
|
|
|
return fmt.Errorf("已退货订单不允许编辑")
|
|
|
}
|
|
|
|
|
|
func (status *ReturnedStatus) Checkout(order *Order) error {
|
|
|
return fmt.Errorf("已退货订单不允许发货")
|
|
|
}
|
|
|
|
|
|
func (status *ReturnedStatus) Return(order *Order) error {
|
|
|
return fmt.Errorf("已退货订单不允许再次退货")
|
|
|
}
|
|
|
|
|
|
func (status *ReturnedStatus) Cancel(order *Order) error {
|
|
|
return fmt.Errorf("已退货订单不能取消")
|
|
|
}
|
|
|
|
|
|
func (status *ReturnedStatus) Receive(order *Order) error {
|
|
|
return fmt.Errorf("已退货订单不能收货")
|
|
|
}
|
|
|
|
|
|
// 取消状态
|
|
|
type CanceledStatus struct{}
|
|
|
|
|
|
func (status *CanceledStatus) Update(order *Order, dat map[string]interface{}) error {
|
|
|
return fmt.Errorf("已取消订单不能编辑")
|
|
|
}
|
|
|
|
|
|
func (status *CanceledStatus) Checkout(order *Order) error {
|
|
|
return fmt.Errorf("已取消订单不能发货")
|
|
|
}
|
|
|
|
|
|
func (status *CanceledStatus) Return(order *Order) error {
|
|
|
return fmt.Errorf("已取消订单不能退货")
|
|
|
}
|
|
|
|
|
|
func (status *CanceledStatus) Cancel(order *Order) error {
|
|
|
return fmt.Errorf("已取消订单不能再次取消")
|
|
|
}
|
|
|
|
|
|
func (status *CanceledStatus) Receive(order *Order) error {
|
|
|
return fmt.Errorf("已取消订单不能进行收货")
|
|
|
}
|
|
|
|
|
|
// 已完成状态
|
|
|
type CompletedStatus struct{}
|
|
|
|
|
|
func (status *CompletedStatus) Update(order *Order, data map[string]interface{}) error {
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
func (status *CompletedStatus) Checkout(order *Order) error {
|
|
|
return fmt.Errorf("已完成订单不能发货")
|
|
|
}
|
|
|
|
|
|
func (status *CompletedStatus) Return(order *Order) error {
|
|
|
return fmt.Errorf("已完成订单不能退货")
|
|
|
}
|
|
|
|
|
|
func (status *CompletedStatus) Cancel(order *Order) error {
|
|
|
return fmt.Errorf("已完成订单不能取消")
|
|
|
}
|
|
|
|
|
|
func (status *CompletedStatus) Receive(order *Order) error {
|
|
|
return fmt.Errorf("已完成订单不能收货")
|
|
|
}
|
|
|
|
|
|
// 订单仓储
|
|
|
type OrderRepository interface {
|
|
|
Save(order *Order) (*Order, error)
|
|
|
Remove(order *Order) (*Order, error)
|
...
|
...
|
|