作者 陈志颖
提交者 yangfu

feat:更新已完成订单编辑

... ... @@ -13,13 +13,14 @@ const (
// 订单状态
const (
ORDER_STATUS_UNSHIPPED = iota + 1 // 待发货
ORDER_STATUS_TRANSIT // 待收货(运输中)
ORDER_STATUS_RECEIVED // 已收货
ORDER_STATUS_RETURN // 退换货
ORDER_STATUS_CANCELED // 已取消(关闭)
ORDER_STATUS_COMPLETED // 已完成
ORDER_STATUS_CLOSED // 已关闭
ORDER_STATUS_UNSHIPPED = iota + 1 // 待发货
ORDER_STATUS_SHIPPING // 已发货
ORDER_STATUS_PART_SHIPPING // 部分发货
ORDER_STATUS_RECEIVED // 已收货
ORDER_STATUS_RETURN // 退换货
ORDER_STATUS_CANCELED // 已取消
ORDER_STATUS_COMPLETED // 已完成
ORDER_STATUS_CLOSED // 已关闭
)
// 订单实体
... ... @@ -73,8 +74,8 @@ type Order struct {
// 订单状态机
type OrderStatus interface {
Update(order *Order, data map[string]interface{}) error // 更新订单
Shipping(order *Order) error // 发货
Return(order *Order) error // 退换/货
Shipping(order *Order) error // 发货(全部发货,部分发货)
Return(order *Order) error // 退换货
Cancel(order *Order) error // 取消订单
Receive(order *Order) error // 收货
Close(order *Order) error // 关闭订单
... ... @@ -204,7 +205,7 @@ func (status *UnShippedStatus) Shipping(order *Order) error {
currentTime := time.Now()
order.DeliveryTime = currentTime
if order.OrderType == ORDER_TYPE_INTENTION {
order.OrderStatus = ORDER_STATUS_TRANSIT
order.OrderStatus = ORDER_STATUS_SHIPPING
order.CurrentStatus = &TransitStatus{}
}
return nil
... ... @@ -234,11 +235,6 @@ func (status *TransitStatus) Shipping(order *Order) error {
return fmt.Errorf("待收货订单不能重复发货")
}
// 待收货订单不能关闭
func (status *TransitStatus) Close(order *Order) error {
return fmt.Errorf("待收货订单不能关闭")
}
// 待收货订单不允许编辑
func (status *TransitStatus) Update(order *Order, data map[string]interface{}) error {
return fmt.Errorf("已发货订单不允许编辑")
... ... @@ -261,10 +257,15 @@ func (status *TransitStatus) Receive(order *Order) error {
return nil
}
// 待收货订单不能关闭
func (status *TransitStatus) Close(order *Order) error {
return fmt.Errorf("待收货订单不能关闭")
}
// 收货状态
type ReceivedStatus struct{}
// 编辑订单
// 已收货订单不能编辑
func (status *ReceivedStatus) Update(order *Order, data map[string]interface{}) error {
return fmt.Errorf("已收货订单不能编辑")
}
... ... @@ -292,6 +293,7 @@ func (status *ReceivedStatus) Receive(order *Order) error {
// 关闭订单
func (status *ReceivedStatus) Close(order *Order) error {
order.CurrentStatus = &ClosedStatus{}
return nil
}
... ... @@ -323,9 +325,9 @@ func (status *ReturnedStatus) Receive(order *Order) error {
return fmt.Errorf("已退货订单不能收货")
}
// 关闭订单
// 关闭已退货订单
func (status *ReturnedStatus) Close(order *Order) error {
order.CurrentStatus = &ClosedStatus{}
return nil
}
... ... @@ -359,6 +361,7 @@ func (status *CanceledStatus) Receive(order *Order) error {
// 关闭订单
func (status *CanceledStatus) Close(order *Order) error {
order.CurrentStatus = &ClosedStatus{}
return nil
}
... ... @@ -367,7 +370,36 @@ type CompletedStatus struct{}
// 编辑已完成订单分红
func (status *CompletedStatus) Update(order *Order, data map[string]interface{}) error {
if planBonus, ok := data["planBonus"]; ok {
order.OrderDividend.PlanBonus = planBonus.(float64)
}
if useBonus, ok := data["useBonus"]; ok {
order.OrderDividend.UseBonus = useBonus.(float64)
}
if bonusHas, ok := data["bonusHas"]; ok {
order.OrderDividend.BonusHas = bonusHas.(float64)
}
if bonusNot, ok := data["bonusNot"]; ok {
order.OrderDividend.BonusNot = bonusNot.(float64)
}
if bonusExpense, ok := data["bonusExpense"]; ok {
order.OrderDividend.BonusExpense = bonusExpense.(float64)
}
if bonusStatus, ok := data["bonusStatus"]; ok {
order.OrderDividend.BonusStatus = bonusStatus.(int)
}
if partnerBonusPercent, ok := data["partnerBonusPercent"]; ok {
order.OrderDividend.PartnerBonusPercent = partnerBonusPercent.(float64)
}
if salesmanBonusPercent, ok := data["salesmanBonusPercent"]; ok {
order.OrderDividend.SalesmanBonusPercent = salesmanBonusPercent.(float64)
}
if salesmanBonus, ok := data["salesmanBonus"]; ok {
order.OrderDividend.SalesmanBonus = salesmanBonus.(float64)
}
if orderDividendStatus, ok := data["orderDividendStatus"]; ok {
order.OrderDividendStatus = orderDividendStatus.(int)
}
return nil
}
... ... @@ -393,12 +425,46 @@ func (status *CompletedStatus) Receive(order *Order) error {
// 关闭已完成订单
func (status *CompletedStatus) Close(order *Order) error {
order.CurrentStatus = &ClosedStatus{}
return nil
}
// 关闭状态
type ClosedStatus struct{}
// 已关闭订单不能进行编辑
func (status *ClosedStatus) Update(order *Order, data map[string]interface{}) error {
return fmt.Errorf("已关闭订单不能进行编辑")
}
// 已关闭订单不能发货
func (status *ClosedStatus) Shipping(order *Order) error {
return fmt.Errorf("已关闭订单不能发货")
}
// 已关闭订单不能退货
func (status *ClosedStatus) Return(order *Order) error {
return fmt.Errorf("已关闭订单不能退货")
}
// 已关闭订单不能取消
func (status *ClosedStatus) Cancel(order *Order) error {
return fmt.Errorf("已关闭订单不能取消")
}
// 已关闭订单不能收货
func (status *ClosedStatus) Receive(order *Order) error {
return fmt.Errorf("已关闭订单不能收货")
}
// 已关闭订单不能再次关闭
func (status *ClosedStatus) Close(order *Order) error {
return fmt.Errorf("已关闭订单不能再次关闭")
}
// 订单仓储
type OrderRepository interface {
Save(order *Order) (*Order, error) // 下单/编辑订单
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)
... ...