...
|
...
|
@@ -13,12 +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_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 // 已关闭
|
|
|
)
|
|
|
|
|
|
// 订单实体
|
...
|
...
|
@@ -33,8 +35,10 @@ type Order struct { |
|
|
PartnerId int64 `json:"partnerId"`
|
|
|
// 发货单号
|
|
|
DeliveryCode string `json:"deliveryCode"`
|
|
|
// 发货时间
|
|
|
DeliveryTime time.Time `json:"deliveryTime"`
|
|
|
// 是否关闭订单标志
|
|
|
IsDisable int `json:"isDisable"`
|
|
|
IsDisable bool `json:"isDisable"`
|
|
|
// 订单编号
|
|
|
OrderNo string `json:"orderNo"`
|
|
|
// 订单详情
|
...
|
...
|
@@ -44,7 +48,7 @@ type Order struct { |
|
|
// 订单分红支付状态
|
|
|
OrderDividendStatus int `json:"orderDividendStatus"`
|
|
|
// 订单货品
|
|
|
OrderGoods []*Goods `json:"orderGoods"`
|
|
|
OrderGoods []*Good `json:"orderGoods"`
|
|
|
// 订单数据来源
|
|
|
OrderSource *OrderSource `json:"orderSource"`
|
|
|
// 订单类型(1.实际订单;2.意向订单)
|
...
|
...
|
@@ -70,13 +74,14 @@ type Order struct { |
|
|
// 订单状态机
|
|
|
type OrderStatus interface {
|
|
|
Update(order *Order, data map[string]interface{}) error // 更新订单
|
|
|
Checkout(order *Order) error // 下单
|
|
|
Shipping(order *Order) error // 发货(全部发货,部分发货)
|
|
|
Return(order *Order) error // 退换货
|
|
|
Cancel(order *Order) error // 取消订单
|
|
|
Receive(order *Order) error // 收货
|
|
|
Close(order *Order) error // 关闭订单
|
|
|
}
|
|
|
|
|
|
// 代发货状态
|
|
|
// 待发货状态
|
|
|
type UnShippedStatus struct{}
|
|
|
|
|
|
// 编辑待发货订单
|
...
|
...
|
@@ -103,7 +108,7 @@ func (status *UnShippedStatus) Update(order *Order, data map[string]interface{}) |
|
|
order.DeliveryCode = deliveryCode.(string)
|
|
|
}
|
|
|
if isDisable, ok := data["isDisable"]; ok {
|
|
|
order.IsDisable = isDisable.(int)
|
|
|
order.IsDisable = isDisable.(bool)
|
|
|
}
|
|
|
if orderNo, ok := data["orderNo"]; ok {
|
|
|
order.OrderNo = orderNo.(string)
|
...
|
...
|
@@ -157,7 +162,7 @@ func (status *UnShippedStatus) Update(order *Order, data map[string]interface{}) |
|
|
order.OrderDividendStatus = orderDividendStatus.(int)
|
|
|
}
|
|
|
if orderGoods, ok := data["orderGoods"]; ok {
|
|
|
order.OrderGoods = orderGoods.([]*Goods)
|
|
|
order.OrderGoods = orderGoods.([]*Good)
|
|
|
}
|
|
|
if dataSourceId, ok := data["dataSourceId"]; ok {
|
|
|
order.OrderSource.DataSourceId = dataSourceId.(int64)
|
...
|
...
|
@@ -183,150 +188,283 @@ func (status *UnShippedStatus) Update(order *Order, data map[string]interface{}) |
|
|
if remarks, ok := data["remarks"]; ok {
|
|
|
order.Remarks = remarks.(string)
|
|
|
}
|
|
|
if createAt, ok := data["createAt"]; ok {
|
|
|
order.CreateAt = createAt.(time.Time)
|
|
|
}
|
|
|
if updateAt, ok := data["updateAt"]; ok {
|
|
|
order.UpdateAt = updateAt.(time.Time)
|
|
|
}
|
|
|
if deleteAt, ok := data["deleteAt"]; ok {
|
|
|
order.DeleteAt = deleteAt.(time.Time)
|
|
|
}
|
|
|
order.UpdateAt = time.Now()
|
|
|
|
|
|
order.ComputeDividend()
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
func (status *UnShippedStatus) Checkout(order *Order) error {
|
|
|
// 发货
|
|
|
func (status *UnShippedStatus) Shipping(order *Order) error {
|
|
|
currentTime := time.Now()
|
|
|
order.DeliveryTime = currentTime
|
|
|
if order.OrderType == ORDER_TYPE_INTENTION {
|
|
|
order.OrderStatus = ORDER_STATUS_SHIPPING
|
|
|
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("待发货订单不能收货")
|
|
|
}
|
|
|
|
|
|
// 待收货订单不能关闭
|
|
|
func (status *UnShippedStatus) Close(order *Order) error {
|
|
|
return fmt.Errorf("待收货订单不能关闭")
|
|
|
}
|
|
|
|
|
|
// 待收货状态
|
|
|
type TransitStatus struct{}
|
|
|
|
|
|
// 待收货订单不能再次发货
|
|
|
func (status *TransitStatus) Shipping(order *Order) error {
|
|
|
return fmt.Errorf("待收货订单不能重复发货")
|
|
|
}
|
|
|
|
|
|
// 待收货订单不允许编辑
|
|
|
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
|
|
|
}
|
|
|
|
|
|
// 待收货订单不能关闭
|
|
|
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("已收货订单不能编辑")
|
|
|
}
|
|
|
|
|
|
func (status *ReceivedStatus) Checkout(order *Order) error {
|
|
|
return fmt.Errorf("已收货订单不能重复发货")
|
|
|
// 已收货订单不能再次收货
|
|
|
func (status *ReceivedStatus) Shipping(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 {
|
|
|
order.IsDisable = true
|
|
|
order.CurrentStatus = &ClosedStatus{}
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
// 退货状态
|
|
|
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) Shipping(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 {
|
|
|
order.IsDisable = true
|
|
|
order.CurrentStatus = &ClosedStatus{}
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
// 取消状态
|
|
|
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) Shipping(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("已取消订单不能进行收货")
|
|
|
}
|
|
|
|
|
|
// 关闭订单
|
|
|
func (status *CanceledStatus) Close(order *Order) error {
|
|
|
order.IsDisable = true
|
|
|
order.CurrentStatus = &ClosedStatus{}
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
// 已完成状态
|
|
|
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
|
|
|
}
|
|
|
|
|
|
func (status *CompletedStatus) Checkout(order *Order) error {
|
|
|
// 已完成的订单不能再次发货
|
|
|
func (status *CompletedStatus) Shipping(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("已完成订单不能收货")
|
|
|
}
|
|
|
|
|
|
// 关闭已完成订单
|
|
|
func (status *CompletedStatus) Close(order *Order) error {
|
|
|
order.IsDisable = true
|
|
|
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)
|
...
|
...
|
@@ -348,8 +486,8 @@ func (order *Order) Update(data map[string]interface{}) error { |
|
|
}
|
|
|
|
|
|
// 发货
|
|
|
func (order *Order) Checkout() error {
|
|
|
return order.CurrentStatus.Checkout(order)
|
|
|
func (order *Order) Shipping() error {
|
|
|
return order.CurrentStatus.Shipping(order)
|
|
|
}
|
|
|
|
|
|
// 退货
|
...
|
...
|
@@ -366,3 +504,75 @@ func (order *Order) Receive() error { |
|
|
func (order *Order) Cancel() error {
|
|
|
return order.CurrentStatus.Cancel(order)
|
|
|
}
|
|
|
|
|
|
// 关闭订单
|
|
|
func (order *Order) Close() error {
|
|
|
return order.CurrentStatus.Close(order)
|
|
|
}
|
|
|
|
|
|
func (order *Order) RefreshOrderDetail() {
|
|
|
|
|
|
}
|
|
|
func (order *Order) ComputeDividend() {
|
|
|
order.computeGoodsDividend()
|
|
|
order.computeOrderDividend()
|
|
|
}
|
|
|
func (order *Order) computeOrderDividend() {
|
|
|
var totalPlanBonus float64
|
|
|
// 调整后分红
|
|
|
var totalUseBonus float64
|
|
|
// 已收分红
|
|
|
var totalBonusHas float64
|
|
|
// 未收分红
|
|
|
var totalBonusNot float64
|
|
|
// 分红支出
|
|
|
var totalBonusExpense float64
|
|
|
for _, v := range order.OrderGoods {
|
|
|
totalPlanBonus += v.GoodDividend.PlanBonus
|
|
|
totalUseBonus += v.GoodDividend.UseBonus
|
|
|
totalBonusHas += v.GoodDividend.BonusHas
|
|
|
totalBonusNot += v.GoodDividend.BonusNot
|
|
|
totalBonusExpense += v.GoodDividend.BonusExpense
|
|
|
}
|
|
|
order.OrderDividend.PlanBonus = totalPlanBonus
|
|
|
order.OrderDividend.UseBonus = totalUseBonus
|
|
|
order.OrderDividend.BonusHas = totalBonusHas
|
|
|
order.OrderDividend.BonusNot = totalBonusNot
|
|
|
order.OrderDividend.BonusExpense = totalBonusExpense
|
|
|
}
|
|
|
func (order *Order) computeGoodsDividend() {
|
|
|
for i := range order.OrderGoods {
|
|
|
good := order.OrderGoods[i]
|
|
|
bonus := good.GoodTotalPrice * float64(good.GoodNum) * (order.OrderDividend.PartnerBonusPercent / 100)
|
|
|
if good.GoodDividend == nil {
|
|
|
good.GoodDividend = &Dividend{
|
|
|
PlanBonus: bonus,
|
|
|
UseBonus: -1,
|
|
|
BonusHas: 0,
|
|
|
BonusNot: bonus,
|
|
|
BonusExpense: 0,
|
|
|
BonusStatus: Dividend_Unpaid,
|
|
|
}
|
|
|
} else {
|
|
|
/* 计算预计分红、调整后分红 */
|
|
|
if bonus != good.GoodDividend.PlanBonus {
|
|
|
if order.OrderStatus == ORDER_STATUS_UNSHIPPED {
|
|
|
good.GoodDividend.PlanBonus = bonus
|
|
|
good.GoodDividend.BonusNot = bonus
|
|
|
} else {
|
|
|
expense := good.GoodDividend.PlanBonus - bonus
|
|
|
if expense <= 0 {
|
|
|
expense = 0
|
|
|
}
|
|
|
good.GoodDividend.UseBonus = bonus
|
|
|
good.GoodDividend.BonusNot = bonus
|
|
|
good.GoodDividend.BonusExpense = expense
|
|
|
}
|
|
|
}
|
|
|
/*计算未支付分红*/
|
|
|
if good.GoodDividend.BonusHas > 0 {
|
|
|
good.GoodDividend.BonusNot = good.GoodDividend.PlanBonus - good.GoodDividend.BonusHas
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
} |
...
|
...
|
|