- retry logic in swtich2SelfDeliverWithRetry implemented.

- when WaybillStatusCanceled received, will create new waybill when order.WaybillVendorID is unknown.
- don't treat mtps exception msg as failed.
- when waybill delivered msg received, set order delivered anyway.
This commit is contained in:
gazebo
2018-07-30 21:02:16 +08:00
parent 0615758d9a
commit 2933392731
2 changed files with 25 additions and 16 deletions

View File

@@ -48,7 +48,7 @@ func (c *WaybillController) OnWaybillExcept(msg *mtpsapi.CallbackOrderExceptionM
WaybillVendorID: model.VendorIDMTPS,
CourierName: msg.CourierName,
CourierMobile: msg.CourierPhone,
Status: model.WaybillStatusFailed, // todo 这里要再确定一下是否只要收到订单异常消息就视为订单失败
Status: model.WaybillStatusUnknown, // todo 这里要再确定一下是否只要收到订单异常消息就只简单当成一个消息
VendorStatus: utils.Int2Str(msg.ExceptionCode),
StatusTime: utils.Timestamp2Time(msg.Timestamp),
}

View File

@@ -289,11 +289,13 @@ func (s *DefScheduler) OnWaybillStatusChanged(bill *model.Waybill, isPending boo
}
case model.WaybillStatusCanceled:
s.removeWaybillFromMap(savedOrderInfo, bill)
if s.isBillCandidate(order, bill) {
if s.isBillCandidate(order, bill) || order.WaybillVendorID == model.VendorIDUnknown {
s.resetTimer(savedOrderInfo, scheduler.TimerStatusTypeWaybill, bill.Status, false)
if !isPending {
bill.WaybillVendorID = model.VendorIDUnknown
s.updateOrderByBill(order, bill, false)
if order.WaybillVendorID != model.VendorIDUnknown {
bill.WaybillVendorID = model.VendorIDUnknown
s.updateOrderByBill(order, bill, false)
}
if bill.WaybillVendorID != order.VendorID { // 3方的运单取消才会重新发起创建3方订单购物平台的运单取消后它本身还会再创建新运单(NewWabill事件有相应TIMER)),至少京东是这样的,暂时按京东的行为来
s.createWaybillOn3rdProviders(savedOrderInfo, nil)
}
@@ -310,11 +312,10 @@ func (s *DefScheduler) OnWaybillStatusChanged(bill *model.Waybill, isPending boo
case model.WaybillStatusDelivered:
s.resetTimer(savedOrderInfo, scheduler.TimerStatusTypeWaybill, bill.Status, false)
s.removeWaybillFromMap(savedOrderInfo, bill)
if s.isBillCandidate(order, bill) {
if order.VendorID != bill.WaybillVendorID && !isPending {
s.SelfDeliverDelievered(order)
}
} else {
if order.VendorID != bill.WaybillVendorID && !isPending {
s.SelfDeliverDelievered(order)
}
if !s.isBillCandidate(order, bill) {
globals.SugarLogger.Warnf("OnWaybillStatusChanged Delivered order(%d, %s) bill(%d, %s), bill:%v shouldn't got here", order.WaybillVendorID, order.VendorWaybillID, bill.WaybillVendorID, bill.VendorWaybillID, bill)
}
}
@@ -391,14 +392,22 @@ func (s *DefScheduler) cancelOtherWaybills(savedOrderInfo *WatchOrderInfo, bill2
func (s *DefScheduler) swtich2SelfDeliverWithRetry(order *model.GoodsOrder, bill *model.Waybill, retryCount int, duration time.Duration) {
globals.SugarLogger.Debugf("swtich2SelfDeliverWithRetry orderID:%s", order.VendorOrderID)
// 当前先不加RETRY逻辑
if err := s.Swtich2SelfDeliver(order); err != nil {
globals.SugarLogger.Infof("swtich2SelfDeliverWithRetry failed, cancel bill:%v, err:%v", bill, err)
if s.CancelWaybill(bill) == nil {
// 转自送失败的取消,要将订单中的运单状态更新
if s.isBillCandidate(order, bill) {
bill.WaybillVendorID = model.VendorIDUnknown
s.updateOrderByBill(order, bill, false)
globals.SugarLogger.Infof("swtich2SelfDeliverWithRetry failed, bill:%v, err:%v", bill, err)
if retryCount > 0 {
time.AfterFunc(duration, func() {
jxutils.CallMsgHandlerAsync(func() {
s.swtich2SelfDeliverWithRetry(order, bill, retryCount-1, duration)
}, order.VendorOrderID)
})
} else {
globals.SugarLogger.Warnf("swtich2SelfDeliverWithRetry finally failed, cancel bill:%v, err:%v", bill, err)
if s.CancelWaybill(bill) == nil {
// 转自送失败的取消,要将订单中的运单状态更新
if s.isBillCandidate(order, bill) {
bill.WaybillVendorID = model.VendorIDUnknown
s.updateOrderByBill(order, bill, false)
}
}
}
}