- handle isPending in OnWaybillStatusChanged.

This commit is contained in:
gazebo
2018-07-26 22:28:36 +08:00
parent 96912cdcb9
commit cdaae1c1fa
3 changed files with 47 additions and 30 deletions

View File

@@ -234,7 +234,7 @@ func (c *OrderController) updateOrderOtherInfo(order *model.GoodsOrder, db orm.O
if num, err := db.Raw(sql, utils.Str2Int64(order.VendorStoreID)).ValuesList(&lists); err == nil && num == 1 {
order.JxStoreID = int(utils.Str2Int64(lists[0][0].(string)))
} else {
globals.SugarLogger.Errorf("updateOrderOtherInfo can not find store info for orderID:%s, store:%s, num:%d, error:%v", order.VendorOrderID, order.VendorStoreID, num, err)
globals.SugarLogger.Warnf("updateOrderOtherInfo can not find store info for orderID:%s, store:%s, num:%d, error:%v", order.VendorOrderID, order.VendorStoreID, num, err)
}
err = c.updateOrderSkuOtherInfo(order.Skus, db)
return err

View File

@@ -144,35 +144,42 @@ func (s *DefScheduler) OnWaybillStatusChanged(bill *model.Waybill, isPending boo
// }
if bill.Status == model.WaybillStatusNew {
s.addWaybill2Map(savedOrderInfo, bill)
if order.WaybillVendorID != model.VendorIDUnknown {
globals.SugarLogger.Debugf("OnWaybillStatusChanged multiple waybill created, bill:%v", bill)
if !(order.WaybillVendorID == bill.WaybillVendorID && order.VendorWaybillID == bill.VendorWaybillID) && bill.WaybillVendorID != order.VendorID {
s.CancelWaybill(bill)
} else if bill.WaybillVendorID == order.VendorID {
globals.SugarLogger.Warnf("OnWaybillStatusChanged bill:%v purchase platform bill came later than others, strange!!!", bill)
if !isPending {
if order.WaybillVendorID != model.VendorIDUnknown {
globals.SugarLogger.Debugf("OnWaybillStatusChanged multiple waybill created, bill:%v", bill)
if !(order.WaybillVendorID == bill.WaybillVendorID && order.VendorWaybillID == bill.VendorWaybillID) && bill.WaybillVendorID != order.VendorID {
s.CancelWaybill(bill)
} else if bill.WaybillVendorID == order.VendorID {
globals.SugarLogger.Warnf("OnWaybillStatusChanged bill:%v purchase platform bill came later than others, strange!!!", bill)
}
}
}
// 只有购物平台的新运单消息才会启动抢单TIMER
if bill.OrderVendorID == bill.WaybillVendorID {
s.resetTimer(savedOrderInfo, scheduler.TimerStatusTypeWaybill, bill.Status, false)
}
} else {
switch bill.Status {
case model.WaybillStatusAccepted:
if order.WaybillVendorID == model.VendorIDUnknown {
s.cancelOtherWaybills(savedOrderInfo, bill)
s.updateOrderByBill(order, bill, false)
} else if !(order.WaybillVendorID == bill.WaybillVendorID && order.VendorWaybillID == bill.VendorWaybillID) && bill.WaybillVendorID != order.VendorID {
// todo 当前逻辑加载PENDING的ORDER时正常状态也可能进这里
s.CancelWaybill(bill)
globals.SugarLogger.Warnf("OnWaybillStatusChanged Accepted orderID:%s got multiple bill:%v, order details:%v", order.VendorOrderID, bill, order)
if !isPending {
if order.WaybillVendorID == model.VendorIDUnknown {
s.cancelOtherWaybills(savedOrderInfo, bill)
s.updateOrderByBill(order, bill, false)
} else if !(order.WaybillVendorID == bill.WaybillVendorID && order.VendorWaybillID == bill.VendorWaybillID) && bill.WaybillVendorID != order.VendorID {
// todo 当前逻辑加载PENDING的ORDER时正常状态也可能进这里
s.CancelWaybill(bill)
globals.SugarLogger.Warnf("OnWaybillStatusChanged Accepted orderID:%s got multiple bill:%v, order details:%v", order.VendorOrderID, bill, order)
}
}
s.resetTimer(savedOrderInfo, scheduler.TimerStatusTypeWaybill, bill.Status, false)
case model.WaybillStatusAcceptCanceled:
if order.WaybillVendorID == bill.WaybillVendorID && order.VendorWaybillID == bill.VendorWaybillID {
bill.WaybillVendorID = model.VendorIDUnknown
s.updateOrderByBill(order, bill, false)
if !isPending {
bill.WaybillVendorID = model.VendorIDUnknown
s.updateOrderByBill(order, bill, false)
s.createWaybillOn3rdProviders(order, bill)
s.createWaybillOn3rdProviders(order, bill)
}
s.resetTimer(savedOrderInfo, scheduler.TimerStatusTypeWaybill, bill.Status, false)
} else if order.WaybillVendorID != model.VendorIDUnknown {
s.CancelWaybill(bill)
@@ -188,10 +195,11 @@ func (s *DefScheduler) OnWaybillStatusChanged(bill *model.Waybill, isPending boo
case model.WaybillStatusFailed: // todo WaybillStatusFailed理解成订单整个失败了不需要再尝试创建运单了注意这里应该加个zabbix日志的报警
s.removeWaybillFromMap(savedOrderInfo, bill)
if order.WaybillVendorID == bill.WaybillVendorID && order.VendorWaybillID == bill.VendorWaybillID {
globals.SugarLogger.Infof("OnWaybillStatusChanged WaybillStatusFailed, bill:%v", bill)
bill.WaybillVendorID = model.VendorIDUnknown
s.updateOrderByBill(order, bill, true)
if !isPending {
globals.SugarLogger.Infof("OnWaybillStatusChanged WaybillStatusFailed, bill:%v", bill)
bill.WaybillVendorID = model.VendorIDUnknown
s.updateOrderByBill(order, bill, true)
}
s.resetTimer(savedOrderInfo, scheduler.TimerStatusTypeWaybill, bill.Status, false)
} else {
globals.SugarLogger.Warnf("OnWaybillStatusChanged Failed bill:%v shouldn't got here", bill)
@@ -199,15 +207,16 @@ func (s *DefScheduler) OnWaybillStatusChanged(bill *model.Waybill, isPending boo
case model.WaybillStatusCanceled:
s.removeWaybillFromMap(savedOrderInfo, bill)
if order.WaybillVendorID == bill.WaybillVendorID && order.VendorWaybillID == bill.VendorWaybillID {
bill.WaybillVendorID = model.VendorIDUnknown
s.updateOrderByBill(order, bill, true)
s.createWaybillOn3rdProviders(order, nil)
if !isPending {
bill.WaybillVendorID = model.VendorIDUnknown
s.updateOrderByBill(order, bill, true)
s.createWaybillOn3rdProviders(order, nil)
}
s.resetTimer(savedOrderInfo, scheduler.TimerStatusTypeWaybill, bill.Status, false)
}
case model.WaybillStatusDelivering:
if order.WaybillVendorID == bill.WaybillVendorID && order.VendorWaybillID == bill.VendorWaybillID {
if order.VendorID != bill.WaybillVendorID {
if order.VendorID != bill.WaybillVendorID && !isPending {
s.SelfDeliverDelievering(order)
}
} else {
@@ -218,7 +227,7 @@ func (s *DefScheduler) OnWaybillStatusChanged(bill *model.Waybill, isPending boo
case model.WaybillStatusDelivered:
s.removeWaybillFromMap(savedOrderInfo, bill)
if order.WaybillVendorID == bill.WaybillVendorID && order.VendorWaybillID == bill.VendorWaybillID {
if order.VendorID != bill.WaybillVendorID {
if order.VendorID != bill.WaybillVendorID && !isPending {
s.SelfDeliverDelievered(order)
}
} else {
@@ -274,7 +283,7 @@ func (s *DefScheduler) createWaybillOn3rdProviders(order *model.GoodsOrder, excl
}
globals.SugarLogger.Debugf("createWaybillOn3rdProviders, orderID:%s, store:%d dont't support 3rd delivery platform", order.VendorOrderID, jxutils.GetJxStoreIDFromOrder(order))
} else {
globals.SugarLogger.Warnf("createWaybillOn3rdProviders, orderID:%s, status:%d doesn't match model.OrderStatusFinishedPickup, bypass", order.VendorOrderID, order.Status)
globals.SugarLogger.Debugf("createWaybillOn3rdProviders, orderID:%s, status:%d doesn't match model.OrderStatusFinishedPickup, bypass", order.VendorOrderID, order.Status)
}
} else {
globals.SugarLogger.Warnf("OnWaybillStatusChanged Canceled failed %d times, stop schedule", savedOrderInfo.retryCount)
@@ -382,10 +391,17 @@ func (s *DefScheduler) resetTimer(savedOrderInfo *WatchOrderInfo, statusType, st
if timeout == 0 {
config.TimeoutAction(order)
} else {
timerName := ""
if statusType == scheduler.TimerStatusTypeOrder {
timerName = model.OrderStatusName[status]
} else if statusType == scheduler.TimerStatusTypeWaybill {
timerName = model.WaybillStatusName[status]
}
savedOrderInfo.timerStatusType = statusType
savedOrderInfo.timerStatus = status
savedOrderInfo.timer = time.AfterFunc(timeout, func() {
jxutils.CallMsgHandlerAsync(func() {
globals.SugarLogger.Debugf("fire timer:%s, orderID:%s", timerName, order.VendorOrderID)
config.TimeoutAction(order)
savedOrderInfo.timerStatus = 0
savedOrderInfo.timerStatusType = scheduler.TimerStatusTypeUnknown

View File

@@ -181,6 +181,8 @@ func (c *BaseScheduler) SelfDeliverDelievering(order *model.GoodsOrder) (err err
return c.GetPurchasePlatformFromVendorID(order.VendorID).SelfDeliverDelievering(order)
}, "SelfDeliverDelievering orderID:%s", order.VendorOrderID)
}
} else if order.Status == model.OrderStatusDelivering {
globals.SugarLogger.Debugf("SelfDeliverDelievering orderID:%s, status:%d already ok", order.VendorOrderID, order.Status)
} else {
globals.SugarLogger.Infof("SelfDeliverDelievering orderID:%s, status:%d is not suitable", order.VendorOrderID, order.Status)
}
@@ -189,8 +191,7 @@ func (c *BaseScheduler) SelfDeliverDelievering(order *model.GoodsOrder) (err err
func (c *BaseScheduler) SelfDeliverDelievered(order *model.GoodsOrder) (err error) {
globals.SugarLogger.Infof("SelfDeliverDelievered orderID:%s", order.VendorOrderID)
// todo
if true { //order.Status == model.OrderStatusDelivering {
if order.Status == model.OrderStatusDelivering {
if c.IsReallyCallPlatformAPI {
err = utils.CallFuncLogError(func() error {
return c.GetPurchasePlatformFromVendorID(order.VendorID).SelfDeliverDelievered(order)