|
|
package domain
|
|
|
|
|
|
import "time"
|
|
|
import (
|
|
|
"fmt"
|
|
|
"time"
|
|
|
)
|
|
|
|
|
|
// 订单类型
|
|
|
const (
|
|
|
ORDER_TYPE_ACTUAL = iota + 1 //实际订单
|
|
|
ORDER_TYPE_INTENTION // 意向订单
|
|
|
)
|
|
|
|
|
|
// 订单状态
|
|
|
const (
|
|
|
ORDER_STATUS_UNSHIPPED = iota + 1 // 待发货
|
|
|
ORDER_STATUS_TRANSIT // 待收货(运输中)
|
|
|
ORDER_STATUS_RECEIVED // 已收货
|
|
|
ORDER_STATUS_RETURN // 退换货
|
|
|
ORDER_STATUS_CANCELED // 已取消(关闭)
|
|
|
ORDER_STATUS_COMPLETED // 已完成
|
|
|
)
|
|
|
|
|
|
// 订单实体
|
|
|
type Order struct {
|
...
|
...
|
@@ -44,23 +63,24 @@ type Order struct { |
|
|
UpdateAt time.Time `json:"updateAt"`
|
|
|
// 软删
|
|
|
DeleteAt time.Time `json:"deleteAt"`
|
|
|
// 当前状态
|
|
|
CurrentStatus OrderStatus `json:"-"`
|
|
|
}
|
|
|
|
|
|
type OrderRepository interface {
|
|
|
Save(order *Order) (*Order, error)
|
|
|
Remove(order *Order) (*Order, error)
|
|
|
FindOne(queryOptions map[string]interface{}) (*Order, error)
|
|
|
Find(queryOptions map[string]interface{}) (int64, []*Order, error)
|
|
|
// 订单状态机
|
|
|
type OrderStatus interface {
|
|
|
Update(order *Order, data map[string]interface{}) error // 更新订单
|
|
|
Checkout(order *Order) error // 下单
|
|
|
Return(order *Order) error // 退换货
|
|
|
Cancel(order *Order) error // 取消订单
|
|
|
Receive(order *Order) error // 收货
|
|
|
}
|
|
|
|
|
|
func (order *Order) Identify() interface{} {
|
|
|
if order.OrderId == 0 {
|
|
|
return nil
|
|
|
}
|
|
|
return order.OrderId
|
|
|
}
|
|
|
// 代发货状态
|
|
|
type UnShippedStatus struct{}
|
|
|
|
|
|
func (order *Order) Update(data map[string]interface{}) error {
|
|
|
// 编辑待发货订单
|
|
|
func (status *UnShippedStatus) Update(order *Order, data map[string]interface{}) error {
|
|
|
if orderId, ok := data["orderId"]; ok {
|
|
|
order.OrderId = orderId.(int64)
|
|
|
}
|
...
|
...
|
@@ -174,3 +194,170 @@ func (order *Order) Update(data map[string]interface{}) error { |
|
|
}
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
func (status *UnShippedStatus) Checkout(order *Order) error {
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
func (status *UnShippedStatus) Return(order *Order) error {
|
|
|
return fmt.Errorf("待发货订单不能退货")
|
|
|
}
|
|
|
|
|
|
func (status *UnShippedStatus) Cancel(order *Order) error {
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
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)
|
|
|
FindOne(queryOptions map[string]interface{}) (*Order, error)
|
|
|
Find(queryOptions map[string]interface{}) (int64, []*Order, error)
|
|
|
}
|
|
|
|
|
|
func (order *Order) Identify() interface{} {
|
|
|
if order.OrderId == 0 {
|
|
|
return nil
|
|
|
}
|
|
|
return order.OrderId
|
|
|
}
|
|
|
|
|
|
func (order *Order) Update(data map[string]interface{}) error {
|
|
|
return order.CurrentStatus.Update(order, data)
|
|
|
}
|
|
|
|
|
|
func (order *Order) Checkout() error {
|
|
|
return order.CurrentStatus.Checkout(order)
|
|
|
}
|
|
|
|
|
|
func (order *Order) Return() error {
|
|
|
return order.CurrentStatus.Return(order)
|
|
|
}
|
|
|
|
|
|
func (order *Order) Receive() error {
|
|
|
return order.CurrentStatus.Receive(order)
|
|
|
}
|
|
|
|
|
|
func (order *Order) Cancel() error {
|
|
|
return order.CurrentStatus.Cancel(order)
|
|
|
} |
...
|
...
|
|