作者 陈志颖

feat:更新订单状态机

version: v1
kind: Attribute
metadata:
name: deliveryTime
description: 发货时间
type:
primitive: datetime
... ...
... ... @@ -14,6 +14,8 @@ metadata:
required: true
- ref: deliveryCode
required: true
- ref: delieveryTime
required: true
- ref: isDisable
required: true
- ref: orderNo
... ...
... ... @@ -19,6 +19,7 @@ const (
ORDER_STATUS_RETURN // 退换货
ORDER_STATUS_CANCELED // 已取消(关闭)
ORDER_STATUS_COMPLETED // 已完成
ORDER_STATUS_CLOSED // 已关闭
)
// 订单实体
... ... @@ -33,6 +34,8 @@ type Order struct {
PartnerId int64 `json:"partnerId"`
// 发货单号
DeliveryCode string `json:"deliveryCode"`
// 发货时间
DeliveryTime time.Time `json:"deliveryTime"`
// 是否关闭订单标志
IsDisable int `json:"isDisable"`
// 订单编号
... ... @@ -71,12 +74,13 @@ type Order struct {
type OrderStatus interface {
Update(order *Order, data map[string]interface{}) error // 更新订单
Checkout(order *Order) error // 下单
Return(order *Order) error // 退换货
Return(order *Order) error // 退换/
Cancel(order *Order) error // 取消订单
Receive(order *Order) error // 收货
Close(order *Order) error // 关闭订单
}
// 发货状态
// 发货状态
type UnShippedStatus struct{}
// 编辑待发货订单
... ... @@ -195,18 +199,29 @@ func (status *UnShippedStatus) Update(order *Order, data map[string]interface{})
return nil
}
// 发货
func (status *UnShippedStatus) Checkout(order *Order) error {
currentTime := time.Now()
order.DeliveryTime = currentTime
if order.OrderType == ORDER_TYPE_INTENTION {
order.OrderStatus = ORDER_STATUS_TRANSIT
order.CurrentStatus = &TransitStatus{}
}
return nil
}
// 退货
func (status *UnShippedStatus) Return(order *Order) error {
return fmt.Errorf("待发货订单不能退货")
}
// 取消订单
func (status *UnShippedStatus) Cancel(order *Order) error {
order.CurrentStatus = &CanceledStatus{}
return nil
}
// 收货
func (status *UnShippedStatus) Receive(order *Order) error {
return fmt.Errorf("待发货订单不能收货")
}
... ... @@ -214,73 +229,102 @@ func (status *UnShippedStatus) Receive(order *Order) error {
// 待收货状态
type TransitStatus struct{}
func (status *TransitStatus) Close(order *Order) error {
panic("implement me")
}
// 待收货订单不允许编辑
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 {
order.CurrentStatus = &ReturnedStatus{}
return nil
}
// 待收货订单不能取消
func (status *TransitStatus) Cancel(order *Order) error {
return fmt.Errorf("待收货订单不能取消")
}
// 收货
func (status *TransitStatus) Receive(order *Order) error {
order.CurrentStatus = &ReceivedStatus{}
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 {
order.CurrentStatus = &ReturnedStatus{}
return nil
}
// 取消订单
func (status *ReceivedStatus) Cancel(order *Order) error {
return fmt.Errorf("已收货订单不能取消")
}
// 收货
func (status *ReceivedStatus) Receive(order *Order) error {
return fmt.Errorf("已收货订单不能重复收货")
}
func (status *ReceivedStatus) Close(order *Order) error {
panic("implement me")
}
// 退货状态
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("已退货订单不能收货")
}
func (status *ReturnedStatus) Close(order *Order) error {
panic("implement me")
}
// 取消状态
type CanceledStatus struct{}
... ... @@ -304,10 +348,15 @@ func (status *CanceledStatus) Receive(order *Order) error {
return fmt.Errorf("已取消订单不能进行收货")
}
func (status *CanceledStatus) Close(order *Order) error {
panic("implement me")
}
// 已完成状态
type CompletedStatus struct{}
func (status *CompletedStatus) Update(order *Order, data map[string]interface{}) error {
return nil
}
... ...