- DefScheduler.IsOrderHasWaybill
- 手动创建运单时要判断订单是否已经有了有效的运单 - 手动取消运单时不做判断
This commit is contained in:
@@ -311,7 +311,7 @@ func (s *DefScheduler) OnWaybillStatusChanged(bill *model.Waybill, isPending boo
|
||||
if !isPending {
|
||||
if order.Status > model.OrderStatusEndBegin {
|
||||
s.ProxyCancelWaybill(order, bill, partner.CancelWaybillReasonNotAcceptIntime, partner.CancelWaybillReasonStrNotAcceptIntime)
|
||||
} else if order.WaybillVendorID != model.VendorIDUnknown {
|
||||
} else if s.IsOrderHasWaybill(order) {
|
||||
globals.SugarLogger.Debugf("OnWaybillStatusChanged multiple waybill created, bill:%v", bill)
|
||||
if s.IsOrderPlatformWaybill(bill) { // 是购物平台运单
|
||||
if order.VendorID != order.WaybillVendorID { // 既有运单不是购物平台运单
|
||||
@@ -347,7 +347,7 @@ func (s *DefScheduler) OnWaybillStatusChanged(bill *model.Waybill, isPending boo
|
||||
// todo 购买平台的运单,优先级最高,但这样写也可能带来问题,即在这个时间,因为之前3方已经接单,已经发出了转自送请求(而且可能成功了),所以加个状态判断
|
||||
if order.WaybillVendorID == model.VendorIDUnknown ||
|
||||
(s.IsOrderPlatformWaybill(bill) && order.VendorID != order.WaybillVendorID && (order.DeliveryFlag&model.OrderDeliveryFlagMaskPurcahseDisabled) == 0) {
|
||||
if order.WaybillVendorID != model.VendorIDUnknown {
|
||||
if s.IsOrderHasWaybill(order) {
|
||||
// 进到这里的原因是,在这个时间点,购物平台物流已经抢单(但抢单消息还没有被收到)(比如:818810379000941)
|
||||
globals.SugarLogger.Infof("OnWaybillStatusChanged orderID:%s purchase platform waybill arrvied later, may case problem", order.VendorOrderID)
|
||||
}
|
||||
@@ -385,7 +385,7 @@ func (s *DefScheduler) OnWaybillStatusChanged(bill *model.Waybill, isPending boo
|
||||
// 取消抢单应该不需要发3方运单
|
||||
// s.createWaybillOn3rdProviders(savedOrderInfo, bill)
|
||||
}
|
||||
} else if order.WaybillVendorID != model.VendorIDUnknown {
|
||||
} else if s.IsOrderHasWaybill(order) {
|
||||
s.ProxyCancelWaybill(order, bill, partner.CancelWaybillReasonNotAcceptIntime, partner.CancelWaybillReasonStrNotAcceptIntime)
|
||||
if !isPending {
|
||||
globals.SugarLogger.Warnf("OnWaybillStatusChanged AcceptCanceled orderID:%s got multiple bill:%v, order details:%v", order.VendorOrderID, bill, order)
|
||||
@@ -416,7 +416,7 @@ func (s *DefScheduler) OnWaybillStatusChanged(bill *model.Waybill, isPending boo
|
||||
if s.isBillCandidate(order, bill) || order.WaybillVendorID == model.VendorIDUnknown {
|
||||
s.resetTimer(savedOrderInfo, bill, isPending)
|
||||
if !isPending {
|
||||
if order.WaybillVendorID != model.VendorIDUnknown {
|
||||
if s.IsOrderHasWaybill(order) {
|
||||
bill.WaybillVendorID = model.VendorIDUnknown
|
||||
s.updateOrderByBill(order, bill, false)
|
||||
}
|
||||
@@ -563,33 +563,39 @@ func (s *DefScheduler) createWaybillOn3rdProviders(savedOrderInfo *WatchOrderInf
|
||||
func (s *DefScheduler) cancelOtherWaybills(savedOrderInfo *WatchOrderInfo, bill2Keep *model.Waybill, cancelReasonID int, cancelReason string) (err error) {
|
||||
globals.SugarLogger.Debugf("cancelOtherWaybills, orderID:%s, bill:%v", savedOrderInfo.order.VendorOrderID, bill2Keep)
|
||||
if (savedOrderInfo.order.DeliveryFlag & model.OrderDeliveryFlagMaskScheduleDisabled) == 0 {
|
||||
toBeDeleted := []*model.Waybill{}
|
||||
for _, v := range savedOrderInfo.waybills {
|
||||
if !s.IsOrderPlatformWaybill(v) && (bill2Keep == nil || !(v.WaybillVendorID == bill2Keep.WaybillVendorID && v.VendorWaybillID == bill2Keep.VendorWaybillID)) {
|
||||
err2 := s.ProxyCancelWaybill(savedOrderInfo.order, v, cancelReasonID, cancelReason)
|
||||
if err2 == nil {
|
||||
toBeDeleted = append(toBeDeleted, v)
|
||||
}
|
||||
// 至少返回一个错误
|
||||
if err == nil && err2 != nil {
|
||||
err = err2
|
||||
}
|
||||
}
|
||||
}
|
||||
if len(toBeDeleted) > 0 {
|
||||
// todo 这里为什么要删除运单,应该只需要在运单完成,取消或失败时才删除
|
||||
// for _, v := range toBeDeleted {
|
||||
// s.removeWaybillFromMap(savedOrderInfo, v.WaybillVendorID)
|
||||
// }
|
||||
} else {
|
||||
globals.SugarLogger.Debugf("cancelOtherWaybills, orderID:%s, bill:%v cancel 0 bills", savedOrderInfo.order.VendorOrderID, bill2Keep)
|
||||
}
|
||||
err = s.cancelOtherWaybills2(savedOrderInfo, bill2Keep, cancelReasonID, cancelReason)
|
||||
} else {
|
||||
globals.SugarLogger.Debugf("cancelOtherWaybills, orderID:%s, bill:%v stop schedule", savedOrderInfo.order.VendorOrderID, bill2Keep)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (s *DefScheduler) cancelOtherWaybills2(savedOrderInfo *WatchOrderInfo, bill2Keep *model.Waybill, cancelReasonID int, cancelReason string) (err error) {
|
||||
globals.SugarLogger.Debugf("cancelOtherWaybills2, orderID:%s, bill:%v", savedOrderInfo.order.VendorOrderID, bill2Keep)
|
||||
toBeDeleted := []*model.Waybill{}
|
||||
for _, v := range savedOrderInfo.waybills {
|
||||
if !s.IsOrderPlatformWaybill(v) && (bill2Keep == nil || !(v.WaybillVendorID == bill2Keep.WaybillVendorID && v.VendorWaybillID == bill2Keep.VendorWaybillID)) {
|
||||
err2 := s.ProxyCancelWaybill(savedOrderInfo.order, v, cancelReasonID, cancelReason)
|
||||
if err2 == nil {
|
||||
toBeDeleted = append(toBeDeleted, v)
|
||||
}
|
||||
// 至少返回一个错误
|
||||
if err == nil && err2 != nil {
|
||||
err = err2
|
||||
}
|
||||
}
|
||||
}
|
||||
if len(toBeDeleted) > 0 {
|
||||
// todo 这里为什么要删除运单,应该只需要在运单完成,取消或失败时才删除
|
||||
// for _, v := range toBeDeleted {
|
||||
// s.removeWaybillFromMap(savedOrderInfo, v.WaybillVendorID)
|
||||
// }
|
||||
} else {
|
||||
globals.SugarLogger.Debugf("cancelOtherWaybills, orderID:%s, bill:%v cancel 0 bills", savedOrderInfo.order.VendorOrderID, bill2Keep)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (s *DefScheduler) swtich2SelfDeliverWithRetry(savedOrderInfo *WatchOrderInfo, bill *model.Waybill, retryCount int, duration time.Duration) {
|
||||
order := savedOrderInfo.order
|
||||
globals.SugarLogger.Debugf("swtich2SelfDeliverWithRetry orderID:%s", order.VendorOrderID)
|
||||
@@ -888,3 +894,7 @@ func (s *DefScheduler) IsOrderPlatformWaybill(bill *model.Waybill) bool {
|
||||
func (s *DefScheduler) IsSpecialOrderPlatformWaybill(bill *model.Waybill) bool {
|
||||
return (bill.OrderVendorID == model.VendorIDWSC && bill.WaybillVendorID == model.VendorIDDada)
|
||||
}
|
||||
|
||||
func (s *DefScheduler) IsOrderHasWaybill(order *model.GoodsOrder) bool {
|
||||
return order.WaybillVendorID != model.VendorIDUnknown
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user