From a5788d5a7fe186803fd7f42eaf3ce577ab08ba05 Mon Sep 17 00:00:00 2001 From: gazebo Date: Sat, 23 Mar 2019 17:08:25 +0800 Subject: [PATCH] =?UTF-8?q?-=20DefScheduler.IsOrderHasWaybill=20-=20?= =?UTF-8?q?=E6=89=8B=E5=8A=A8=E5=88=9B=E5=BB=BA=E8=BF=90=E5=8D=95=E6=97=B6?= =?UTF-8?q?=E8=A6=81=E5=88=A4=E6=96=AD=E8=AE=A2=E5=8D=95=E6=98=AF=E5=90=A6?= =?UTF-8?q?=E5=B7=B2=E7=BB=8F=E6=9C=89=E4=BA=86=E6=9C=89=E6=95=88=E7=9A=84?= =?UTF-8?q?=E8=BF=90=E5=8D=95=20-=20=E6=89=8B=E5=8A=A8=E5=8F=96=E6=B6=88?= =?UTF-8?q?=E8=BF=90=E5=8D=95=E6=97=B6=E4=B8=8D=E5=81=9A=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../jxcallback/scheduler/defsch/defsch.go | 60 +++++++++++-------- 1 file changed, 35 insertions(+), 25 deletions(-) diff --git a/business/jxcallback/scheduler/defsch/defsch.go b/business/jxcallback/scheduler/defsch/defsch.go index 0798da077..4a37b41b5 100644 --- a/business/jxcallback/scheduler/defsch/defsch.go +++ b/business/jxcallback/scheduler/defsch/defsch.go @@ -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 +}